Skip to content

Commit 0ec02c8

Browse files
Merge pull request #166 from SSCHAcode/warning_on_stress_vcrelax
Added an error if no stress tensor is found
2 parents 74061a6 + b1630ce commit 0ec02c8

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

Modules/Relax.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ def vc_relax(self, target_press = 0, static_bulk_modulus = 100,
609609
if ensemble_loc is not None and self.save_ensemble:
610610
self.minim.ensemble.save_bin(ensemble_loc, pop)
611611

612+
613+
612614
self.minim.population = pop
613615
self.minim.init(delete_previous_data = False)
614616

@@ -625,6 +627,11 @@ def vc_relax(self, target_press = 0, static_bulk_modulus = 100,
625627
stress_tensor *= sscha.SchaMinimizer.__RyBohr3_to_evA3__
626628
stress_err *= sscha.SchaMinimizer.__RyBohr3_to_evA3__
627629

630+
# Check if the stress tensor is actually loaded in the ensemble
631+
if np.max(np.abs(self.minim.ensemble.stresses)) < 1e-10:
632+
# Probably there is an error in the submission of the stress tensor calculation
633+
raise ValueError("Error, the stress tensor is not loaded in the ensemble. Check the stress tensor calculation.")
634+
628635
# Get the pressure
629636
Press = np.trace(stress_tensor) / 3
630637

@@ -676,7 +683,7 @@ def vc_relax(self, target_press = 0, static_bulk_modulus = 100,
676683
Gibbs Free energy = {:.10e} eV {}
677684
Zero energy = {:.10e} eV
678685
679-
""".format(Press / CC.Units.GPA_TO_EV_PER_A3, press_err/ CC.Units.GPA_TO_EV_PER_A3, target_press , Vol,target_press_evA3 * Vol, helmoltz, mark_helmoltz, gibbs, mark_gibbs, self.minim.eq_energy)
686+
""".format(Press / CC.Units.GPA_TO_EV_PER_A3, press_err/ CC.Units.GPA_TO_EV_PER_A3, target_press, target_press, Vol, target_press_evA3 * Vol, helmoltz, mark_helmoltz, gibbs, mark_gibbs, self.minim.eq_energy)
680687
print(message)
681688
# print " ====================== "
682689
# print " ENTHALPIC CONTRIBUTION "
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import cellconstructor as CC, cellconstructor.Phonons
2+
import sscha, sscha.Ensemble
3+
import sscha.SchaMinimizer, sscha.Relax
4+
import sscha.Utilities
5+
6+
import ase, ase.calculators, ase.calculators.emt
7+
import numpy as np
8+
import os, sys
9+
10+
import pytest
11+
12+
13+
def test_gold(use_julia=True, verbose=False):
14+
supercell=(2,2,2)
15+
16+
# Change directory to the current script
17+
total_path = os.path.dirname(os.path.abspath(__file__))
18+
os.chdir(total_path)
19+
20+
cif_file="../test_release/Au_mp-81_primitive.cif"
21+
temperature = 300
22+
23+
# Load the structure
24+
struct = CC.Structure.Structure()
25+
struct.read_generic_file(cif_file)
26+
gold_dyn = CC.Phonons.compute_phonons_finite_displacements(struct,
27+
ase.calculators.emt.EMT(), supercell=supercell)
28+
29+
# Setup a sscha
30+
gold_dyn.Symmetrize()
31+
gold_dyn.ForcePositiveDefinite()
32+
33+
ensemble = sscha.Ensemble.Ensemble(gold_dyn, temperature)
34+
minim = sscha.SchaMinimizer.SSCHA_Minimizer(ensemble)
35+
minim.set_minimization_step(0.001)
36+
minim.meaningful_factor = 1e-5
37+
minim.use_julia = use_julia
38+
39+
relax = sscha.Relax.SSCHA(minim,
40+
ase_calculator=ase.calculators.emt.EMT(),
41+
N_configs = 50,
42+
max_pop = 3)
43+
relax.save_ensemble=False
44+
45+
cfp=None
46+
if verbose:
47+
ioinfo = sscha.Utilities.IOInfo()
48+
ioinfo.SetupSaving("minim")
49+
cfp = ioinfo.CFP_SaveAll
50+
51+
relax.setup_custom_functions(
52+
custom_function_post=cfp)
53+
54+
relax.vc_relax(target_press=0)
55+
56+
if verbose:
57+
relax.minim.dyn.save_qe("final_dyn")
58+
59+
if __name__ == "__main__":
60+
use_julia=True
61+
if len(sys.argv) > 1:
62+
if sys.argv[1].lower() != "julia":
63+
use_julia=False
64+
65+
test_gold(verbose=True, use_julia=use_julia)

0 commit comments

Comments
 (0)