Commit 9fb49b25 authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Fixed issue in reading xyz-files with ASE, added support for reading REFTRAJ files.

parent 7a272fca
......@@ -47,6 +47,7 @@ class CP2KParser(ParserInterface):
version_id = result_version.group(1).replace('.', '')
if result_run_type:
run_type = result_run_type.group(1)
if version_id is None:
msg = "Could not find a version specification from the given main file."
logger.exception(msg)
......
......@@ -218,6 +218,9 @@ class CP2KGeoOptParser(MainHierarchicalParser):
# Push the trajectory
n_steps = len(steps) + 1
last_step = n_steps - 1
# First push the original system geometry
# print(self.cache_service["atom_positions"])
for i_step in range(n_steps):
singleId = backend.openSection("section_single_configuration_calculation")
systemId = backend.openSection("section_system")
......@@ -227,7 +230,13 @@ class CP2KGeoOptParser(MainHierarchicalParser):
try:
pos = next(self.traj_iterator)
except StopIteration:
logger.error("Could not get the next geometries from an external file. It seems that the number of optimization steps in the CP2K outpufile doesn't match the number of steps found in the external trajectory file.")
logger.error(
"Could not get next geometry from an external"
" file. It seems that the number of optimization "
"steps in the CP2K output file doesn't match the "
"number of steps found in the external trajectory "
"file."
)
else:
backend.addArrayValues("atom_positions", pos, unit="angstrom")
backend.closeSection("section_system", systemId)
......
......@@ -3,6 +3,7 @@ standard_library.install_aliases()
from builtins import object
import os
import re
from io import StringIO
import logging
import pickle
import numpy as np
......@@ -11,6 +12,7 @@ import nomadcore.configurationreading
from cp2kparser.generic.inputparsing import metainfo_data_prefix, metainfo_section_prefix
from pint import UnitRegistry
import ase
ureg = UnitRegistry()
logger = logging.getLogger("nomad")
......@@ -168,9 +170,20 @@ class CP2KInputParser(AbstractBaseParser):
}
coord_extension = extension_map.get(coord_format)
if coord_extension is not None:
# We first remove the comment line from the XYZ file,
# because ASE cannot properly handle comments that have ASE
# specific data that is malformed.
abs_filename = self.file_service.get_absolute_path_to_file(coord_filename)
stringio = StringIO()
with open(abs_filename, "r") as fin:
for i_line, line in enumerate(fin):
if i_line == 1:
stringio.write("\n")
else:
stringio.write(line)
try:
atoms = ase.io.read(abs_filename, format=coord_extension)
atoms = ase.io.read(stringio, format="xyz")
final_pos = atoms.get_positions()
final_lab = atoms.get_chemical_symbols()
except StopIteration:
......
......@@ -35,6 +35,7 @@ class CP2KMDParser(MainHierarchicalParser):
self.cell_freq = None
self.md_quicksteps = []
self.ensemble = None
self.cp2k_ensemble = None
#=======================================================================
# Globally cached values
......@@ -150,18 +151,21 @@ class CP2KMDParser(MainHierarchicalParser):
def onClose_x_cp2k_section_md_settings(self, backend, gIndex, section):
# Ensemble
sampling = section.get_latest_value("x_cp2k_md_ensemble_type")
if sampling is not None:
cp2k_ensemble = section.get_latest_value("x_cp2k_md_ensemble_type")
self.cp2k_ensemble = cp2k_ensemble
if cp2k_ensemble is not None:
sampling_map = {
"NVE": "NVE",
"NVT": "NVT",
"NPT_F": "NPT",
"NPT_I": "NPT",
}
sampling = sampling_map.get(sampling)
sampling = sampling_map.get(cp2k_ensemble)
if sampling is not None:
self.ensemble = sampling
backend.addValue("ensemble_type", sampling)
else:
logger.error("Unknown ensemble type {}.".format(cp2k_ensemble))
# Sampling type
backend.addValue("sampling_method", "molecular_dynamics")
......@@ -173,7 +177,7 @@ class CP2KMDParser(MainHierarchicalParser):
self.velo_freq = section.get_latest_value("x_cp2k_md_velocities_print_frequency")
self.cell_freq = section.get_latest_value("x_cp2k_md_simulation_cell_print_frequency")
# Step number
# Number of steps
self.n_steps = section.get_latest_value("x_cp2k_md_number_of_time_steps")
# Files
......@@ -280,15 +284,25 @@ class CP2KMDParser(MainHierarchicalParser):
# to know from which frame number we should start reading the
# configurations, because the print settings in the previous runs may
# have been different from now, and the step numbers are hard to align.
# In this case we just parse what is found in this output file
# In this case we just parse what is found in this output file. The
# REFTRAJ calculations use a different indexing that starts from 2
# instead of one.
start_step_number = md_steps[1]["x_cp2k_md_step_number"][0]
if start_step_number != 1:
if (self.cp2k_ensemble.upper() == "REFTRAJ" and start_step_number != 2) or \
(self.cp2k_ensemble.upper() != "REFTRAJ" and start_step_number != 1):
self.traj_iterator = None
self.cell_iterator = None
self.vel_iterator = None
self.energy_iterator = None
for i_step in range(self.n_steps + 1):
# The reftraj mode has axactly the requested number of steps, but other
# modes have one more.
if self.cp2k_ensemble.upper() == "REFTRAJ":
n_steps = self.n_steps
else:
n_steps = self.n_steps + 1
for i_step in range(n_steps):
sectionGID = backend.openSection("section_single_configuration_calculation")
systemGID = backend.openSection("section_system")
......
# Version information for this restart file
# current date 2017-05-29 17:39:10.619
# current working dir /wrk/jagermar/DONOTREMOVE/critcat/cu/cp2k/h_slab/fdsmear_pbe_dzvp-molopt-sr-gth/Cu_typefcc_pristine_Hn1_ver3_MJ20170526/ref
# Program compiled at Thu Nov 3 13:22:03 EET 2016
# Program compiled on taito-login3.csc.fi
# Program compiled for taito_gcc_xsmm
# Source code revision number svn:17462
&GLOBAL
PREFERRED_FFT_LIBRARY FFTSG
EXTENDED_FFT_LENGTHS T
PRINT_LEVEL LOW
PROJECT_NAME gopt
RUN_TYPE GEO_OPT
&END GLOBAL
&MOTION
&GEO_OPT
TYPE MINIMIZATION
OPTIMIZER BFGS
MAX_ITER 240
STEP_START_VAL 10
&END GEO_OPT
&CELL_OPT
TYPE DIRECT_CELL_OPT
KEEP_ANGLES T
&END CELL_OPT
&MD
ENSEMBLE REFTRAJ
STEPS 100
&REFTRAJ
TRAJ_FILE_NAME slab.xyz
FIRST_SNAPSHOT 1
EVAL_ENERGY_FORCES T
&END REFTRAJ
&END MD
&END MOTION
&FORCE_EVAL
METHOD QS
&DFT
BASIS_SET_FILE_NAME ./BASIS_SET
POTENTIAL_FILE_NAME ./POTENTIAL
UKS T
&SCF
MAX_ITER_LUMO 10000
EPS_LUMO 9.9999999999999995E-07
MAX_SCF 2000
EPS_SCF 9.9999999999999995E-08
CHOLESKY INVERSE_DBCSR
SCF_GUESS ATOMIC
ADDED_MOS 500
&DIAGONALIZATION T
ALGORITHM STANDARD
&END DIAGONALIZATION
&SMEAR T
METHOD FERMI_DIRAC
ELECTRONIC_TEMPERATURE 2.5000000000000000E+02
&END SMEAR
&MIXING T
METHOD BROYDEN_MIXING
ALPHA 1.0000000000000001E-01
BETA 1.5000000000000000E+00
NBUFFER 8
&END MIXING
&PRINT
&RESTART ON
ADD_LAST NUMERIC
COMMON_ITERATION_LEVELS 1
BACKUP_COPIES 0
&EACH
MD 1
&END EACH
&END RESTART
&RESTART_HISTORY OFF
&END RESTART_HISTORY
&END PRINT
&END SCF
&QS
EPS_DEFAULT 9.9999999999999998E-13
MAP_CONSISTENT T
EXTRAPOLATION ASPC
EXTRAPOLATION_ORDER 4
METHOD GPW
&END QS
&MGRID
NGRIDS 5
CUTOFF 5.5000000000000000E+02
REL_CUTOFF 6.0000000000000000E+01
&END MGRID
&XC
DENSITY_CUTOFF 1.0000000000000000E-10
GRADIENT_CUTOFF 1.0000000000000000E-10
TAU_CUTOFF 1.0000000000000000E-10
&XC_GRID
XC_SMOOTH_RHO NONE
XC_DERIV SPLINE2
&END XC_GRID
&XC_FUNCTIONAL NO_SHORTCUT
&PBE T
&END PBE
&END XC_FUNCTIONAL
&VDW_POTENTIAL
POTENTIAL_TYPE PAIR_POTENTIAL
&PAIR_POTENTIAL
TYPE DFTD3(BJ)
PARAMETER_FILE_NAME ./dftd3.dat
REFERENCE_FUNCTIONAL PBE
CALCULATE_C9_TERM T
REFERENCE_C9_TERM T
LONG_RANGE_CORRECTION T
&END PAIR_POTENTIAL
&END VDW_POTENTIAL
&END XC
&PRINT
&PDOS SILENT
FILENAME dosfile
LOG_PRINT_KEY T
COMPONENTS F
APPEND T
NLUMO -1
&END PDOS
&LOWDIN ON
FILENAME lowdin
&EACH
MD 1
&END EACH
&END LOWDIN
&END PRINT
&END DFT
&SUBSYS
&CELL
A 1.0210621920300001E+01 0.0000000000000000E+00 0.0000000000000000E+00
B 5.1053109601699997E+00 8.8426579714500004E+00 0.0000000000000000E+00
C 0.0000000000000000E+00 0.0000000000000000E+00 2.2084234471799999E+01
PERIODIC XYZ
MULTIPLE_UNIT_CELL 1 1 1
&END CELL
&COORD
Cu -6.3871241730842820E-01 1.8409029124369907E+00 9.8993381405720324E+00
Cu 1.9297510687263069E+00 1.8332970519842473E+00 9.8995653494722191E+00
Cu 4.4666001697550950E+00 1.8409024300368910E+00 9.8993380691689215E+00
Cu 7.0350593540425637E+00 1.8332978744017399E+00 9.8995653805527084E+00
Cu 6.3878521708616542E-01 4.0541385289095482E+00 9.8993228800211970E+00
Cu 3.1756712246289913E+00 4.0617407710352458E+00 9.8988329597437374E+00
Cu 5.7440967989788412E+00 4.0541373137101511E+00 9.8993228016739341E+00
Cu 8.2809819318742512E+00 4.0617397411245255E+00 9.8988328574889959E+00
Cu 1.9139428452612195E+00 6.2622297374568561E+00 9.8993380463087863E+00
Cu 4.4824066549714274E+00 6.2546237638880919E+00 9.8995655579992903E+00
Cu 7.0192544925479803E+00 6.2622315867769389E+00 9.8993380313065362E+00
Cu 9.5877156447880871E+00 6.2546256357479422E+00 9.8995654906316410E+00
Cu 3.1914397439794464E+00 8.4754650138121992E+00 9.8993227987159607E+00
Cu 5.7283268874110060E+00 8.4830679413795949E+00 9.8988330426618827E+00
Cu 8.2967525949275487E+00 8.4754641039542076E+00 9.8993228159085138E+00
Cu 1.0833635744725784E+01 8.4830693378159054E+00 9.8988330500656527E+00
Cu -6.2301593544263545E-01 3.5959003595735062E-01 1.2185401430280356E+01
Cu 1.9138712132819797E+00 3.6719296184924566E-01 1.2184911666906014E+01
Cu 4.4822971412370709E+00 3.5958861485703075E-01 1.2185401418379909E+01
Cu 7.0191802960149534E+00 3.6719385514883734E-01 1.2184911663281012E+01
Cu 6.2290430844247280E-01 2.5880341947602212E+00 1.2184668909838207E+01
Cu 3.1913681145302353E+00 2.5804282484070162E+00 1.2184896416283024E+01
Cu 5.7282172284216388E+00 2.5880323463610755E+00 1.2184668981516452E+01
Cu 8.2966783936443118E+00 2.5804263800245417E+00 1.2184896438337406E+01
Cu 1.9296397486665935E+00 4.7809172037670500E+00 1.2185401514624932E+01
Cu 4.4665257436694796E+00 4.7885194487835747E+00 1.2184911589240892E+01
Cu 7.0349509359805955E+00 4.7809182389469385E+00 1.2185401616009910E+01
Cu 9.5718360829119220E+00 4.7885206765974386E+00 1.2184911671702158E+01
Cu 3.1755598753809982E+00 7.0093609204370315E+00 1.2184669132069777E+01
Cu 5.7440233741937607E+00 7.0017550498319086E+00 1.2184896337050699E+01
Cu 8.2808735397118216E+00 7.0093600919152967E+00 1.2184669086904883E+01
Cu 1.0849332718461687E+01 7.0017555519124031E+00 1.2184896408123929E+01
&END COORD
&KIND Mo
BASIS_SET DZVP-MOLOPT-SR-GTH
POTENTIAL GTH-PBE-q14
&END KIND
&KIND S
BASIS_SET DZVP-MOLOPT-SR-GTH
POTENTIAL GTH-PBE-q6
&END KIND
&KIND Co
BASIS_SET DZVP-MOLOPT-SR-GTH
POTENTIAL GTH-PBE-q17
&END KIND
&KIND Ni
BASIS_SET DZVP-MOLOPT-SR-GTH
POTENTIAL GTH-PBE-q18
&END KIND
&KIND Cu
BASIS_SET DZVP-MOLOPT-SR-GTH
POTENTIAL GTH-PBE-q11
&POTENTIAL
1 0 10
0.5300000000000000E+00 0
3
0.4313550500000000E+00 3 0.9693805070000000E+01 -0.6470165350000000E+01 0.1935952150000000E+01
0.1150177396000000E+02 -0.4998606960000000E+01
0.3967521270000000E+01
0.5613915500000000E+00 2 0.2545473300000000E+01 -0.7846357300000000E+00
0.9283935200000000E+00
0.2645548500000000E+00 1 -0.1282861406000000E+02
# Potential name: GTH-PBE-Q11 for symbol: CU
# Potential read from the potential filename: ./POTENTIAL
&END POTENTIAL
&END KIND
&KIND H
BASIS_SET DZVP-MOLOPT-GTH
POTENTIAL GTH-PBE-q1
&END KIND
&TOPOLOGY
COORD_FILE_NAME slab.xyz
COORD_FILE_FORMAT XYZ
NUMBER_OF_ATOMS 32
MULTIPLE_UNIT_CELL 1 1 1
&CENTER_COORDINATES T
&END CENTER_COORDINATES
&END TOPOLOGY
&PRINT
&CELL ON
&END CELL
&END PRINT
&END SUBSYS
&PRINT
&FORCES SILENT
FILENAME forces
&EACH
MD 1
&END EACH
&END FORCES
&END PRINT
&END FORCE_EVAL
# Version information for this restart file
# current date 2017-05-29 17:39:10.606
# current working dir /wrk/jagermar/DONOTREMOVE/critcat/cu/cp2k/h_slab/fdsmear_pbe_dzvp-molopt-sr-gth/Cu_typefcc_pristine_Hn1_ver3_MJ20170526/ref
# Program compiled at Thu Nov 3 13:22:03 EET 2016
# Program compiled on taito-login3.csc.fi
# Program compiled for taito_gcc_xsmm
# Source code revision number svn:17462
&GLOBAL
PREFERRED_FFT_LIBRARY FFTSG
EXTENDED_FFT_LENGTHS T
PRINT_LEVEL LOW
PROJECT_NAME gopt
RUN_TYPE GEO_OPT
&END GLOBAL
&MOTION
&GEO_OPT
TYPE MINIMIZATION
OPTIMIZER BFGS
MAX_ITER 240
STEP_START_VAL 10
&END GEO_OPT
&CELL_OPT
TYPE DIRECT_CELL_OPT
KEEP_ANGLES T
&END CELL_OPT
&MD
ENSEMBLE REFTRAJ
STEPS 100
&REFTRAJ
TRAJ_FILE_NAME slab.xyz
FIRST_SNAPSHOT 1
EVAL_ENERGY_FORCES T
&END REFTRAJ
&END MD
&END MOTION
&FORCE_EVAL
METHOD QS
&DFT
BASIS_SET_FILE_NAME ./BASIS_SET
POTENTIAL_FILE_NAME ./POTENTIAL
UKS T
&SCF
MAX_ITER_LUMO 10000
EPS_LUMO 9.9999999999999995E-07
MAX_SCF 2000
EPS_SCF 9.9999999999999995E-08
CHOLESKY INVERSE_DBCSR
SCF_GUESS ATOMIC
ADDED_MOS 500
&DIAGONALIZATION T
ALGORITHM STANDARD
&END DIAGONALIZATION
&SMEAR T
METHOD FERMI_DIRAC
ELECTRONIC_TEMPERATURE 2.5000000000000000E+02
&END SMEAR
&MIXING T
METHOD BROYDEN_MIXING
ALPHA 1.0000000000000001E-01
BETA 1.5000000000000000E+00
NBUFFER 8
&END MIXING
&PRINT
&RESTART ON
ADD_LAST NUMERIC
COMMON_ITERATION_LEVELS 1
BACKUP_COPIES 0
&EACH
MD 1
&END EACH
&END RESTART
&RESTART_HISTORY OFF
&END RESTART_HISTORY
&END PRINT
&END SCF
&QS
EPS_DEFAULT 9.9999999999999998E-13
MAP_CONSISTENT T
EXTRAPOLATION ASPC
EXTRAPOLATION_ORDER 4
METHOD GPW
&END QS
&MGRID
NGRIDS 5
CUTOFF 5.5000000000000000E+02
REL_CUTOFF 6.0000000000000000E+01
&END MGRID
&XC
DENSITY_CUTOFF 1.0000000000000000E-10
GRADIENT_CUTOFF 1.0000000000000000E-10
TAU_CUTOFF 1.0000000000000000E-10
&XC_GRID
XC_SMOOTH_RHO NONE
XC_DERIV SPLINE2
&END XC_GRID
&XC_FUNCTIONAL NO_SHORTCUT
&PBE T
&END PBE
&END XC_FUNCTIONAL
&VDW_POTENTIAL
POTENTIAL_TYPE PAIR_POTENTIAL
&PAIR_POTENTIAL
TYPE DFTD3(BJ)
PARAMETER_FILE_NAME ./dftd3.dat
REFERENCE_FUNCTIONAL PBE
CALCULATE_C9_TERM T
REFERENCE_C9_TERM T
LONG_RANGE_CORRECTION T
&END PAIR_POTENTIAL
&END VDW_POTENTIAL
&END XC
&PRINT
&PDOS SILENT
FILENAME dosfile
LOG_PRINT_KEY T
COMPONENTS F
APPEND T
NLUMO -1
&END PDOS
&LOWDIN ON
FILENAME lowdin
&EACH
MD 1
&END EACH
&END LOWDIN
&END PRINT
&END DFT
&SUBSYS
&CELL
A 1.0210621920300001E+01 0.0000000000000000E+00 0.0000000000000000E+00
B 5.1053109601699997E+00 8.8426579714500004E+00 0.0000000000000000E+00
C 0.0000000000000000E+00 0.0000000000000000E+00 2.2084234471799999E+01
PERIODIC XYZ
MULTIPLE_UNIT_CELL 1 1 1
&END CELL
&COORD
Cu -6.3871241730842820E-01 1.8409029124369907E+00 9.8993381405720324E+00
Cu 1.9297510687263069E+00 1.8332970519842473E+00 9.8995653494722191E+00
Cu 4.4666001697550950E+00 1.8409024300368910E+00 9.8993380691689215E+00
Cu 7.0350593540425637E+00 1.8332978744017399E+00 9.8995653805527084E+00
Cu 6.3878521708616542E-01 4.0541385289095482E+00 9.8993228800211970E+00
Cu 3.1756712246289913E+00 4.0617407710352458E+00 9.8988329597437374E+00
Cu 5.7440967989788412E+00 4.0541373137101511E+00 9.8993228016739341E+00
Cu 8.2809819318742512E+00 4.0617397411245255E+00 9.8988328574889959E+00
Cu 1.9139428452612195E+00 6.2622297374568561E+00 9.8993380463087863E+00
Cu 4.4824066549714274E+00 6.2546237638880919E+00 9.8995655579992903E+00
Cu 7.0192544925479803E+00 6.2622315867769389E+00 9.8993380313065362E+00
Cu 9.5877156447880871E+00 6.2546256357479422E+00 9.8995654906316410E+00
Cu 3.1914397439794464E+00 8.4754650138121992E+00 9.8993227987159607E+00
Cu 5.7283268874110060E+00 8.4830679413795949E+00 9.8988330426618827E+00
Cu 8.2967525949275487E+00 8.4754641039542076E+00 9.8993228159085138E+00
Cu 1.0833635744725784E+01 8.4830693378159054E+00 9.8988330500656527E+00
Cu -6.2301593544263545E-01 3.5959003595735062E-01 1.2185401430280356E+01
Cu 1.9138712132819797E+00 3.6719296184924566E-01 1.2184911666906014E+01
Cu 4.4822971412370709E+00 3.5958861485703075E-01 1.2185401418379909E+01
Cu 7.0191802960149534E+00 3.6719385514883734E-01 1.2184911663281012E+01
Cu 6.2290430844247280E-01 2.5880341947602212E+00 1.2184668909838207E+01
Cu 3.1913681145302353E+00 2.5804282484070162E+00 1.2184896416283024E+01
Cu 5.7282172284216388E+00 2.5880323463610755E+00 1.2184668981516452E+01
Cu 8.2966783936443118E+00 2.5804263800245417E+00 1.2184896438337406E+01
Cu 1.9296397486665935E+00 4.7809172037670500E+00 1.2185401514624932E+01
Cu 4.4665257436694796E+00 4.7885194487835747E+00 1.2184911589240892E+01
Cu 7.0349509359805955E+00 4.7809182389469385E+00 1.2185401616009910E+01
Cu 9.5718360829119220E+00 4.7885206765974386E+00 1.2184911671702158E+01
Cu 3.1755598753809982E+00 7.0093609204370315E+00 1.2184669132069777E+01
Cu 5.7440233741937607E+00 7.0017550498319086E+00 1.2184896337050699E+01
Cu 8.2808735397118216E+00 7.0093600919152967E+00 1.2184669086904883E+01
Cu 1.0849332718461687E+01 7.0017555519124031E+00 1.2184896408123929E+01
&END COORD
&KIND Mo
BASIS_SET DZVP-MOLOPT-SR-GTH
POTENTIAL GTH-PBE-q14
&END KIND
&KIND S
BASIS_SET DZVP-MOLOPT-SR-GTH
POTENTIAL GTH-PBE-q6
&END KIND
&KIND Co
BASIS_SET DZVP-MOLOPT-SR-GTH
POTENTIAL GTH-PBE-q17
&END KIND
&KIND Ni
BASIS_SET DZVP-MOLOPT-SR-GTH
POTENTIAL GTH-PBE-q18
&END KIND
&KIND Cu
BASIS_SET DZVP-MOLOPT-SR-GTH
POTENTIAL GTH-PBE-q11
&POTENTIAL
1 0 10
0.5300000000000000E+00 0
3
0.4313550500000000E+00 3 0.9693805070000000E+01 -0.6470165350000000E+01 0.1935952150000000E+01
0.1150177396000000E+02 -0.4998606960000000E+01
0.3967521270000000E+01
0.5613915500000000E+00 2 0.2545473300000000E+01 -0.7846357300000000E+00
0.9283935200000000E+00
0.2645548500000000E+00 1 -0.1282861406000000E+02
# Potential name: GTH-PBE-Q11 for symbol: CU
# Potential read from the potential filename: ./POTENTIAL
&END POTENTIAL
&END KIND
&KIND H
BASIS_SET DZVP-MOLOPT-GTH
POTENTIAL GTH-PBE-q1
&END KIND
&TOPOLOGY
COORD_FILE_NAME slab.xyz
COORD_FILE_FORMAT XYZ
NUMBER_OF_ATOMS 32
MULTIPLE_UNIT_CELL 1 1 1
&CENTER_COORDINATES T
&END CENTER_COORDINATES
&END TOPOLOGY
&PRINT
&CELL ON
&END CELL
&END PRINT
&END SUBSYS
&PRINT
&FORCES SILENT
FILENAME forces
&EACH
MD 1
&END EACH