Commit be07b559 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Reimplemented the fairdi integration.

parent a41c1213
......@@ -37,6 +37,7 @@ from phonopy.units import *
from nomadcore.unit_conversion.unit_conversion import convert_unit_function
from nomadcore.parser_backend import *
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from phonopy.structure.atoms import PhonopyAtoms as Atoms
phonopy_version = __version__
parser_info = {"name": "parser_phonopy", "version": "1.0"}
......@@ -49,24 +50,31 @@ metaInfoEnv, warnings = loadJsonFile(
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):
""" Parsing method for phonopy.
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)
def parse_without_class(name, backend):
cell_obj = read_aims("geometry.in")
cell = cell_obj.get_cell()
positions = cell_obj.get_positions()
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):
supercell_matrix = np.diag(control.phonon["supercell"])
elif (len(control.phonon["supercell"]) == 9):
......@@ -76,8 +84,7 @@ def parse_without_class(name, backend, parser_info):
####
#### constructing FORCE_CONSTANTS
set_of_forces, phonopy_obj, Relative_Path = Collect_Forces_aims(
cell_obj, supercell_matrix, displacement, sym, dir_name)
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:
......@@ -104,10 +111,9 @@ def parse_without_class(name, backend, parser_info):
positions = convert_angstrom(positions)
displacement = convert_angstrom(displacement)
# Previously was the start of the parser.
#### parsing
pbc = np.array((1, 1, 1), bool)
Parse = backend # Previous dev. called backend Parse.
# Parse = JsonParseEventsWriterBackend(metaInfoEnv)
Parse = backend
Parse.startedParsingSession(name, parser_info)
sRun = Parse.openSection("section_run")
Parse.addValue("program_name", "Phonopy")
......@@ -144,26 +150,10 @@ def parse_without_class(name, backend, parser_info):
Parse.closeSection("section_single_configuration_calculation", results)
Parse.closeSection("section_run", sRun)
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__':
import sys
......@@ -180,47 +170,6 @@ if __name__ == '__main__':
mainDir = os.path.dirname(os.path.dirname(os.path.abspath(args.mainFilePath)))
os.chdir(mainDir)
name = args.mainFileUri
cell_obj = read_aims("geometry.in")
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)
backend = JsonParseEventsWriterBackend(metaInfoEnv)
parse_without_class(name, backend)
......@@ -114,7 +114,7 @@ def generate_kPath_ase(cell, symprec):
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)
phonopy_obj = Phonopy(cell_obj,
supercell_matrix,
......@@ -130,11 +130,8 @@ def Collect_Forces_aims(cell_obj, supercell_matrix, displacement, sym, dir_name,
Relative_Path = []
for directory, supercell in zip(directories, supercells):
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):
logging.warn("!!! file not found: %s" % aims_out)
os.chdir(os.path.join(dir_name, directory))
cwd = os.getcwd()
con_list = os.listdir(cwd)
check_var = False
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment