Commit 00698fbe authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Enabled parsing of cell information from input file.

parent bc9a0527
......@@ -9,7 +9,6 @@ metainfo_section_prefix = "x_cp2k_section_input_"
metainfo_data_prefix = "x_cp2k_input_"
#===============================================================================
class CP2KInput(object):
"""The contents of a CP2K simulation including default values and default
units from the version-specific xml file.
......@@ -154,7 +153,6 @@ class CP2KInput(object):
return parameter.lone_value
#===============================================================================
class Section(object):
"""An input section in a CP2K calculation.
"""
......@@ -216,7 +214,6 @@ class Section(object):
return value.upper()
#===============================================================================
class InputObject(object):
"""Base class for all kind of data elements in the CP2K input.
"""
......@@ -231,7 +228,6 @@ class InputObject(object):
self.default_value = None
#===============================================================================
class Keyword(InputObject):
"""Information about a keyword in a CP2K calculation.
"""
......@@ -265,13 +261,14 @@ class Keyword(InputObject):
"""
# Decode the unit and the value if not done before
proper_value = None
if self.default_unit:
if not self.value_no_unit:
if self.default_unit is not None:
if self.value_no_unit is None:
self.decode_cp2k_unit_and_value()
if self.value_no_unit is not None:
proper_value = self.value_no_unit
else:
proper_value = self.value
# if allow_default:
if proper_value is None:
proper_value = self.default_value
......@@ -331,8 +328,8 @@ class Keyword(InputObject):
"""If the units of this value can be changed, return a value and the
unit separately.
"""
if self.default_unit:
if not self.value_no_unit:
if self.default_unit is not None:
if self.value_no_unit is None:
self.decode_cp2k_unit_and_value()
return self.value_no_unit
else:
......@@ -352,22 +349,22 @@ class Keyword(InputObject):
def decode_cp2k_unit_and_value(self):
"""Given a CP2K unit name, decode it as Pint unit definition.
"""
splitted = self.value.split(None, 1)
unit_definition = splitted[0]
if unit_definition.startswith('[') and unit_definition.endswith(']'):
unit_definition = unit_definition[1:-1]
self.unit = CP2KInput.decode_cp2k_unit(self.default_unit)
self.value_no_unit = splitted[1]
elif self.default_unit:
logger.debug("No special unit definition found, returning default unit.")
self.unit = CP2KInput.decode_cp2k_unit(self.default_unit)
self.value_no_unit = self.value
else:
logger.debug("The value has no unit, returning bare value.")
self.value_no_unit = self.value
if self.value is not None:
splitted = self.value.split(None, 1)
unit_definition = splitted[0]
if unit_definition.startswith('[') and unit_definition.endswith(']'):
unit_definition = unit_definition[1:-1]
self.unit = CP2KInput.decode_cp2k_unit(unit_definition)
self.value_no_unit = splitted[1]
elif self.default_unit:
logger.debug("No special unit definition found, returning default unit.")
self.unit = CP2KInput.decode_cp2k_unit(self.default_unit)
self.value_no_unit = self.value
else:
logger.debug("The value has no unit, returning bare value.")
self.value_no_unit = self.value
#===============================================================================
class SectionParameters(InputObject):
"""Section parameters in a CP2K calculation.
......@@ -382,7 +379,6 @@ class SectionParameters(InputObject):
self.lone_keyword_value = lone_keyword_value
#===============================================================================
class DefaultKeyword(InputObject):
"""Default keyword in the CP2K input.
"""
......
......@@ -380,18 +380,19 @@ class CP2KCommonParser(CommonParser):
# correspondent, and push directly to the superBackend to avoid caching
try:
sic_cp2k = section.get_latest_value("self_interaction_correction_method")
sic_map = {
"NO": "",
"AD SIC": "SIC_AD",
"Explicit Orbital SIC": "SIC_EXPLICIT_ORBITALS",
"SPZ/MAURI SIC": "SIC_MAURI_SPZ",
"US/MAURI SIC": "SIC_MAURI_US",
}
sic_nomad = sic_map.get(sic_cp2k)
if sic_nomad is not None:
backend.superBackend.addValue('self_interaction_correction_method', sic_nomad)
else:
logger.warning("Unknown self-interaction correction method used.")
if sic_cp2k is not None:
sic_map = {
"NO": "",
"AD SIC": "SIC_AD",
"Explicit Orbital SIC": "SIC_EXPLICIT_ORBITALS",
"SPZ/MAURI SIC": "SIC_MAURI_SPZ",
"US/MAURI SIC": "SIC_MAURI_US",
}
sic_nomad = sic_map.get(sic_cp2k)
if sic_nomad is not None:
backend.superBackend.addValue('self_interaction_correction_method', sic_nomad)
else:
logger.warning("Unknown self-interaction correction method used.")
except:
pass
......@@ -515,7 +516,6 @@ class CP2KCommonParser(CommonParser):
"""
self.section_system_index = gIndex
self.cache_service.addValue("number_of_atoms")
# self.cache_service.push_array_values("simulation_cell", unit="angstrom")
self.cache_service.addArrayValues("configuration_periodic_dimensions")
self.cache_service.addArrayValues("atom_labels")
......
......@@ -8,6 +8,9 @@ import pickle
import numpy as np
from nomadcore.baseclasses import AbstractBaseParser
from cp2kparser.generic.inputparsing import metainfo_data_prefix, metainfo_section_prefix
from pint import UnitRegistry
import ase
ureg = UnitRegistry()
logger = logging.getLogger("nomad")
......@@ -66,7 +69,6 @@ class CP2KInputParser(AbstractBaseParser):
self.cache_service.add("vel_add_last")
self.cache_service.add("each_geo_opt")
self.cache_service.add("traj_add_last")
# self.cache_service.add("electronic_structure_method")
def parse(self, filepath):
......@@ -80,6 +82,91 @@ class CP2KInputParser(AbstractBaseParser):
# Parse everything in the input to cp2k specific metadata
self.fill_metadata()
# If the print level is low, parse the system geometry from the input
# file. If keywords that manipulate the system are enabled, the
# geometry is not parsed because the manipulations can be hard to
# reproduce.
print_level = self.input_tree.get_keyword("GLOBAL/PRINT_LEVEL")
multiple_unit_cell = self.input_tree.get_keyword("FORCE_EVAL/SUBSYS/MULTIPLE_UNIT_CELL")
top_multiple_unit_cell = self.input_tree.get_keyword("FORCE_EVAL/SUBSYS/TOPOLOGY/MULTIPLE_UNIT_CELL")
centering = self.input_tree.get_section("FORCE_EVAL/SUBSYS/TOPOLOGY/CENTER_COORDINATES")
if multiple_unit_cell is None:
multiple_unit_cell = np.array([1, 1, 1])
if print_level == "LOW" \
and np.array_equal(multiple_unit_cell, [1, 1, 1]) \
and np.array_equal(top_multiple_unit_cell, [1, 1, 1]) \
and not centering.accessed:
cell_section = self.input_tree.get_section("FORCE_EVAL/SUBSYS/CELL")
a_obj = cell_section.get_keyword_object("A")
b_obj = cell_section.get_keyword_object("B")
c_obj = cell_section.get_keyword_object("C")
a_val = a_obj.get_value()
b_val = b_obj.get_value()
c_val = c_obj.get_value()
abc_obj = cell_section.get_keyword_object("ABC")
angles_obj = cell_section.get_keyword_object("ALPHA_BETA_GAMMA")
abc_val = abc_obj.get_value()
angles_val = angles_obj.get_value()
# Cell given as three vectors
if a_val is not None and b_val is not None and c_val is not None:
a_unit = a_obj.get_unit()
b_unit = b_obj.get_unit()
c_unit = c_obj.get_unit()
a = (a_val * ureg(a_unit)).to("angstrom").magnitude
b = (b_val * ureg(b_unit)).to("angstrom").magnitude
c = (c_val * ureg(c_unit)).to("angstrom").magnitude
cell = np.stack((a, b, c), axis=0)
self.cache_service["simulation_cell"] = cell
self.cache_service["lattice_vectors"] = cell
# Cell given as lengths and angles
elif abc_val is not None and angles_val is not None:
abc_unit = abc_obj.get_unit()
angles_unit = angles_obj.get_unit()
abc = (abc_val * ureg(abc_unit)).to("angstrom").magnitude
angles = (angles_val * ureg(angles_unit)).to("degree").magnitude
parameters = np.hstack((abc, angles))
cell = ase.geometry.cellpar_to_cell(parameters)
self.cache_service["simulation_cell"] = cell
self.cache_service["lattice_vectors"] = cell
coord = self.input_tree.get_section("FORCE_EVAL/SUBSYS/COORD")
scaled = coord.get_keyword("SCALED")
coords = coord.default_keyword.value
print(coords)
coord_unit = coord.get_keyword("UNIT")
if len(coords) != 0:
lines = coords.split("\n")
pos = []
labels = []
for line in lines:
if len(line) != 0:
parts = line.split()
i_lab = parts[0]
i_x = float(parts[1])
i_y = float(parts[2])
i_z = float(parts[3])
labels.append(i_lab)
pos.append([i_x, i_y, i_z])
pos = np.array(pos)
coord_unit = self.get_pint_unit_string(coord_unit)
pos = (pos * ureg(coord_unit)).to("angstrom").magnitude
labels = np.array(labels)
if scaled == "F" or scaled == "FALSE":
self.cache_service["atom_positions"] = pos
self.cache_service["atom_labels"] = labels
# self.cache_service["simulation_cell"] = cell
# self.cache_service["lattice_vectors"] = cell
# coordinates = self.input_tree.get_section("FORCE_EVAL/SUBSYS/COORD")
# print(coordinates.get_section_parameter())
# self.cache_service["atom_positions"] = coordinates
# self.cache_service["atom_labels"] = labels
# Parse the used XC_functionals and their parameters
xc = self.input_tree.get_section("FORCE_EVAL/DFT/XC/XC_FUNCTIONAL")
if xc is not None:
......@@ -383,11 +470,13 @@ class CP2KInputParser(AbstractBaseParser):
# Contents (keywords, default keywords)
else:
split = line.split(None, 1)
print(split)
if len(split) <= 1:
keyword_value = ""
else:
keyword_value = split[1]
keyword_name = split[0].upper()
# print(keyword_value)
self.input_tree.set_keyword(path + "/" + keyword_name, keyword_value)
def fill_metadata(self):
......
This diff is collapsed.
This diff is collapsed.
&GLOBAL
PROJECT Si_bulk8
RUN_TYPE ENERGY_FORCE
PRINT_LEVEL LOW
&END GLOBAL
&FORCE_EVAL
METHOD Quickstep
&SUBSYS
&KIND Si
ELEMENT Si
BASIS_SET DZVP-GTH-PADE
POTENTIAL GTH-PADE-q4
&END KIND
&CELL
ABC 5.430697500 5.430697500 5.430697500
ALPHA_BETA_GAMMA [rad] 1.5707963268 1.5707963268 1.5707963268
&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.
This diff is collapsed.
This diff is collapsed.
&GLOBAL
PROJECT Si_bulk8
RUN_TYPE ENERGY_FORCE
PRINT_LEVEL LOW
&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
DBCSR| Multiplication driver SMM
DBCSR| Multiplication stack size 1000
DBCSR| Multiplication stack buffers 0
DBCSR| Multiplication size stacks 3
DBCSR| Use subcommunicators T
DBCSR| Use MPI combined types F
DBCSR| Use MPI memory allocation T
DBCSR| Use Communication thread T
DBCSR| Communication thread load 100
**** **** ****** ** PROGRAM STARTED AT 2014-01-27 00:15:40.989
***** ** *** *** ** PROGRAM STARTED ON spring.kcl.ac.uk
** **** ****** PROGRAM STARTED BY tong
***** ** ** ** ** PROGRAM PROCESS ID 22581
**** ** ******* ** PROGRAM STARTED IN /home/tong/tutorials/static_calculati
on
CP2K| version string: CP2K version 2.5 (Development Version)
CP2K| source code revision number: git:071de34
CP2K| is freely available from http://www.cp2k.org/
CP2K| Program compiled at Sat Oct 26 15:17:35 BST 2013
CP2K| Program compiled on spring.kcl.ac.uk
CP2K| Program compiled for Linux-spring-gfortran
CP2K| Input file name Si_bulk8.inp
GLOBAL| Force Environment number 1
GLOBAL| Basis set file name BASIS_SET
GLOBAL| Geminal file name BASIS_GEMINAL
GLOBAL| Potential file name GTH_POTENTIALS
GLOBAL| MM Potential file name MM_POTENTIAL
GLOBAL| Coordinate file name __STD_INPUT__
GLOBAL| Method name CP2K
GLOBAL| Project name Si_bulk8
GLOBAL| Preferred FFT library FFTW3
GLOBAL| Run type ENERGY_FORCE
GLOBAL| All-to-all communication in single precision F
GLOBAL| FFTs using library dependent lengths F
GLOBAL| Global print level LOW
GLOBAL| Total number of message passing processes 2
GLOBAL| Number of threads for this process 1
GLOBAL| This output is from process 0
MEMORY| system memory details [Kb]
MEMORY| rank 0 min max average
MEMORY| MemTotal 65362240 65362240 65362240 65362240
MEMORY| MemFree 59646576 59646576 59646576 59646576
MEMORY| Buffers 455920 455920 455920 455920
MEMORY| Cached 4618696 4618696 4618696 4618696
MEMORY| Slab 408436 408436 408436 408436
MEMORY| SReclaimable 0 0 0 0
MEMORY| MemLikelyFree 64721192 64721192 64721192 64721192
GENERATE| Preliminary Number of Bonds generated: 0
GENERATE| Achieved consistency in connectivity generation.
*******************************************************************************
*******************************************************************************
** **
** ##### ## ## **
** ## ## ## ## ## **
** ## ## ## ###### **
** ## ## ## ## ## ##### ## ## #### ## ##### ##### **
** ## ## ## ## ## ## ## ## ## ## ## ## ## ## **
** ## ## ## ## ## ## ## #### ### ## ###### ###### **
** ## ### ## ## ## ## ## ## ## ## ## ## **
** ####### ##### ## ##### ## ## #### ## ##### ## **
** ## ## **
** **
** ... make the atoms dance **
** **
** Copyright (C) by CP2K Developers Group (2000 - 2013) **
** **
*******************************************************************************
SCF PARAMETERS Density guess: ATOMIC
--------------------------------------------------------
max_scf: 300
max_scf_history: 0
max_diis: 4
--------------------------------------------------------
eps_scf: 1.00E-07
eps_scf_history: 0.00E+00
eps_diis: 1.00E-01
eps_eigval: 1.00E-05
--------------------------------------------------------
level_shift [a.u.]: 0.00
--------------------------------------------------------
Mixing method: BROYDEN_MIXING
charge density mixing in g-space
--------------------------------------------------------
No outer SCF
Number of electrons: 32
Number of occupied orbitals: 16
Number of molecular orbitals: 16
Number of orbital functions: 104
Number of independent orbital functions: 104
Extrapolation method: initial_guess
SCF WAVEFUNCTION OPTIMIZATION
Step Update method Time Convergence Total energy Change
------------------------------------------------------------------------------
1 NoMix/Diag. 0.40E+00 0.6 0.75558724 -32.2320848878 -3.22E+01
2 Broy./Diag. 0.40E+00 1.1 0.05667976 -31.1418135481 1.09E+00
3 Broy./Diag. 0.40E+00 1.1 0.09691469 -31.1974003416 -5.56E-02
4 Broy./Diag. 0.40E+00 1.1 0.00245608 -31.3378474040 -1.40E-01
5 Broy./Diag. 0.40E+00 1.1 0.00235460 -31.3009654398 3.69E-02
6 Broy./Diag. 0.40E+00 1.1 0.00007565 -31.2972158934 3.75E-03
7 Broy./Diag. 0.40E+00 1.1 0.00009004 -31.2977293749 -5.13E-04
8 Broy./Diag. 0.40E+00 1.1 0.00000186 -31.2978454163 -1.16E-04
9 Broy./Diag. 0.40E+00 1.1 0.00000252 -31.2978835492 -3.81E-05
10 Broy./Diag. 0.40E+00 1.1 5.6405E-09 -31.2978852054 -1.66E-06
*** SCF run converged in 10 steps ***
Electronic density on regular grids: -31.9999999889 0.0000000111
Core density on regular grids: 31.9999999939 -0.0000000061
Total charge density on r-space grids: 0.0000000051
Total charge density g-space grids: 0.0000000051
Overlap energy of the core charge distribution: 0.00000000005320
Self energy of the core charge distribution: -82.06393942512820
Core Hamiltonian energy: 18.06858429706010
Hartree energy: 42.41172824581682
Exchange-correlation energy: -9.71425832315952
Total energy: -31.29788520535761
ENERGY| Total FORCE_EVAL ( QS ) energy (a.u.): -31.297885372811002
ATOMIC FORCES in [a.u.]
# Atom Kind Element X Y Z
1 1 Si 0.00000000 0.00000000 0.00000000
2 1 Si 0.00000000 0.00000001 0.00000001
3 1 Si 0.00000001 0.00000001 0.00000000
4 1 Si 0.00000001 0.00000000 0.00000001
5 1 Si -0.00000001 -0.00000001 -0.00000001
6 1 Si -0.00000001 -0.00000001 -0.00000001
7 1 Si -0.00000001 -0.00000001 -0.00000001
8 1 Si -0.00000001 -0.00000001 -0.00000001
SUM OF ATOMIC FORCES -0.00000000 -0.00000000 -0.00000000 0.00000000
-------------------------------------------------------------------------------
- -
- DBCSR STATISTICS -
- -
-------------------------------------------------------------------------------
COUNTER CPU GPU GPU%
number of processed stacks 22 0 0.0
mutmuls inhomo. stacks 0 0 0.0
matmuls 13 x 13 x 16 396 0 0.0
matmuls total 396 0 0.0
flops total 2141568 0 0.0
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
- -
- MESSAGE PASSING PERFORMANCE -
- -
-------------------------------------------------------------------------------
ROUTINE CALLS TOT TIME [s] AVE VOLUME [Bytes] PERFORMANCE [MB/s]
MP_Group 4 0.000
MP_Bcast 38 0.003 5130582. 64987.37
MP_Allreduce 183 0.002 391. 35.77
MP_Sync 4 0.000
MP_Alltoall 120 0.126 3441585. 3277.70
MP_ISendRecv 90 0.000 285531. 0.00
MP_Wait 90 0.052
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
- -
- R E F E R E N C E S -
- -
-------------------------------------------------------------------------------
CP2K version 2.5 (Development Version), the CP2K developers group (2013).
CP2K is freely available from http://www.cp2k.org/ .
Krack, M.
THEORETICAL CHEMISTRY ACCOUNTS, 114 (1-3), 145-152 (2005).
Pseudopotentials for H to Kr optimized for gradient-corrected
exchange-correlation functionals.
http://dx.doi.org/10.1007/s00214-005-0655-y