fixing repo tags infrastructure, "meat" is missing

parent cd4c42c3
......@@ -8,8 +8,32 @@ import logging
base_path = os.path.abspath(os.path.dirname(__file__))
def calculateTags(inputDict, backend):
pass
def calculateTags(inputDict, backend, calcUri):
repoSectUri = inputDict.get("section_repository_info.uri")
if repoSectUri:
backend.openContext(repoSectUri)
else:
backend.openContext(calcUri)
repoSect = backend.openSection("section_repository_info")
# fill out i.e. backend.addValue unsing input Dict
# "repository_checksum",
# "repository_chemical_formula",
# "repository_parser_id",
# "repository_atomic_elements",
# "repository_basis_set_type",
# "repository_code_version",
# "repository_crystal_system",
# "repository_program_name",
# "repository_spacegroup_nr",
# "repository_system_type",
# "repository_xc_treatment"
# add more?
if repoSectUri:
backend.closeContext(repoSectUri)
else:
backend.closeSection("section_repository_info", repoSect)
backend.closeContext(calcUri)
sys.stdout.flush()
def main():
metapath = '../../../../nomad-meta-info/meta_info/nomad_meta_info/' +\
......@@ -22,9 +46,9 @@ def main():
extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS,
uri=None)
backend = JsonParseEventsWriterBackend(metaInfoEnv)
calcContext = sys.argv[1]
calcUri = sys.argv[1]
backend.startedParsingSession(
calcContext,
calcUri,
parserInfo = {'name':'RepoTagsNormalizer', 'version': '1.0'})
dictReader=ParseStreamedDicts(sys.stdin)
......@@ -33,6 +57,9 @@ def main():
inputDict=dictReader.readNextDict()
if inputDict is None:
break
calculateTags(inputDict,backend)
calculateTags(inputDict,backend, calcUri)
backend.finishedParsingSession("ParseSuccess", None)
sys.stdout.flush()
if __name__ == "__main__":
main()
......@@ -5,11 +5,14 @@ import eu.nomad_lab.DefaultPythonInterpreter
import org.{ json4s => jn }
import scala.collection.breakOut
import eu.nomad_lab.normalize.ExternalNormalizerGenerator
import eu.nomad_lab.normalize.Normalizer
import eu.nomad_lab.meta
import eu.nomad_lab.ref.ObjectKind
import eu.nomad_lab.query
import eu.nomad_lab.resolve._
import eu.nomad_lab.h5.EmitJsonVisitor
import eu.nomad_lab.h5.H5EagerScanner
import eu.nomad_lab.h5.SectionH5
import eu.nomad_lab.parsers.ExternalParserWrapper
import eu.nomad_lab.JsonUtils
import scala.collection.mutable.StringBuilder
......@@ -48,14 +51,15 @@ object RepoTagsNormalizer extends ExternalNormalizerGenerator(
) ++ DefaultPythonInterpreter.commonDirMapping(),
metaInfoEnv = lab.meta.KnownMetaInfoEnvs.all
) {
val trace: Boolean = false
override def stdInHandler(context: ResolvedRef)(wrapper: ExternalParserWrapper)(pIn: java.io.OutputStream): Unit = {
/* val out: java.io.Writer = if (trace)
val trace = Normalizer.trace
val out: java.io.Writer =
new java.io.BufferedWriter(new java.io.OutputStreamWriter(pIn));
val stringBuilder = if (trace)
new StringBuilder
else
null
val stringBuilder = new StringBuilder
def writeOut(s: String): Unit = {
out.write(s)
if (trace) stringBuilder ++= s
......@@ -74,47 +78,56 @@ object RepoTagsNormalizer extends ExternalNormalizerGenerator(
case Calculation(archiveSet, c) =>
val programNames: Set[String] = (for (v <- c.valueTable(Seq("section_run", "program_name"))) yield (v.stringValue))(breakOut)
val programVersions: Set[String] = (for (v <- c.valueTable(Seq("section_run", "program_version"))) yield (v.stringValue))(breakOut)
val xcFunctionals: Set[String] = (for (v <- c.valueTable(Seq("section_run", "section_method", "section_xc_functionals", "xc_functional_name"))) yield (v.stringValue))(breakOut)
val xcFunctionals: Set[String] = (for (v <- c.valueTable(Seq("section_run", "section_method", "section_XC_functionals", "XC_functional_name"))) yield (v.stringValue))(breakOut)
val electronicStructureMethods: Set[String] = (for (v <- c.valueTable(Seq("section_run", "section_method", "electronic_structure_method"))) yield (v.stringValue))(breakOut)
val singleConfSections = c.sectionTable(Seq("section_run", "section_single_configuration_calculation"))
val singleConfSections = c.sectionTable(Seq("section_run", "section_single_configuration_calculation"))
val nEnergyEvaluations = singleConfSections.lengthL
var lastEnergyEval: Option[SectionH5] = None
var lastGeomery: Option[SectionH5] = None
var lastGeometry: Option[SectionH5] = None
var lastEnergy: Option[Double] = None
if (nEnergyEvaluations > 0) {
lastEnergyEval = Some(singleConfSections(nEnergyEvaluations-1))
lastGeomery = lastEnergyEval.maybeValue("single_configuration_calculation_to_system_ref") match {
val lastEnergyEval: SectionH5 = singleConfSections(nEnergyEvaluations - 1)
lastGeometry = lastEnergyEval.maybeValue("single_configuration_calculation_to_system_ref").map(_.longValue) match {
case Some(idx) =>
val sysSections = c.sectionTable(Seq("section_run", "section_system"))
val sysSections = c.sectionTable(Seq("section_run", "section_system"))
Some(sysSections(idx))
case None =>
None
}
lastEnergy = lastEnergyEval.maybeValue("energy_total").map(_.doubleValue)
}
val repoInfo = c.sectionTable(Seq("section_repository_info"))
writeOut(s"""{
"program_name": ${JsonUtils.normalizedStr(jn.JArray(programNames.map(jn.JString(_))(breakOut))},
"program_version": ${JsonUtils.normalizedStr(jn.JArray(programVersions.map(jn.JString(_))(breakOut))},
"xc_functional_name": ${JsonUtils.normalizedStr(jn.JArray(xcFunctionals.map(jn.JString(_))(breakOut))},
"electronic_structure_method": ${JsonUtils.normalizedStr(jn.JArray(electronicStructureMethods.map(jn.JString(_))(breakOut))},
"program_name": ${JsonUtils.normalizedStr(jn.JArray(programNames.map(jn.JString(_))(breakOut)))},
"program_version": ${JsonUtils.normalizedStr(jn.JArray(programVersions.map(jn.JString(_))(breakOut)))},
"XC_functional_name": ${JsonUtils.normalizedStr(jn.JArray(xcFunctionals.map(jn.JString(_))(breakOut)))},
"electronic_structure_method": ${JsonUtils.normalizedStr(jn.JArray(electronicStructureMethods.map(jn.JString(_))(breakOut)))},
"section_single_confguration_calculation.length": ${nEnergyEvaluations},
"energy_total.last": ${lastEnergy.getOrElse("null"),
"energy_total.last": ${lastEnergy.getOrElse("null")},
"section_system.last": """)
lastGeometry match {
case None => "null"
case Some(geo) =>
val visitor = new EmitJsonVisitor(
writeOut = writeOut
)
val scanner = new H5EagerScanner
scanner.scanResolvedRef(Section(archiveSet, geo), visitor)
}
writeOut("}\n")
writeOut(""",
"section_repository_info.uri": """)
if (repoInfo.isEmpty)
writeOut("null")
else
writeOut(JsonUtils.escapeString(repoInfo(0).toRef.toUriStr(ObjectKind.NormalizedData)))
writeOut("}]\n")
flush()
case r =>
case r =>
throw new Exception(s"RepoTagsNormalizer expected a calculation as context, but got $r")
}
} finally {
out.close()
pIn.close()
wrapper.sendStatus = ExternalParserWrapper.SendStatus.Finished
}*/
}
}
}
[{
"program_name": ["FHI-aims"],
"program_version": ["081912"],
"XC_functional_name": ["GGA_C_PBE","GGA_X_PBE"],
"electronic_structure_method": ["DFT"],
"section_single_confguration_calculation.length": 1,
"energy_total.last": null,
"section_system.last": {
"type": "nomad_section_2_0",
"name": "section_system",
"gIndex": 0,
"uri": "nmd://N0jqPXU7FP2SaaH8sMvXrW0DZsK0Z/CGivpJxhUx8d3FzFw7jHDjE51ZlOK/section_run/0c/section_system/0c",
"atom_labels": {"flatData":["Au","Au","Au","O","O","H"],"shape":[6]},
"atom_positions": {"flatData":[4.903707E-10,5.365501E-10,5.622263000000001E-10,7.491290000000001E-10,5.132975E-10,5.667301E-10,9.918509000000001E-10,5.750429E-10,5.194042E-10,1.1977479E-9,5.786581000000001E-10,5.245453000000001E-10,1.2591336E-9,5.101932E-10,4.114972E-10,1.2846226E-9,4.2635300000000006E-10,4.542142E-10],"shape":[6,3]}
},
"section_repository_info.uri": null}]
[{
"program_name": ["FHI-aims"],
"program_version": ["081912"],
"XC_functional_name": ["GGA_C_PBE","GGA_X_PBE"],
"electronic_structure_method": ["DFT"],
"section_single_confguration_calculation.length": 1,
"energy_total.last": null,
"section_system.last": {
"type": "nomad_section_2_0",
"name": "section_system",
"gIndex": 0,
"uri": "nmd://N0jqPXU7FP2SaaH8sMvXrW0DZsK0Z/CGivpJxhUx8d3FzFw7jHDjE51ZlOK/section_run/0c/section_system/0c",
"atom_labels": {"flatData":["Au","Au","Au","O","O","H"],"shape":[6]},
"atom_positions": {"flatData":[4.903707E-10,5.365501E-10,5.622263000000001E-10,7.491290000000001E-10,5.132975E-10,5.667301E-10,9.918509000000001E-10,5.750429E-10,5.194042E-10,1.1977479E-9,5.786581000000001E-10,5.245453000000001E-10,1.2591336E-9,5.101932E-10,4.114972E-10,1.2846226E-9,4.2635300000000006E-10,4.542142E-10],"shape":[6,3]}
},
"section_repository_info.uri": "nmd://N0jqPXU7FP2SaaH8sMvXrW0DZsK0Z/CGivpJxhUx8d3FzFw7jHDjE51ZlOK/section_repository_info/0c"
}]
Markdown is supported
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