def test_write_phonopy_yaml_extra(self): phonopy = self._get_phonon() settings = { 'force_sets': True, 'displacements': True, 'force_constants': True, 'born_effective_charge': True, 'dielectric_constant': True } phpy_yaml = PhonopyYaml(calculator='vasp', settings=settings) phpy_yaml.set_phonon_info(phonopy)
def get_phonopy_yaml_txt(structure, settings, supercell_matrix=None, primitive_matrix=None, calculator=None): unitcell = phonopy_atoms_from_structure(structure) ph = Phonopy(unitcell, supercell_matrix=settings['supercell_matrix'], primitive_matrix='auto', calculator=calculator) phpy_yaml = PhonopyYaml() phpy_yaml.set_phonon_info(ph) return str(phpy_yaml)
def run_task(self, fw_spec): unitcell = read_vasp("POSCAR-unitcell") phonon = phonopy.Phonopy(unitcell, self.get("supercell")) supercell = phonon.get_supercell() phonon.generate_displacements() supercells = phonon.supercells_with_displacements ids = np.arange(len(supercells)) + 1 write_supercells_with_displacements(supercell, supercells, ids) units = get_default_physical_units("vasp") phpy_yaml = PhonopyYaml(physical_units=units, settings={ 'force_sets': False, 'born_effective_charge': False, 'dielectric_constant': False, 'displacements': True }) phpy_yaml.set_phonon_info(phonon) with open("phonopy_disp.yaml", 'w') as w: w.write(str(phpy_yaml))
def test_write_phonopy_yaml_extra(ph_nacl_nofcsym: Phonopy): """Test PhonopyYaml.set_phonon_info, __str__, yaml_data, parse. settings parameter controls amount of yaml output. In this test, more data than the default are dumped and those are tested. """ phonon = ph_nacl_nofcsym settings = { "force_sets": True, "displacements": True, "force_constants": True, "born_effective_charge": True, "dielectric_constant": True, } phpy_yaml = PhonopyYaml(calculator="vasp", settings=settings) phpy_yaml.set_phonon_info(phonon) phpy_yaml_test = PhonopyYaml() phpy_yaml_test.yaml_data = yaml.safe_load(StringIO(str(phpy_yaml))) phpy_yaml_test.parse() np.testing.assert_allclose(phpy_yaml.force_constants, phpy_yaml_test.force_constants, atol=1e-8) np.testing.assert_allclose(phpy_yaml.nac_params["born"], phpy_yaml_test.nac_params["born"], atol=1e-8) np.testing.assert_allclose( phpy_yaml.nac_params["dielectric"], phpy_yaml_test.nac_params["dielectric"], atol=1e-8, ) np.testing.assert_allclose( phpy_yaml.nac_params["factor"], phpy_yaml_test.nac_params["factor"], atol=1e-8, ) disps, forces = get_displacements_and_forces(phpy_yaml.dataset) disps_test, forces_test = get_displacements_and_forces( phpy_yaml_test.dataset) np.testing.assert_allclose(forces, forces_test, atol=1e-8) np.testing.assert_allclose(disps, disps_test, atol=1e-8)
def test_write_phonopy_yaml(ph_nacl_nofcsym: Phonopy, helper_methods): """Test PhonopyYaml.set_phonon_info, __str__, yaml_data, parse.""" phonon = ph_nacl_nofcsym phpy_yaml = PhonopyYaml(calculator="vasp") phpy_yaml.set_phonon_info(phonon) phpy_yaml_test = PhonopyYaml() phpy_yaml_test.yaml_data = yaml.safe_load(StringIO(str(phpy_yaml))) phpy_yaml_test.parse() helper_methods.compare_cells_with_order(phpy_yaml.primitive, phpy_yaml_test.primitive) helper_methods.compare_cells_with_order(phpy_yaml.unitcell, phpy_yaml_test.unitcell) helper_methods.compare_cells_with_order(phpy_yaml.supercell, phpy_yaml_test.supercell) assert phpy_yaml.version == phpy_yaml_test.version np.testing.assert_allclose(phpy_yaml.supercell_matrix, phpy_yaml_test.supercell_matrix, atol=1e-8) np.testing.assert_allclose(phpy_yaml.primitive_matrix, phpy_yaml_test.primitive_matrix, atol=1e-8)
import phonopy from phonopy.interface.phonopy_yaml import PhonopyYaml phonon = phonopy.load(supercell_matrix=[[2, 0, 0], [0, 2, 0], [0, 0, 2]], primitive_matrix=[[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]], unitcell_filename="POSCAR-unitcell", force_sets_filename="FORCE_SETS", born_filename="BORN") phpy_yaml = PhonopyYaml(calculator='vasp', settings={'force_constants': True}) phpy_yaml.set_phonon_info(phonon) print(phpy_yaml)
def test_write_phonopy_yaml(self): phonopy = self._get_phonon() phpy_yaml = PhonopyYaml(calculator='vasp') phpy_yaml.set_phonon_info(phonopy)
from phonopy import Phonopy from phonopy.interface.vasp import read_vasp from phonopy.file_IO import parse_FORCE_SETS, parse_BORN from phonopy.interface.phonopy_yaml import PhonopyYaml unitcell = read_vasp("POSCAR") phonon = Phonopy(unitcell, [[2, 0, 0], [0, 2, 0], [0, 0, 2]], primitive_matrix=[[0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]) force_sets = parse_FORCE_SETS() phonon.set_displacement_dataset(force_sets) phonon.produce_force_constants() primitive = phonon.get_primitive() nac_params = parse_BORN(primitive, filename="BORN") phonon.set_nac_params(nac_params) phpy_yaml = PhonopyYaml(calculator='vasp', show_force_constants=True) phpy_yaml.set_phonon_info(phonon) print(phpy_yaml)