qhp.py 3.63 KB
Newer Older
1
import numpy as np
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
2
import setup_paths
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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.units import EvTokJmol, Kb as kBoltzmann

parser_info = {"name": "parser_quasi_harmonic_properties", "version": "1.0"}

path = "../../../../nomad-meta-info/meta_info/nomad_meta_info/quasi-harmonic-properties.nomadmetainfo.json"
metaInfoPath = os.path.normpath(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), path))
metaInfoEnv, warns = loadJsonFile(filePath=metaInfoPath,
                                  dependencyLoader=None,
                                  extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS,
                                  uri=None)

def parse(name):
    Parse = JsonParseEventsWriterBackend(metaInfoEnv)
    Parse.startedParsingSession(name, parser_info)
    sRun = Parse.openSection("section_run")
    system = Parse.openSection("section_system")
    Parse.addValue("spacegroup_3D_number", spacegroup)
    springermat = Parse.openSection("section_springer_material")
    Parse.addValue("springer_formula", material)
    Parse.closeSection("section_springer_material", springermat)
    Parse.closeSection("section_system", system)
    results = Parse.openSection("section_single_configuration_calculation")
    sTD = Parse.openSection("section_thermodynamical_properties")
    fref = Parse.openSection("section_calculation_to_folder_refs")
    Parse.addValue("calculation_to_folder_kind", "folder_containing_calculations")
    Parse.addValue("calculation_to_folder_external_url", name)
    Parse.closeSection("section_calculation_to_folder_refs", fref)
    Parse.addArrayValues("thermodynamical_property_temperature", T)
    Parse.addArrayValues("thermodynamical_property_heat_capacity_C_v", cV)
    Parse.addArrayValues("x_qhp_quasi_harmonic_free_energy", Free)
    Parse.addArrayValues("x_qhp_quasi_harmonic_bulk_modulus", B)
    Parse.addArrayValues("x_qhp_quasi_harmonic_volume", V)
    Parse.addArrayValues("x_qhp_quasi_harmonic_thermal_expansion", alpha)
    Parse.closeSection("section_thermodynamical_properties", sTD)
    Parse.closeSection("section_single_configuration_calculation", results)
    Parse.closeSection("section_run", sRun)
    Parse.finishedParsingSession("ParseSuccess", None)

if __name__ == '__main__':
    import sys
    parser = argparse.ArgumentParser(description='Parses a txt file containing quasi harmonic data.')
    parser.add_argument('mainFileUri',
                        help='The uri of the main file associated with this calculation.')
    parser.add_argument('mainFilePath', default = None,
                        help='The path to the main file associated with this calculation.')

    args = parser.parse_args()
    if args.mainFilePath:
        mainDir = os.path.dirname(os.path.dirname(os.path.abspath(args.mainFilePath)))
        os.chdir(mainDir)
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
57
    with open("Quasi-harmonic_properties.txt") as qh:
58
59
60
61
62
        for line in qh:
            if "Quasi-harmonic" in line:
                spacegroup = line.split()[-1]
                material = line.split()[-3]
    name = args.mainFileUri
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
63
    T, V, alpha, B, Free, cV = np.loadtxt("Quasi-harmonic_properties.txt").T
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
64
    cV = kBoltzmann * cV
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
65
66
    cubAtocubm = convert_unit_function('angstrom**3', 'meter**3')
    eVpercubAtoJoulespercubm = convert_unit_function('eV*angstrom**-3', 'joules*meter**-3')
67
68
69
70
71
72
73
    eVtoJoules = convert_unit_function('eV', 'joules')
    eVperKtoJoules = convert_unit_function('eV*K**-1', 'joules*K**-1')
    Free = eVtoJoules(Free)     
    V = cubAtocubm(V)
    B = eVpercubAtoJoulespercubm(B)
    cV = eVperKtoJoules(cV)
    parse(name)