Skip to content
Snippets Groups Projects
Commit be07b559 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Reimplemented the fairdi integration.

parent a41c1213
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,7 @@ from phonopy.units import * ...@@ -37,6 +37,7 @@ from phonopy.units import *
from nomadcore.unit_conversion.unit_conversion import convert_unit_function from nomadcore.unit_conversion.unit_conversion import convert_unit_function
from nomadcore.parser_backend import * from nomadcore.parser_backend import *
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from phonopy.structure.atoms import PhonopyAtoms as Atoms
phonopy_version = __version__ phonopy_version = __version__
parser_info = {"name": "parser_phonopy", "version": "1.0"} parser_info = {"name": "parser_phonopy", "version": "1.0"}
...@@ -49,24 +50,31 @@ metaInfoEnv, warnings = loadJsonFile( ...@@ -49,24 +50,31 @@ metaInfoEnv, warnings = loadJsonFile(
extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None) extraArgsHandling = InfoKindEl.ADD_EXTRA_ARGS, uri = None)
from phonopy.structure.atoms import PhonopyAtoms as Atoms class PhonopyParserWrapper():
""" A proper class envolop for running this parser using Noamd-FAIRD infra. """
def __init__(self, backend, **kwargs):
self.backend_factory = backend
def parse(self, mainfile):
logging.info('phonopy parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory(metaInfoEnv)
# Call the old parser without a class.
mainDir = os.path.dirname(os.path.dirname(os.path.abspath(mainfile)))
cwd = os.getcwd()
os.chdir(mainDir)
try:
return parse_without_class(mainfile, backend)
finally:
os.chdir(cwd)
def parse_without_class(name, backend, parser_info): def parse_without_class(name, backend):
""" Parsing method for phonopy. cell_obj = read_aims("geometry.in")
Args:
name: file_name to parse
backend: Localbackend object
parser_info: information about parser to be saved.
"""
# Settings that were previously defined in main().
dir_name = os.path.dirname(name)
geometry_file = os.path.join(dir_name, "geometry.in")
cell_obj = read_aims(geometry_file)
cell = cell_obj.get_cell() cell = cell_obj.get_cell()
positions = cell_obj.get_positions() positions = cell_obj.get_positions()
symbols = np.array(cell_obj.get_chemical_symbols()) symbols = np.array(cell_obj.get_chemical_symbols())
control = Control(file = os.path.join(dir_name, "control.in")) control = Control()
if (len(control.phonon["supercell"]) == 3): if (len(control.phonon["supercell"]) == 3):
supercell_matrix = np.diag(control.phonon["supercell"]) supercell_matrix = np.diag(control.phonon["supercell"])
elif (len(control.phonon["supercell"]) == 9): elif (len(control.phonon["supercell"]) == 9):
...@@ -76,8 +84,7 @@ def parse_without_class(name, backend, parser_info): ...@@ -76,8 +84,7 @@ def parse_without_class(name, backend, parser_info):
#### ####
#### constructing FORCE_CONSTANTS #### constructing FORCE_CONSTANTS
set_of_forces, phonopy_obj, Relative_Path = Collect_Forces_aims( set_of_forces, phonopy_obj, Relative_Path = Collect_Forces_aims(cell_obj, supercell_matrix, displacement, sym)
cell_obj, supercell_matrix, displacement, sym, dir_name)
Prep_Path = name.split("phonopy-FHI-aims-displacement-") Prep_Path = name.split("phonopy-FHI-aims-displacement-")
Whole_Path = [] Whole_Path = []
for Path in Relative_Path: for Path in Relative_Path:
...@@ -104,10 +111,9 @@ def parse_without_class(name, backend, parser_info): ...@@ -104,10 +111,9 @@ def parse_without_class(name, backend, parser_info):
positions = convert_angstrom(positions) positions = convert_angstrom(positions)
displacement = convert_angstrom(displacement) displacement = convert_angstrom(displacement)
# Previously was the start of the parser. #### parsing
pbc = np.array((1, 1, 1), bool) pbc = np.array((1, 1, 1), bool)
Parse = backend # Previous dev. called backend Parse. Parse = backend
# Parse = JsonParseEventsWriterBackend(metaInfoEnv)
Parse.startedParsingSession(name, parser_info) Parse.startedParsingSession(name, parser_info)
sRun = Parse.openSection("section_run") sRun = Parse.openSection("section_run")
Parse.addValue("program_name", "Phonopy") Parse.addValue("program_name", "Phonopy")
...@@ -144,26 +150,10 @@ def parse_without_class(name, backend, parser_info): ...@@ -144,26 +150,10 @@ def parse_without_class(name, backend, parser_info):
Parse.closeSection("section_single_configuration_calculation", results) Parse.closeSection("section_single_configuration_calculation", results)
Parse.closeSection("section_run", sRun) Parse.closeSection("section_run", sRun)
Parse.finishedParsingSession("ParseSuccess", None) Parse.finishedParsingSession("ParseSuccess", None)
return Parse # Return the local backend to which we have been writing.
class PhonopyParserWrapper():
""" A proper class envolop for running this parser using Noamd-FAIRD infra. """
def __init__(self, backend, **kwargs):
self.backend_factory = backend
def parse(self, mainfile):
logging.info('phonopy parser started')
logging.getLogger('nomadcore').setLevel(logging.WARNING)
backend = self.backend_factory(metaInfoEnv)
# Call the old parser without a class.
parserInfo = parser_info
backend = parse_without_class(mainfile, backend, parserInfo)
return backend
return backend
#### determening properties of the undisplaced cell
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
...@@ -180,47 +170,6 @@ if __name__ == '__main__': ...@@ -180,47 +170,6 @@ if __name__ == '__main__':
mainDir = os.path.dirname(os.path.dirname(os.path.abspath(args.mainFilePath))) mainDir = os.path.dirname(os.path.dirname(os.path.abspath(args.mainFilePath)))
os.chdir(mainDir) os.chdir(mainDir)
name = args.mainFileUri name = args.mainFileUri
cell_obj = read_aims("geometry.in") backend = JsonParseEventsWriterBackend(metaInfoEnv)
cell = cell_obj.get_cell()
positions = cell_obj.get_positions()
symbols = np.array(cell_obj.get_chemical_symbols())
control = Control()
if (len(control.phonon["supercell"]) == 3):
supercell_matrix = np.diag(control.phonon["supercell"])
elif (len(control.phonon["supercell"]) == 9):
supercell_matrix = np.array(control.phonon["supercell"]).reshape(3,3)
displacement = control.phonon["displacement"]
sym = control.phonon["symmetry_thresh"]
####
#### constructing FORCE_CONSTANTS
set_of_forces, phonopy_obj, Relative_Path = Collect_Forces_aims(cell_obj, supercell_matrix, displacement, sym)
Prep_Path = name.split("phonopy-FHI-aims-displacement-")
Whole_Path = []
for Path in Relative_Path:
Whole_Path.append("%s%s" % (Prep_Path[0], Path))
phonopy_obj.set_forces(set_of_forces)
phonopy_obj.produce_force_constants()
FC2 = phonopy_obj.get_force_constants()
####
#### obtaining information about supercell
super_c=phonopy_obj.supercell
s_cell = super_c.get_cell()
super_pos = super_c.get_positions()
super_sym = np.array(super_c.get_chemical_symbols())
####
#### Converting properties to Si unitis
converter_FC2 = convert_unit_function('eV*angstrom**-2', 'joules*meter**-2')
convert_angstrom = convert_unit_function('angstrom', 'meter')
FC2 = converter_FC2(FC2)
cell = convert_angstrom(cell)
s_cell = convert_angstrom(s_cell)
super_pos = convert_angstrom(super_pos)
positions = convert_angstrom(positions)
displacement = convert_angstrom(displacement)
#### parsing
parse(name)
parse_without_class(name, backend)
...@@ -114,7 +114,7 @@ def generate_kPath_ase(cell, symprec): ...@@ -114,7 +114,7 @@ def generate_kPath_ase(cell, symprec):
return parameters return parameters
#### ####
def Collect_Forces_aims(cell_obj, supercell_matrix, displacement, sym, dir_name, tol = 1e-6): def Collect_Forces_aims(cell_obj, supercell_matrix, displacement, sym, tol = 1e-6):
symmetry = Symmetry(cell_obj) symmetry = Symmetry(cell_obj)
phonopy_obj = Phonopy(cell_obj, phonopy_obj = Phonopy(cell_obj,
supercell_matrix, supercell_matrix,
...@@ -130,11 +130,8 @@ def Collect_Forces_aims(cell_obj, supercell_matrix, displacement, sym, dir_name, ...@@ -130,11 +130,8 @@ def Collect_Forces_aims(cell_obj, supercell_matrix, displacement, sym, dir_name,
Relative_Path = [] Relative_Path = []
for directory, supercell in zip(directories, supercells): for directory, supercell in zip(directories, supercells):
aims_out = os.path.join(directory, directory + ".out") aims_out = os.path.join(directory, directory + ".out")
# Added below line for NOMAD-FAIRD
aims_out = os.path.join(dir_name, aims_out)
if not os.path.isfile(aims_out): if not os.path.isfile(aims_out):
logging.warn("!!! file not found: %s" % aims_out) logging.warn("!!! file not found: %s" % aims_out)
os.chdir(os.path.join(dir_name, directory))
cwd = os.getcwd() cwd = os.getcwd()
con_list = os.listdir(cwd) con_list = os.listdir(cwd)
check_var = False check_var = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment