Skip to content

Commit 4a07e10

Browse files
authored
add ability to turn off spectrum (#87)
1 parent f076577 commit 4a07e10

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/mattersim/applications/phonon.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(
3131
supercell_matrix: np.ndarray = None,
3232
qpoints_mesh: np.ndarray = None,
3333
max_atoms: int = None,
34+
calc_spec: bool = True,
3435
):
3536
"""_summary
3637
@@ -51,6 +52,8 @@ def __init__(
5152
max_atoms (int, optional): Maximum atoms number limitation for the
5253
supercell generation. If not set, will automatic generate super
5354
-cell based on symmetry. Defaults to None.
55+
calc_spec (bool, optional): If calculate the spectrum and check
56+
imaginary frequencies. Default to True.
5457
"""
5558
assert (
5659
atoms.calc is not None
@@ -88,6 +91,7 @@ def __init__(
8891
self.qpoints_mesh = qpoints_mesh
8992

9093
self.max_atoms = max_atoms
94+
self.calc_spec = calc_spec
9195

9296
def compute_force_constants(self, atoms: Atoms, nrep_second: np.ndarray):
9397
"""
@@ -209,14 +213,18 @@ def run(self):
209213
print("Error while computing force constants:", e)
210214
raise
211215

212-
try:
213-
# Calculate phonon spectrum
214-
self.compute_phonon_spectrum_dos(self.atoms, phonon, k_point_mesh)
215-
# check whether has imaginary frequency
216-
has_imaginary = self.check_imaginary_freq(phonon)
217-
except Exception as e:
218-
print("Error while computing phonon spectrum and dos:", e)
219-
raise
216+
if self.calc_spec:
217+
try:
218+
# Calculate phonon spectrum
219+
self.compute_phonon_spectrum_dos(self.atoms, phonon, k_point_mesh)
220+
# check whether has imaginary frequency
221+
has_imaginary = self.check_imaginary_freq(phonon)
222+
except Exception as e:
223+
print("Error while computing phonon spectrum and dos:", e)
224+
raise
225+
else:
226+
has_imaginary = 'Not calculated, set calc_spec True'
227+
phonon.save(settings={"force_constants": True})
220228

221229
except Exception as e:
222230
print("An error occurred during the Phonon workflow:", e)

0 commit comments

Comments
 (0)