Planned maintenance on Wednesday, 2021-01-20, 17:00-18:00. Expect some interruptions during that time

fixed prototypes (requires updated proto info)

parent 4e36caa1
......@@ -35,6 +35,8 @@ from nomadcore.parse_streamed_dicts import ParseStreamedDicts
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.parser_backend import JsonParseEventsWriterBackend
from ase import Atoms
from systax import Class3DAnalyzer
#prototypes_file = os.path.normpath("/nomad-lab-base/analysis-tools/structural-similarity/python-modules/nomad_sim/structure_types.py")
......@@ -43,8 +45,6 @@ import sys
#sys.path.append('/home/beaker/py3k/lib/python3.5/')
import spglib
import logging
#LOGGER = logging.getLogger(__name__)
#logging.basicConfig(level=logging.ERROR)
......@@ -116,9 +116,8 @@ def get_structure_type(space_group, norm_wyckoff):
"""
structure_type_info = {}
for type_description in str_types_by_spg.get((space_group), []):
current_norm_wyckoffs = type_description.get("normalized_wyckoff_spg")
for type_description in str_types_by_spg.get(space_group, []):
current_norm_wyckoffs = type_description.get("normalized_wysytax")
if current_norm_wyckoffs and current_norm_wyckoffs == norm_wyckoff:
structure_type_info = type_description
break
......@@ -153,14 +152,45 @@ def dictToNarray(dictValue):
v=dictValue['flatData']
return np.reshape(np.asarray(v), dictValue['shape'])
def countNrs(l):
res = {}
for i in l:
res[i] = res.get(i, 0) + 1
return res
def protoNormalizeWycoff(protoDict):
"""recalculates the normalized wyckoff values for the given prototype dictionary"""
cell = np.asarray(protoDict['lattice_vectors'])
atomSpecies = [toAtomNr(at) for at in protoDict['atom_labels']]
labels = protoDict['atom_labels']
atomSpecies = [toAtomNr(at) for at in labels]
atomPos = np.asarray(protoDict['atom_positions'])
symm = systemToSpg(cell, atomSpecies, atomPos)
wyckoffs = symm.get("wyckoffs")
norm_wyckoff = get_normalized_wyckoff(atomSpecies,wyckoffs)
#symm = systemToSpg(cell, atomSpecies, atomPos)
atoms = Atoms(numbers=atomSpecies,
positions=1e10*atomPos,
cell=1e10*cell,
pbc=True
)
analyzer = Class3DAnalyzer(atoms, spglib_precision = 2*0.001)
space_group_number = analyzer.get_space_group_number()
if space_group_number != protoDict.get('Space Group Number'):
print('YYY space_group',space_group_number, 'does not match expected', protoDict)
return protoDict.get('normalized_wyckoff')
prim_sys = analyzer._get_spglib_primitive_system()
prim_num = prim_sys.get_atomic_numbers()
prim_pos = prim_sys.get_scaled_positions()
wyckoffs = analyzer._get_spglib_wyckoff_letters_primitive()
equiV = analyzer._get_spglib_equivalent_atoms_primitive()
#wyckoffs = symm.get("wyckoffs")
#if len(equiV) > len(prim_pos):
# fullNum = np.asarray(prim_num)[equiV].tolist()
# fullWyc = np.asarray(wyckoffs)[equiV].tolist()
#else:
# fullNum = prim_num
# fullWyc = wyckoffs
norm_wyckoff = get_normalized_wyckoff(prim_num, wyckoffs)
if protoDict.get('Space Group Number') == 230:
print('XXX')
print('XXX', "original atomSpecies:", countNrs(atomSpecies), "primitive numbers:", countNrs(prim_num), "equiV:", equiV, "fullNrs:", "original wyckoffs:", countNrs(wyckoffs), "normalized wyckoffs:",norm_wyckoff,"primitive scaled pos:",prim_pos)
return norm_wyckoff
def updatePrototypesWyckoff(protos):
......@@ -168,7 +198,8 @@ def updatePrototypesWyckoff(protos):
for protoDict in pts:
try:
wy = protoNormalizeWycoff(protoDict)
protoDict['normalized_wyckoff_spg'] = wy
if wy:
protoDict['normalized_wysytax'] = wy
except:
logging.exception("Failed to compute normalized wyckoffs for %s", json.dumps(protoDict))
......@@ -181,7 +212,7 @@ def systemToSpg(cell, atomSpecies, atomPos):
return symm
def classify_by_norm_wyckoff(sectionSystem):
def classify_section_system(sectionSystem):
try:
###
......@@ -211,9 +242,20 @@ def classify_by_norm_wyckoff(sectionSystem):
symm = systemToSpg(cell, atomSpecies, atomPos)
wyckoffs = symm.get("wyckoffs")
spg_nr = symm.get("number")
### adds recalculated wyckoff positions
updatePrototypesWyckoff(str_types_by_spg)
except:
#logging.exception("failure while computing for %r",json_file_name)
logging.exception("failure while computing for that example")
return classify_by_wyckoff(atomSpecies, wyckoffs, spg_nr)
def classify_by_wyckoff(atomSpecies, wyckoffs, spg_nr):
try:
#import pprint
#### adds recalculated wyckoff positions
#print(30*'-')
#updatePrototypesWyckoff(str_types_by_spg)
#print(30*'-')
#pprint.pprint(str_types_by_spg)
#print(30*'-')
###
norm_wyckoff = get_normalized_wyckoff(atomSpecies,wyckoffs)
......@@ -221,6 +263,7 @@ def classify_by_norm_wyckoff(sectionSystem):
if protoDict is None:
proto = "%d-_" % spg_nr
return {"prototype_label":proto}
else:
#if protoDict.get("Notes","") not in ["", "_", "-", "–"]:
# proto = '%d-%s' % (spg_nr, protoDict)
......@@ -229,12 +272,11 @@ def classify_by_norm_wyckoff(sectionSystem):
proto = '%d-%s-%s' % (spg_nr, protoDict.get("Prototype","-"),protoDict.get("Pearsons Symbol","-"))
aflow_prototype_id = protoDict.get("aflow_prototype_id","-")
aflow_prototype_url = protoDict.get("aflow_prototype_url","-")
return {"prototype_label":proto, "prototype_aflow_id":aflow_prototype_id, "prototype_aflow_url":aflow_prototype_url}
return {"prototype_label":proto, "prototype_aflow_id":aflow_prototype_id, "prototype_aflow_url":aflow_prototype_url}
except:
#logging.exception("failure while computing for %r",json_file_name)
logging.exception("failure while computing for that example")
return None
return {}
#classify_by_norm_wyckoff(json_list)
......@@ -245,10 +287,11 @@ def main():
metaInfoPath = os.path.normpath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), metapath))
metaInfoEnv, warns = loadJsonFile(filePath=metaInfoPath,
dependencyLoader=None,
extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS,
uri=None)
metaInfoEnv = None
#metaInfoEnv, warns = loadJsonFile(filePath=metaInfoPath,
# dependencyLoader=None,
# extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS,
# uri=None)
backend = JsonParseEventsWriterBackend(metaInfoEnv)
#Start
calcContext=sys.argv[1]
......@@ -263,25 +306,23 @@ def main():
sectSys = dictReader.readNextDict()
if sectSys is None:
break
try:
labels = classify_by_norm_wyckoff(sectSys)
if not set(['section_system_uri', 'wyckoff_letters_primitive', 'atomic_numbers_primitive', 'space_group_number']).issubset(sectSys):
continue
labels = classify_by_wyckoff(sectSys['atomic_numbers_primitive'], sectSys['wyckoff_letters_primitive'], sectSys['space_group_number'])
if labels:
backend.openContext(sectSys['uri'])
backend.openContext(sectSys['section_system_uri'])
pSect = backend.openSection("section_prototype")
backend.addValue("prototype_assignement_method", "normalized-wyckoff")
backend.addValue("prototype_label", labels['prototype_label'])
backend.addValue("prototype_aflow_id", labels["prototype_aflow_id"])
backend.addValue("prototype_aflow_url", labels["prototype_aflow_url"])
aid = labels.get("prototype_aflow_id")
if aid:
backend.addValue("prototype_aflow_id", aid)
aurl = labels.get("prototype_aflow_url")
if aurl:
backend.addValue("prototype_aflow_url", aurl)
backend.closeSection("section_prototype", pSect)
# backend.addValue("prototype_aflow_id", aflow_prototype_id)
# backend.addValue("prototype_aflow_url", aflow_prototype_url)
# if "aflow_prototype_url" in sectSys:
# backend.addValue("prototype_aflow_url",sectSys["aflow_prototype_url"])
backend.closeContext(sectSys['uri'])
backend.closeContext(sectSys['section_system_uri'])
sys.stdout.flush()
except:
logging.exception("exception trying to calculate prototype for %s",sectSys)
......@@ -293,4 +334,3 @@ def main():
if __name__ == '__main__':
main()
......@@ -22,11 +22,15 @@ import scala.collection.breakOut
import eu.nomad_lab.normalize.ExternalNormalizerGenerator
import eu.nomad_lab.meta
import eu.nomad_lab.query
import eu.nomad_lab.normalize.Normalizer
import eu.nomad_lab.resolve._
import eu.nomad_lab.ref.ObjectKind
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.JsonSupport
import eu.nomad_lab.JsonSupport.formats
import eu.nomad_lab.JsonUtils
import scala.collection.mutable.StringBuilder
......@@ -46,7 +50,7 @@ object PrototypesNormalizer extends ExternalNormalizerGenerator(
)) :: Nil
),
context = "calculation_context",
filter = query.CompiledQuery(query.QueryExpression("section_system"), meta.KnownMetaInfoEnvs.publicMeta),
filter = query.CompiledQuery(query.QueryExpression("wyckoff_letters_primitive"), meta.KnownMetaInfoEnvs.publicMeta),
cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/normalizers/prototypes/normalizer/normalizer-prototypes/classify4me_prototypes.py",
"${contextUri}", "${archivePath}"),
resList = Seq(
......@@ -64,10 +68,17 @@ object PrototypesNormalizer extends ExternalNormalizerGenerator(
) ++ DefaultPythonInterpreter.commonDirMapping(),
metaInfoEnv = lab.meta.KnownMetaInfoEnvs.all
) {
val trace: Boolean = false
case class PrototypeInfo(
section_system_uri: String,
wyckoff_letters_primitive: Seq[String],
atomic_numbers_primitive: Seq[Int],
space_group_number: Int
)
override def stdInHandler(context: ResolvedRef)(wrapper: ExternalParserWrapper)(pIn: java.io.OutputStream): Unit = {
val out: java.io.Writer = new java.io.BufferedWriter(new java.io.OutputStreamWriter(pIn));
val trace: Boolean = Normalizer.trace
val stringBuilder = if (trace)
new StringBuilder
else
......@@ -89,30 +100,39 @@ object PrototypesNormalizer extends ExternalNormalizerGenerator(
context match {
case Calculation(archiveSet, c) =>
val sysTable = c.sectionTable(Seq("section_run", "section_system"))
def outputSysSection(sysSection: SectionH5): Unit = {
if (!isFirst)
writeOut(",")
else
isFirst = false
//writeOut(s"""{
// | "context": ${JsonUtils.escapeString(m.toRef.toUriStr(archiveSet.objectKind))},
// | "section_system": """.stripMargin)
val visitor = new EmitJsonVisitor(
writeOut = writeOut
)
val scanner = new H5EagerScanner
scanner.scanResolvedRef(Section(archiveSet, sysSection), visitor)
//writeOut("}")
flush()
val symmetryTable = sysTable.subSectionTable("section_symmetry")
val stdSysTable = symmetryTable.subSectionTable("section_primitive_system")
var lastSys: Long = -1L
for (stdSys <- stdSysTable) {
val symm: SectionH5 = stdSys.parentSection.get
val symmMethod: Option[String] = symm.maybeValue("symmetry_method").map(_.stringValue)
symmMethod match {
case Some("spg_normalized") =>
val sysSection = symm.parentSection.get
if (sysSection.gIndex != lastSys) {
lastSys = sysSection.gIndex
for (atomNrs <- stdSys.maybeValue("atomic_numbers_primitive").map(_.seqLongValue())) {
for (wyckoffs <- stdSys.maybeValue("wyckoff_letters_primitive").map(_.seqStringValue())) {
for (spacegroup <- symm.maybeValue("space_group_number").map(_.intValue)) {
val pInfo = PrototypeInfo(
section_system_uri = sysSection.toRef.toUriStr(ObjectKind.NormalizedData),
wyckoff_letters_primitive = wyckoffs,
atomic_numbers_primitive = atomNrs.map(_.intValue),
space_group_number = spacegroup
)
if (!isFirst)
writeOut(",\n")
else
isFirst = false
writeOut(JsonSupport.writeNormalizedStr(pInfo))
flush()
}
}
}
}
case _ => ()
}
}
val nSys = sysTable.lengthL
if (nSys > 0)
outputSysSection(sysTable(0))
if (nSys > 1)
outputSysSection(sysTable(nSys - 1))
writeOut("]")
flush()
case r =>
......
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