Commit d1803f6e authored by Mohamed, Fawzi Roberto (fawzi)'s avatar Mohamed, Fawzi Roberto (fawzi)
Browse files

Making band structure normalizer compile...

parent fb2a7938
...@@ -8,7 +8,9 @@ import eu.nomad_lab.normalize.ExternalNormalizerGenerator ...@@ -8,7 +8,9 @@ import eu.nomad_lab.normalize.ExternalNormalizerGenerator
import eu.nomad_lab.meta import eu.nomad_lab.meta
import eu.nomad_lab.query import eu.nomad_lab.query
import eu.nomad_lab.resolve._ import eu.nomad_lab.resolve._
import eu.nomad_lab.ref.NomadUri
import eu.nomad_lab.h5.EmitJsonVisitor import eu.nomad_lab.h5.EmitJsonVisitor
import eu.nomad_lab.h5.SectionH5
import eu.nomad_lab.h5.H5EagerScanner import eu.nomad_lab.h5.H5EagerScanner
import eu.nomad_lab.parsers.ExternalParserWrapper import eu.nomad_lab.parsers.ExternalParserWrapper
import eu.nomad_lab.JsonUtils import eu.nomad_lab.JsonUtils
...@@ -30,7 +32,7 @@ object BandStructureNormalizer extends ExternalNormalizerGenerator( ...@@ -30,7 +32,7 @@ object BandStructureNormalizer extends ExternalNormalizerGenerator(
)) :: Nil )) :: Nil
), ),
context = "calculation_context", context = "calculation_context",
filter = query.CompiledQuery(query.QueryExpression("section_k_band and not section_k_band_normalized"), meta.KnownMetaInfoEnvs.all), filter = query.CompiledQuery(query.QueryExpression("section_k_band" /*" and not section_k_band_normalized" */ ), meta.KnownMetaInfoEnvs.all),
cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/normalizers/band-structure/normalizer/normalizer-band-structure/normalizer_band_structure.py", cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/normalizers/band-structure/normalizer/normalizer-band-structure/normalizer_band_structure.py",
"${context}", "${archivePath}"), "${context}", "${archivePath}"),
resList = Seq( resList = Seq(
...@@ -91,98 +93,108 @@ object BandStructureNormalizer extends ExternalNormalizerGenerator( ...@@ -91,98 +93,108 @@ object BandStructureNormalizer extends ExternalNormalizerGenerator(
refE match { refE match {
case Some(e) => case Some(e) =>
writeOut(s""", writeOut(s""",
| "$refEName": ${e.mkString("[",",","]")}""".stripMargin) | "$refEName": ${e.mkString("[", ",", "]")}""".stripMargin)
case None => () case None => ()
} }
} }
b.parentSection.map{ singleConf: SectionH5 => b.parentSection.foreach { singleConf: SectionH5 =>
val eFermi = singleConf.maybeValue("energy_reference_fermi")(_.seqDoubleValue) val eFermi = singleConf.maybeValue("energy_reference_fermi").map(_.seqDoubleValue())
writeOutRefE("energy_reference_fermi", eFermi) writeOutRefE("energy_reference_fermi", eFermi)
val eVbTop = singleConf.maybeValue("energy_reference_highest_occupied").map(_.seqDoubleValue) val eVbTop = singleConf.maybeValue("energy_reference_highest_occupied").map(_.seqDoubleValue())
writeOutRefE("energy_reference_highest_occupied", eVbTop) writeOutRefE("energy_reference_highest_occupied", eVbTop)
var contextsToGiveBack = Seq() var contextsToGiveBack: Seq[ResolvedRef] = Seq()
try { try {
// get DOS // get DOS
val dosInfo: Option[(Option[Seq[Double]], Option[Seq[Double]], SectionH5)] = b.parentSection.map{ singleConf: SectionH5 => val dosInfo: Option[(Option[Seq[Double]], Option[Seq[Double]], SectionH5)] = b.parentSection match {
// try locally case None => None
val dosColl = singleConf.subSectionCollection("section_dos") case Some(singleConf) =>
if (dosColl.length > 0) { // try locally
if (dosColl.length > 1) val dosColl = singleConf.subSectionCollection("section_dos")
logging.warn(s"multiple dos in $singleConf, using first") if (dosColl.length > 0) {
Some(eFermi, eVbTop, dosColl(0)) if (dosColl.length > 1)
} else { logger.warn(s"multiple dos in $singleConf, using first")
// look in archive Some(eFermi, eVbTop, dosColl(0))
val sysIdx = singleConf.maybeValue("single_configuration_calculation_to_system_ref").map( _.longValue ) } else {
// look in archive
val sys = singleConf.parentSection.map{ run: SectionH5 => singleConf.maybeValue("single_configuration_calculation_to_system_ref").map(_.longValue) match {
run.sectionTable("section_system")(sysIdx) case None => None
} case Some(sysIdx) =>
sys.maybeValue("configuration_raw_gid").map( _.stringValue) match { singleConf.parentSection.map { run: SectionH5 =>
case Some(confId) => run.table.subSectionTable("section_system")(sysIdx)
val possibleDosScanOp = new query.CollectUrisScanOp( } match {
context = "section_single_configuration_calculation", case None => None
filter = query.CompiledQuery(query.QueryExpression("section_dos and configuration_raw_gid = \"$confId\"")), case Some(sys) =>
metaInfoEnv0 = None) sys.maybeValue("configuration_raw_gid").map(_.stringValue) match {
val evaluator = new query.DirectArchiveScanner( case Some(confId) =>
archiveSet = archiveSet, val possibleDosScanOp = new query.CollectUrisScanOp(
archive = c.archive, context = "section_single_configuration_calculation",
scanOp = possibleDosScanOp filter = query.CompiledQuery(query.QueryExpression("section_dos and configuration_raw_gid = \"$confId\""), meta.KnownMetaInfoEnvs.all),
) metaInfoEnv0 = None
evaluator.run() )
val uris = possibleDosScanOp.uris val evaluator = new query.DirectArchiveScanner(
evaluator.cleanup() archiveSet = archiveSet,
if (uris.length > 0) { archive = c.archive,
if (uris.length > 1) { scanOp = possibleDosScanOp
logger.warn(s"found multiple DoS potentially matching to $b in archive: $uris, shoudl check method more carefully, skipping for now...") )
None evaluator.run()
} else { val uris = possibleDosScanOp.uris
val dosCtx = resolve.resolveInArchiveSet(archiveSet, NomadUri(uris(0)).toRef) evaluator.cleanup()
contextsToGiveBack += dosCtx if (uris.length > 0) {
dosCtx match { if (uris.length > 1) {
case Section(_,dosSingleConf) => logger.warn(s"found multiple DoS potentially matching to $b in archive: $uris, should check method more carefully, skipping for now...")
val dosEVbTop = dosSingleConf.maybeValue("energy_reference_highest_occupied").map(_.doubleValue) None
val dosEFermi = dosSingleConf.maybeValue("energy_reference_fermi").map(_.doubleValue) } else {
if (dosCollection.length > 0) { val dosCtx = Resolver.resolveInArchiveSet(archiveSet, NomadUri(uris(0)).toRef)
if (dosCollection.length > 1) contextsToGiveBack = contextsToGiveBack :+ dosCtx
logger.warn(s"multiple dos in $singleConf, using first") dosCtx match {
Some(dosEFermi, dosEVbTop, dosColl(0)) case Section(_, dosSingleConf) =>
} else { val dosEVbTop = dosSingleConf.maybeValue("energy_reference_highest_occupied").map(_.seqDoubleValue())
logger.warn(s"query error, expected a section_dos in $dosSingleConf") val dosEFermi = dosSingleConf.maybeValue("energy_reference_fermi").map(_.seqDoubleValue())
None val dosCollection = dosSingleConf.subSectionCollection("section_dos")
if (dosCollection.length > 0) {
if (dosCollection.length > 1)
logger.warn(s"multiple dos in $singleConf, using first")
Some((dosEFermi, dosEVbTop, dosColl(0)))
} else {
logger.warn(s"query error, expected a section_dos in $dosSingleConf")
None
}
case _ =>
logger.warn(s"query error, expected valid section as result of query, not ${dosCtx.uriString}")
None
}
}
} else {
None
}
case None =>
logger.warn(s"Could not find configuration_raw_gid for configuration of band structure $b, search of DoS failed.")
None
} }
case _ =>
logger.warn(s"query error, expected valid section as result of query, not ${dosCtx.uriString}")
None
} }
}
} else {
None
}
case None =>
logger.warn(s"Could not find configuration_raw_gid for configuration of band structure $b, search of DoS failed.")
None
}
}
}
} }
} dosInfo match {
dosInfo match { case Some((dFermi, dVBTop, dos)) =>
case Some((dFermi, dVBTop, dos)) => writeOut(""",
writeOut(""",
| "dos": { | "dos": {
| "section_dos":""".stripMargin) | "section_dos":""".stripMargin)
scanner.scanResolvedRef(Section(archiveSet, dos), visitor) scanner.scanResolvedRef(Section(archiveSet, dos), visitor)
writeOutRefE("energy_reference_fermi", dFermi) writeOutRefE("energy_reference_fermi", dFermi)
writeOutRefE("energy_reference_highest_occupied", dVBTop) writeOutRefE("energy_reference_highest_occupied", dVBTop)
writeOut("\n }") writeOut("\n }")
case None => () case None => ()
} }
} finally { } finally {
for (ctx <- contextsToGiveBack) for (ctx <- contextsToGiveBack)
ctx.giveBack() ctx.giveBack()
} }
writeOut("\n}") writeOut("\n}")
}
flush() flush()
} }
writeOut("]\n") writeOut("]\n")
......
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