-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Phonon module to generate the trajectory from a phonon mode.
- Loading branch information
1 parent
ca8a036
commit 8c944cc
Showing
12 changed files
with
212 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Helper function to perform vector dot product | ||
function vec_dot(a, b) { | ||
return a.reduce((sum, value, index) => sum + value * b[index], 0); | ||
} | ||
|
||
// Helper function to create a complex number in polar form | ||
function complexPolar(magnitude, angle) { | ||
return { | ||
real: magnitude * Math.cos(angle), | ||
imag: magnitude * Math.sin(angle), | ||
mult(other) { | ||
return { | ||
real: this.real * other.real - this.imag * other.imag, | ||
imag: this.real * other.imag + this.imag * other.real, | ||
}; | ||
}, | ||
}; | ||
} | ||
|
||
// Helper function to multiply complex numbers | ||
function complexMult(complex, phase) { | ||
return phase.mult({ real: complex[0], imag: complex[1] }); | ||
} | ||
|
||
export class Phonon { | ||
constructor(atoms, kpoint = null, eigenvectors = null, addatomphase = true) { | ||
this.atoms = atoms; | ||
this.kpoint = kpoint; | ||
this.eigenvectors = eigenvectors; | ||
this.addatomphase = addatomphase; | ||
this.vibrations = []; | ||
} | ||
|
||
// Compute initial phases and vibrations | ||
calculateVibrations() { | ||
const fractional_positions = this.atoms.calculateFractionalCoordinates(); | ||
const natoms = this.atoms.positions.length; | ||
let atom_phase = []; | ||
|
||
if (this.addatomphase) { | ||
atom_phase = fractional_positions.map((position) => vec_dot(this.kpoint, position)); | ||
} else { | ||
atom_phase = new Array(natoms).fill(0); | ||
} | ||
console.log("atom_phase: ", atom_phase); | ||
|
||
for (let i = 0; i < natoms; i++) { | ||
let sprod = atom_phase[i]; | ||
let phase = complexPolar(1.0, sprod * 2.0 * Math.PI); | ||
this.vibrations.push(this.eigenvectors[i].map((vector) => complexMult(vector, phase))); | ||
} | ||
console.log("vibrations: ", this.vibrations); | ||
} | ||
|
||
// Get the trajectory of the phonon mode | ||
getTrajectory(amplitude, nframes, kpoint = null, eigenvectors = null, atoms = null, repeat = [1, 1, 1], addatomphase = null) { | ||
if (atoms) { | ||
this.atoms = atoms; | ||
} | ||
if (kpoint) { | ||
this.kpoint = kpoint; | ||
} | ||
if (eigenvectors) { | ||
this.eigenvectors = eigenvectors; | ||
} | ||
if (this.kpoint === null || this.eigenvectors === null) { | ||
throw new Error("kpoint and eigenvectors must be provided"); | ||
} | ||
if (addatomphase !== null) { | ||
this.addatomphase = addatomphase; | ||
} | ||
|
||
this.calculateVibrations(); | ||
const trajectory = []; | ||
const times = Array.from({ length: nframes }, (_, i) => 2 * Math.PI * (i / nframes)); | ||
times.forEach((t) => { | ||
const newAtoms = this.atoms.copy(); | ||
let phase = complexPolar(amplitude, t); | ||
const movement = []; | ||
for (let i = 0; i < this.atoms.positions.length; i++) { | ||
let displacement = this.vibrations[i].map((v) => phase.real * v.real); | ||
newAtoms.positions[i] = this.atoms.positions[i].map((pos, index) => pos + displacement[index] / 5); | ||
movement.push(displacement); | ||
} | ||
newAtoms.newAttribute("movement", movement); | ||
trajectory.push(newAtoms.multiply(...repeat)); | ||
}); | ||
return trajectory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-18.5 KB
(68%)
tests/e2e/gui.spec.js-snapshots/Phonon-frame-0-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-7.72 KB
(84%)
tests/e2e/gui.spec.js-snapshots/Phonon-frame-10-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters