Skip to content

Commit

Permalink
Reintroduce structure parser based on pdb format v0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Nov 10, 2017
1 parent 39ef402 commit 8c9e629
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
6 changes: 5 additions & 1 deletion aiida_cp2k/calculations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def _init_internal_params(self):
self._OUTPUT_FILE_NAME = 'aiida.out'
self._DEFAULT_INPUT_FILE = self._INPUT_FILE_NAME
self._DEFAULT_OUTPUT_FILE = self._OUTPUT_FILE_NAME
self._PROJECT_NAME = 'aiida'
self._TRAJ_FILE_NAME = self._PROJECT_NAME + '-pos-1.pdb'
self._COORDS_FILE_NAME = 'aiida.coords.pdb'
self._default_parser = 'cp2k'

Expand Down Expand Up @@ -101,6 +103,8 @@ def _prepare_for_submission(self, tempfolder, inputdict):

# write cp2k input file
inp = Cp2kInput(params)
inp.add_keyword("GLOBAL/PROJECT", self._PROJECT_NAME)
inp.add_keyword("MOTION/PRINT/TRAJECTORY/FORMAT", "PDB")
if structure is not None:
struct_fn = tempfolder.get_abs_path(self._COORDS_FILE_NAME)
structure.get_ase().write(struct_fn, format="proteindatabank")
Expand Down Expand Up @@ -135,7 +139,7 @@ def _prepare_for_submission(self, tempfolder, inputdict):
calcinfo.remote_symlink_list = []
calcinfo.local_copy_list = local_copy_list
calcinfo.remote_copy_list = []
calcinfo.retrieve_list = [self._OUTPUT_FILE_NAME]
calcinfo.retrieve_list = [self._OUTPUT_FILE_NAME, self._TRAJ_FILE_NAME]
calcinfo.retrieve_list += settings.pop('additional_retrieve_list', [])

# check for left over settings
Expand Down
27 changes: 27 additions & 0 deletions aiida_cp2k/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
# For further information please visit http://www.aiida.net #
###########################################################################

import re
import ase.io
from StringIO import StringIO

from aiida.parsers.parser import Parser
from aiida.orm.data.parameter import ParameterData
from aiida.orm.data.structure import StructureData
from aiida.parsers.exceptions import OutputParsingError
from aiida_cp2k.calculations import Cp2kCalculation

Expand Down Expand Up @@ -41,6 +44,7 @@ def parse_with_retrieved(self, retrieved):

new_nodes_list = []
self._parse_stdout(out_folder, new_nodes_list)
self._parse_trajectory(out_folder, new_nodes_list)

return True, new_nodes_list

Expand All @@ -57,8 +61,31 @@ def _parse_stdout(self, out_folder, new_nodes_list):
if line.startswith(' ENERGY| '):
result_dict['energy'] = float(line.split()[8])
result_dict['energy_units'] = "a.u."
if line.startswith(' The number of warnings for this run is :'):
result_dict['nwarnings'] = int(line.split()[-1])

pair = (self.get_linkname_outparams(), ParameterData(dict=result_dict))
new_nodes_list.append(pair)

#---------------------------------------------------------------------------
def _parse_trajectory(self, out_folder, new_nodes_list):
fn = self._calc._TRAJ_FILE_NAME
if fn not in out_folder.get_folder_list():
return # not every run type produces a trajectory

abs_fn = out_folder.get_abs_path(fn)
content = open(abs_fn).read()
frames = re.findall(r"\n(REMARK.*?\nEND)", content, re.DOTALL)
atoms = ase.io.read(StringIO(frames[-1]), format='proteindatabank')
pair = (self.get_linkname_outstructure(), StructureData(ase=atoms))
new_nodes_list.append(pair)

#---------------------------------------------------------------------------
def get_linkname_outstructure(self):
"""
Returns the name of the link to the output_structure
"""
return 'output_structure'


#EOF
2 changes: 1 addition & 1 deletion setup.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.4",
"version": "0.5",
"name": "aiida_cp2k",
"url": "https://github.com/cp2k/aiida-cp2k",
"license": "MIT License",
Expand Down
28 changes: 16 additions & 12 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def main():

codename = sys.argv[1]
code = test_and_get_code(codename, expected_code_type='cp2k')
test_no_structure_data(code)
test_energy_mm(code)
test_energy_dft(code)
test_geo_opt_dft(code)
test_no_structure_data(code)
print("All tests passed :-)")
sys.exit(0)

Expand Down Expand Up @@ -122,6 +122,9 @@ def test_energy_mm(code):

wait_for_calc(calc)

# check warnings
assert calc.res.nwarnings == 0

# check energy
expected_energy = 0.146927412614e-3
if abs(calc.res.energy - expected_energy) < 1e-10:
Expand Down Expand Up @@ -201,10 +204,6 @@ def test_geo_opt_dft(code):
})
calc.use_parameters(parameters)

# settings
settings = ParameterData(dict={'additional_retrieve_list':['*.xyz']})
calc.use_settings(settings)

# resources
calc.set_max_wallclock_seconds(3*60) # 3 min
calc.set_resources({"num_machines": 1})
Expand All @@ -227,9 +226,8 @@ def test_geo_opt_dft(code):
sys.exit(3)

# check geometry
expected_dist = 0.736125211
traj_fn = calc.out.retrieved.get_abs_path('PROJECT-pos-1.xyz')
dist = ase.io.read(traj_fn, index='-1').get_distance(0, 1)
expected_dist = 0.737 # pdb format has only three digits
dist = calc.out.output_structure.get_ase().get_distance(0, 1)
if abs(dist - expected_dist) < 1e-7:
print "OK, H-H distance has the expected value"
else:
Expand Down Expand Up @@ -329,14 +327,20 @@ def wait_for_calc(calc, timeout_secs=5*60.0):
except subprocess.CalledProcessError as e:
print "Note: the command failed, message: {}".format(e.message)
if calc.has_finished():
print "Calculation terminated its execution"
print "Calculation terminated its execution."
exited_with_timeout = False
break

# check exit status
# check for timeout
if exited_with_timeout:
print "Timeout!! Calculation did not complete after {} seconds".format(
timeout_secs)
print "Timeout!! Calculation did not complete after %i seconds" % timeout_secs
os.system("cat ~/.aiida/daemon/log/aiida_daemon.log")
sys.exit(2)

# check calculation status
if calc.has_failed():
print "Calculation failed with state: " + calc.get_state()
os.system("cat ~/.aiida/daemon/log/aiida_daemon.log")
sys.exit(2)

#===============================================================================
Expand Down

0 comments on commit 8c9e629

Please sign in to comment.