qhp.py 5.29 KB
Newer Older
1
import numpy as np
2
from fnmatch import fnmatch
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
3
4
import os
import argparse
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
5
import setup_paths
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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)

21
def prep_ref(ref_listP, ref_listS, Emit, kindP, kindS):
22
#    sCalc = Emit.openSection("section_calculation_to_calculation_refs")
23
    for ref in ref_listP:
24
25
        sCalc = Emit.openSection("section_calculation_to_calculation_refs")

26
27
        Emit.addValue("calculation_to_calculation_kind", kindP)
        Emit.addValue("calculation_to_calculation_external_url", ref)
28
        Emit.closeSection("section_calculation_to_calculation_refs", sCalc)
29
    sCalc = Emit.openSection("section_calculation_to_calculation_refs")
30
    for ref in ref_listS:
31
        sCalc = Emit.openSection("section_calculation_to_calculation_refs")
32
33
        Emit.addValue("calculation_to_calculation_kind", kindS)
        Emit.addValue("calculation_to_calculation_external_url", ref)
34
        Emit.closeSection("section_calculation_to_calculation_refs", sCalc)
35
36


37
38
39
40
41
42
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)
43
    Parse.addValue("x_qhp_formula", material)
44
45
    Parse.closeSection("section_system", system)
    results = Parse.openSection("section_single_configuration_calculation")
46
47
48
49
50
    #fref = Parse.openSection("section_calculation_to_calculation_refs")
    #Parse.addValue("calculation_to_calculation_kind", "source_folder")
    #Parse.addValue("calculation_to_calculation_external_url", refname)
    #Parse.closeSection("section_calculation_to_calculation_refs", fref)
    prep_ref(Phonon_path, Static_path, Parse, "source_phonon_calculations", "source_static_calculations")
Hagen-Henrik Kowalski's avatar
bugfix    
Hagen-Henrik Kowalski committed
51
    frameSeq = Parse.openSection("section_frame_sequence")
Hagen-Henrik Kowalski's avatar
fix    
Hagen-Henrik Kowalski committed
52
    Parse.addArrayValues("frame_sequence_local_frames_ref", np.array([results]))
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
53
    sTD = Parse.openSection("section_thermodynamical_properties")
54
55
56
57
58
59
60
    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)
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
61
    Parse.closeSection("section_frame_sequence", frameSeq)
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    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:
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
76
        mainDir = os.path.dirname(args.mainFilePath)
77
        os.chdir(mainDir)
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
78
    with open("Quasi-harmonic_properties.txt") as qh:
79
80
        for line in qh:
            if "Quasi-harmonic" in line:
81
82
                spacegroup = int(line.split()[-1])
                material = str(line.split()[-3])
83
    name = args.mainFilePath
84
    refname = name.split("/Quasi-harmonic_properties.txt")[0]
85
86
87
88
89
90
91
92
93
94
95
96
97
    #cwd_ref = os.getcwd(refname)
    con_ref = os.listdir(mainDir)
    Phonon_path = []
    Static_path = []
    for con in con_ref:
        if fnmatch(con, "Phonon*"):
            for sub in os.listdir("%s/%s" % (refname, con)):
                if fnmatch(sub, "phonopy-FHI-aims-displacement*"):
                    Phonon_path.append("%s/%s/%s/%s.out" % (refname,con,sub,sub))
        elif fnmatch(con, "Murn_data"):
            for sub in os.listdir("%s/%s" % (refname, con)):
                if fnmatch(sub, "aims*"):
                    Static_path.append("%s/%s/%s" % (refname,con,sub))
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
98
    T, V, alpha, B, Free, cV = np.loadtxt("Quasi-harmonic_properties.txt").T
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
99
    cV = kBoltzmann * cV
Hagen-Henrik Kowalski's avatar
Hagen-Henrik Kowalski committed
100
101
    cubAtocubm = convert_unit_function('angstrom**3', 'meter**3')
    eVpercubAtoJoulespercubm = convert_unit_function('eV*angstrom**-3', 'joules*meter**-3')
102
103
104
105
106
107
108
    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)