adding scala wrapper

currently checks only for netcdf files, should do better...
parent 8ffad15c
package eu.nomad_lab.parsers
import eu.{ nomad_lab => lab }
import eu.nomad_lab.DefaultPythonInterpreter
import org.{ json4s => jn }
import scala.collection.breakOut
import java.nio.charset.StandardCharsets
object AtkParser extends SimpleExternalParserGenerator(
name = "AtkParser",
parserInfo = jn.JObject(
("name" -> jn.JString("AtkParser")) ::
("parserId" -> jn.JString("AtkParser" + lab.AtkVersionInfo.version)) ::
("versionInfo" -> jn.JObject(
("nomadCoreVersion" -> jn.JObject(lab.NomadCoreVersionInfo.toMap.map {
case (k, v) => k -> jn.JString(v.toString)
}(breakOut): List[(String, jn.JString)])) ::
(lab.AtkVersionInfo.toMap.map {
case (key, value) =>
(key -> jn.JString(value.toString))
}(breakOut): List[(String, jn.JString)])
)) :: Nil
),
mainFileTypes = Seq("application/x-netcdf"),
cmd = Seq(DefaultPythonInterpreter.pythonExe(), "${envDir}/parsers/atk/parser/parser-atk/parser_atk.py",
"${mainFilePath}"),
mainFileRe = "".r,
resList = Seq(
"parser-atk/atkio2.py",
"parser-atk/atkio.py",
"parser-atk/configurations.py",
"parser-atk/libxc_names.py",
"parser-atk/parser_atk.py",
"parser-atk/parser_calculator.py",
"parser-atk/parser_configurations2.py",
"parser-atk/parser_configurations.py",
"parser-atk/periodic_table.py",
"parser-atk/physical_quantities.py",
"parser-atk/setup_paths.py",
"nomad_meta_info/public.nomadmetainfo.json",
"nomad_meta_info/common.nomadmetainfo.json",
"nomad_meta_info/meta_types.nomadmetainfo.json",
"nomad_meta_info/atk.nomadmetainfo.json"
) ++ DefaultPythonInterpreter.commonFiles(),
dirMap = Map(
"parser-atk" -> "parsers/atk/parser/parser-atk",
"nomad_meta_info" -> "nomad-meta-info/meta_info/nomad_meta_info"
) ++ DefaultPythonInterpreter.commonDirMapping(),
metaInfoEnv = Some(lab.meta.KnownMetaInfoEnvs.atk)
) {
override def isMainFile(filePath: String, bytePrefix: Array[Byte], stringPrefix: Option[String]): Option[ParserMatch] = {
// TO DO: be more specific: open and look for something special, not all netcdf files are Atk files...
if (bytePrefix.startsWith("CDF".getBytes(StandardCharsets.US_ASCII)) &&
bytePrefix.size > 3 && (bytePrefix(3) == 1 || bytePrefix(3) == 2))
Some(ParserMatch(mainFileMatchPriority, mainFileMatchWeak))
else
None
}
}
package eu.nomad_lab.parsers
import org.specs2.mutable.Specification
object AtkParserSpec extends Specification {
"AtkParserTest" >> {
"test Si2 with json-events" >> {
ParserRun.parse(AtkParser, "parsers/atk/test/examples/Si2.nc", "json-events") must_== ParseResult.ParseSuccess
}
"test Si2 with json" >> {
ParserRun.parse(AtkParser, "parsers/atk/test/examples/Si2.nc", "json") must_== ParseResult.ParseSuccess
}
"test Water with json-events" >> {
ParserRun.parse(AtkParser, "parsers/atk/test/examples/Water.nc", "json-events") must_== ParseResult.ParseSuccess
}
"test Water with json" >> {
ParserRun.parse(AtkParser, "parsers/atk/test/examples/Water.nc", "json") must_== ParseResult.ParseSuccess
}
}
}
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