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