Commit 71e689cc authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Scala integration should now be possible. Added test folder. Updated README.md.

parent c5d5ae16
# CP2K NoMaD Parser
This is the parser for [CP2K](https://www.cp2k.org/).
It is part of the [NOMAD Laboratory](http://nomad-lab.eu).
# QuickStart
- Clone repository
#Installation
```shell
## Within NOMAD
When used within the NOMAD Laboratory, this parser will be available as a
submodule of the nomad-lab-base repository. You can download the base repository
with the command:
```sh
git clone --recursive git@gitlab.mpcdf.mpg.de:nomad-lab/nomad-lab-base.git
```
And the installation will be done according to the instruction found in
https://gitlab.mpcdf.mpg.de/nomad-lab/nomad-lab-base/wikis/how-to-write-a-parser#shell-commands
## Standalone Installation
The parser is also available as a standalone package within the repository:
```sh
git clone git@gitlab.mpcdf.mpg.de:nomad-lab/parser-cp2k.git
```
```
- Run setup by running the setup.py script. For local, user specific install
without sudo permissions use (omit --user for a system-wide install):
If used in this standalone mode you can use the installation script
parser-cp2k/parser/parser-cp2k/setup.py with the folllowing command
```shell
```sh
python setup.py install --user
```
# Structure
Currently the python package is divided the following subpackages:
- utils: Generic utility classes and base classes
- parsing: The classes that actually define the parser functionality.
```
After the local install the parser will be available to python import under the name
'cp2kparser'.
# Usage
## Within NOMAD
The scala layer can access the parser throught the scalainterface.py file.
## Standalone
The parser can be used in a python only standalone mode with a separate
'nomadtoolkit' package. In this local mode the parser can be like this:
```python
from nomadtoolkit import Analyzer
from cp2kparser import CP2KParser
# Initialize the contents and the parser you want to use.
paths = "/home/lauri/Dropbox/nomad-dev/parser-cp2k/parser/parser-cp2k/cp2kparser/tests/cp2k_2.6.2/functionals/lda"
parser = CP2KParser(contents=paths)
# Initialize the analyzer. The analyzer will initialize the parser with a local
# backend so that the results will be available as a python dictionary.
analyzer = Analyzer(parser)
results = analyzer.parse()
cell = results["simulation_cell"]
n_atoms = results["number_of_atoms"]
atom_position = results["atom_position"]
atom_label = results["atom_label"]
print cell.value
print n_atoms.value
print atom_position.value
print atom_label.value
```
This standalone python-only mode is primarily for people who want to easily
access the parser without the need to setup the whole "NOMAD Stack". It is also
used when running unit tests. The nomadtoolkit package is currently used by the
developer only and is thus not available through gitlab.
# Tools and Methods
......
"""
This is the access point to the parser for the scala layer in the nomad project.
"""
import setup_paths
import os
from cp2kparser import CP2KParser
from cp2kparser.parsing.versions.cp2k262.outputparser import CP2KOutputParser
from nomadcore.local_meta_info import loadJsonFile, InfoKindEl
from nomadcore.simple_parser import mainFunction
# This is what should be called by the scala layer to run the parser. Currently
# This is what gets run when the scala layer calls for this parser. Currently
# only the outputparser is used because the scala layer doesn't support
# auxiliary files. Also the version identification is skipped and the structure
# used in CP2K 2.6.2 is assumed.
......@@ -19,7 +20,7 @@ if __name__ == "__main__":
outputparser = CP2KOutputParser(None, None)
# Setup the metainfos
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../../../nomad-meta-info/meta_info/nomad_meta_info/{}".format(cp2kparser.get_metainfo_filename())))
metaInfoPath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../../../nomad-meta-info/meta_info/nomad_meta_info/cp2k.nomadmetainfo.json"))
metaInfoEnv, warnings = loadJsonFile(filePath=metaInfoPath, dependencyLoader=None, extraArgsHandling=InfoKindEl.ADD_EXTRA_ARGS, uri=None)
# Parser info
......
"""
Setups the python-common lirary in the PYTHONPATH system variable.
"""
import sys
import os
import os.path
baseDir = os.path.dirname(os.path.abspath(__file__))
commonDir = os.path.normpath(os.path.join(baseDir, "../../../../../python-common/common/python"))
parserDir = os.path.normpath(os.path.join(baseDir, "../../parser-cp2k"))
# Using sys.path.insert(1, ...) instead of sys.path.insert(0, ...) based on
# this discusssion:
# http://stackoverflow.com/questions/10095037/why-use-sys-path-appendpath-instead-of-sys-path-insert1-path
if not commonDir in sys.path:
sys.path.insert(1, commonDir)
sys.path.insert(1, parserDir)
......@@ -372,6 +372,14 @@ class FileParser(object):
"""
return self.root_matcher.allMetaNames()
def startedParsing(self, fInName, parser):
"""Function is called when the parsing starts.
Get compiled parser.
Later one can compile a parser for parsing an external file.
"""
self.parser = parser
#===============================================================================
class ParserContext(object):
......
from setuptools import setup, find_packages
"""
This is a setup script for installing the parser locally on python path with
all the required dependencies. Used mainly for local testing.
"""
from setuptools import setup
#===============================================================================
def main():
# Start package setup
setup(
name="cp2karser",
name="cp2kparser",
version="0.1",
include_package_data=True,
package_data={
......@@ -19,7 +23,6 @@ def main():
install_requires=[
'pint',
'numpy',
'ase'
],
zip_safe=False
)
......
This diff is collapsed.
This diff is collapsed.
&GLOBAL
PROJECT Si_bulk8
RUN_TYPE ENERGY_FORCE
PRINT_LEVEL MEDIUM
&END GLOBAL
&FORCE_EVAL
METHOD Quickstep
&SUBSYS
&KIND Si
ELEMENT Si
BASIS_SET DZVP-GTH-PADE
POTENTIAL GTH-PADE-q4
&END KIND
&CELL
A 5.430697500 0.000000000 0.000000000
B 0.000000000 5.430697500 0.000000000
C 0.000000000 0.000000000 5.430697500
&END CELL
&COORD
Si 0.000000000 0.000000000 0.000000000
Si 0.000000000 2.715348700 2.715348700
Si 2.715348700 2.715348700 0.000000000
Si 2.715348700 0.000000000 2.715348700
Si 4.073023100 1.357674400 4.073023100
Si 1.357674400 1.357674400 1.357674400
Si 1.357674400 4.073023100 4.073023100
Si 4.073023100 4.073023100 1.357674400
&END COORD
&END SUBSYS
&DFT
BASIS_SET_FILE_NAME BASIS_SET
POTENTIAL_FILE_NAME GTH_POTENTIALS
&QS
EPS_DEFAULT 1.0E-10
&END QS
&MGRID
NGRIDS 4
CUTOFF 300
REL_CUTOFF 60
&END MGRID
&XC
&XC_FUNCTIONAL PADE
&END XC_FUNCTIONAL
&END XC
&SCF
SCF_GUESS ATOMIC
EPS_SCF 1.0E-7
MAX_SCF 300
&DIAGONALIZATION ON
ALGORITHM STANDARD
&END DIAGONALIZATION
&MIXING T
METHOD BROYDEN_MIXING
ALPHA 0.4
NBROYDEN 8
&END MIXING
&END SCF
&END DFT
&PRINT
&FORCES ON
&END FORCES
&END PRINT
&END FORCE_EVAL
This diff is collapsed.
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