class DeformedStructureSetTest(PymatgenTest): def setUp(self): lattice = Lattice([[3.8401979337, 0.00, 0.00], [1.9200989668, 3.3257101909, 0.00], [0.00, -2.2171384943, 3.1355090603]]) self.structure = Structure(lattice, ["Si", "Si"], [[0, 0, 0], [0.75, 0.5, 0.75]]) self.default_dss = DeformedStructureSet(self.structure) def test_init(self): with self.assertRaises(ValueError): DeformedStructureSet(self.structure, num_norm=5) DeformedStructureSet(self.structure, num_shear=5) self.assertEqual(self.structure, self.default_dss.undeformed_structure) def test_as_strain_dict(self): strain_dict = self.default_dss.as_strain_dict() for i, def_struct in enumerate(self.default_dss): test_strain = IndependentStrain(self.default_dss.deformations[i]) strain_keys = [ strain for strain in list(strain_dict.keys()) if (strain == test_strain).all() ] self.assertEqual(len(strain_keys), 1) self.assertEqual(self.default_dss.def_structs[i], strain_dict[strain_keys[0]])
class DeformedStructureSetTest(PymatgenTest): def setUp(self): self.structure = self.get_structure("Sn") self.default_dss = DeformedStructureSet(self.structure) def test_init(self): with self.assertRaises(ValueError): DeformedStructureSet(self.structure, num_norm=5) with self.assertRaises(ValueError): DeformedStructureSet(self.structure, num_shear=5) self.assertEqual(self.structure, self.default_dss.undeformed_structure) # Test symmetry dss_symm = DeformedStructureSet(self.structure, symmetry=True) # Should be 4 strains for normal, 2 for shear (since +/- shear # are symmetrically equivalent) self.assertEqual(len(dss_symm), 6) def test_as_strain_dict(self): strain_dict = self.default_dss.as_strain_dict() for i, def_struct in enumerate(self.default_dss): test_strain = IndependentStrain(self.default_dss.deformations[i]) strain_keys = [ strain for strain in list(strain_dict.keys()) if (strain == test_strain).all() ] self.assertEqual(len(strain_keys), 1) self.assertEqual(self.default_dss.def_structs[i], strain_dict[strain_keys[0]])
class DeformedStructureSetTest(PymatgenTest): def setUp(self): self.structure = self.get_structure("Sn") self.default_dss = DeformedStructureSet(self.structure) def test_init(self): with self.assertRaises(ValueError): DeformedStructureSet(self.structure, num_norm=5) with self.assertRaises(ValueError): DeformedStructureSet(self.structure, num_shear=5) self.assertEqual(self.structure, self.default_dss.undeformed_structure) # Test symmetry dss_symm = DeformedStructureSet(self.structure, symmetry=True) # Should be 4 strains for normal, 2 for shear (since +/- shear # are symmetrically equivalent) self.assertEqual(len(dss_symm), 6) def test_as_strain_dict(self): strain_dict = self.default_dss.as_strain_dict() for i, def_struct in enumerate(self.default_dss): test_strain = IndependentStrain(self.default_dss.deformations[i]) strain_keys = [strain for strain in list(strain_dict.keys()) if (strain == test_strain).all()] self.assertEqual(len(strain_keys), 1) self.assertEqual(self.default_dss.def_structs[i], strain_dict[strain_keys[0]])
class DeformedStructureSetTest(PymatgenTest): def setUp(self): lattice = Lattice( [[3.8401979337, 0.00, 0.00], [1.9200989668, 3.3257101909, 0.00], [0.00, -2.2171384943, 3.1355090603]] ) self.structure = Structure(lattice, ["Si", "Si"], [[0, 0, 0], [0.75, 0.5, 0.75]]) self.default_dss = DeformedStructureSet(self.structure) def test_init(self): with self.assertRaises(ValueError): DeformedStructureSet(self.structure, num_norm=5) with self.assertRaises(ValueError): DeformedStructureSet(self.structure, num_shear=5) self.assertEqual(self.structure, self.default_dss.undeformed_structure) def test_as_strain_dict(self): strain_dict = self.default_dss.as_strain_dict() for i, def_struct in enumerate(self.default_dss): test_strain = IndependentStrain(self.default_dss.deformations[i]) strain_keys = [strain for strain in list(strain_dict.keys()) if (strain == test_strain).all()] self.assertEqual(len(strain_keys), 1) self.assertEqual(self.default_dss.def_structs[i], strain_dict[strain_keys[0]])
import pymatgen as mg from pymatgen.analysis.elasticity.strain import DeformedStructureSet import os from shutil import copyfile from pymatgen.io.vasp.outputs import Vasprun from pymatgen.analysis.elasticity.stress import Stress from pymatgen.analysis.elasticity.elastic import ElasticTensor structure = mg.Structure.from_file("POSCAR") def_set = DeformedStructureSet(structure) strains = def_set.as_strain_dict() calculations = [] for x in range(1, 25): calculations.append('poscar%s' % x) match_dict = {} for calc in calculations: struct = mg.Structure.from_file(calc + "/POSCAR") vrun = Vasprun(calc + '/vasprun.xml', parse_dos=False, parse_eigen=False) stress = Stress(vrun.ionic_steps[-1]['stress']) for strain in strains: if strains[strain].lattice == struct.lattice: match_dict[strain] = stress elastics = ElasticTensor.from_stress_dict(match_dict) with open("elasts.txt", 'w') as f: f.write(str(elastics.voigt) + '\n') f.write(str(elastics.k_voigt) + '\n')