Skip to content

Commit

Permalink
Make StructureData optional, v0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Nov 6, 2017
1 parent b8aaf9e commit 05e85f8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
27 changes: 12 additions & 15 deletions aiida_cp2k/calculations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,19 @@ def _prepare_for_submission(self, tempfolder, inputdict):

# write cp2k input file
inp = Cp2kInput(params)
for i, a in enumerate('ABC'):
val = '{:<15} {:<15} {:<15}'.format(*structure.cell[i])
inp.add_keyword('FORCE_EVAL/SUBSYS/CELL/'+a, val)
inp.add_keyword("FORCE_EVAL/SUBSYS/TOPOLOGY/COORD_FILE_NAME", self._COORDS_FILE_NAME)
inp.add_keyword("FORCE_EVAL/SUBSYS/TOPOLOGY/COORD_FILE_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")
for i, a in enumerate('ABC'):
val = '{:<15} {:<15} {:<15}'.format(*structure.cell[i])
inp.add_keyword('FORCE_EVAL/SUBSYS/CELL/'+a, val)
inp.add_keyword("FORCE_EVAL/SUBSYS/TOPOLOGY/COORD_FILE_NAME", self._COORDS_FILE_NAME)
inp.add_keyword("FORCE_EVAL/SUBSYS/TOPOLOGY/COORD_FILE_FORMAT", "pdb")
inp.add_keyword("GLOBAL/PROJECT", self._PROJECT_NAME)
inp_fn = tempfolder.get_abs_path(self._INPUT_FILE_NAME)
with open(inp_fn, "w") as f:
f.write(inp.render())

# write structure file
struct_fn = tempfolder.get_abs_path(self._COORDS_FILE_NAME)
structure.get_ase().write(struct_fn, format="proteindatabank")

# create code info
codeinfo = CodeInfo()
cmdline = settings.pop('cmdline', [])
Expand Down Expand Up @@ -162,12 +161,10 @@ def _verify_inlinks(self, inputdict):
params = params_node.get_dict()

# structure
try:
structure = inputdict.pop(self.get_linkname('structure'))
except KeyError:
raise InputValidationError("No structure specified for this calculation")
if not isinstance(structure, StructureData):
raise InputValidationError("structure is not of type StructureData")
structure = inputdict.pop(self.get_linkname('structure'), None)
if structure is not None:
if not isinstance(structure, StructureData):
raise InputValidationError("structure is not of type StructureData")

# code
try:
Expand Down
2 changes: 1 addition & 1 deletion setup.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.2.2",
"version": "0.3",
"name": "aiida_cp2k",
"url": "https://github.com/cp2k/aiida-cp2k",
"license": "MIT License",
Expand Down
48 changes: 42 additions & 6 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ 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)
Expand All @@ -44,11 +45,10 @@ def main():

#===============================================================================
def test_energy_mm(code):
print("Testing CP2K ENERGY (MM) ...")
print("Testing CP2K ENERGY on H2O (MM) ...")

# calc object
calc = code.new_calc()
calc.label = "Test CP2K ENERGY on H2O (MM)"

# parameters
# based on cp2k/tests/Fist/regtest-1-1/water_1.inp
Expand Down Expand Up @@ -143,11 +143,10 @@ def test_energy_mm(code):

#===============================================================================
def test_energy_dft(code):
print("Testing CP2K ENERGY (DFT)...")
print("Testing CP2K ENERGY on H2O (DFT)...")

# calc object
calc = code.new_calc()
calc.label = "Test CP2K ENERGY on H2O (DFT)"

# structure
atoms = ase.build.molecule('H2O')
Expand Down Expand Up @@ -182,11 +181,10 @@ def test_energy_dft(code):

#===============================================================================
def test_geo_opt_dft(code):
print("Testing CP2K GEO_OPT (DFT)...")
print("Testing CP2K GEO_OPT on H2 (DFT)...")

# calc object
calc = code.new_calc()
calc.label = "Test CP2K GEO_OPT on H2 (DFT)"

# structure
atoms = ase.build.molecule('H2')
Expand Down Expand Up @@ -235,6 +233,44 @@ def test_geo_opt_dft(code):
print "Actual dist value: {}".format(dist)
sys.exit(3)

#===============================================================================
def test_no_structure_data(code):
print("Testing CP2K ENERGY on H2 (DFT) without StructureData...")

# calc object
calc = code.new_calc()

# structure directly included in parameters
force_eval = get_force_eval()
force_eval['SUBSYS']['CELL'] = {'ABC': '4.0 4.0 4.75'}
force_eval['SUBSYS']['COORD'] = {' ': ['H 2.0 2.0 2.737166',
'H 2.0 2.0 2.000000']}

# parameters
parameters = ParameterData(dict={'FORCE_EVAL':force_eval})
calc.use_parameters(parameters)

# resources
calc.set_max_wallclock_seconds(3*60) # 3 min
calc.set_resources({"num_machines": 1})

# store and submit
calc.store_all()
calc.submit()
print "submitted calculation: UUID=%s, pk=%s"%(calc.uuid,calc.dbnode.pk)

wait_for_calc(calc)

# check results
expected_energy = -1.14005678487
if abs(calc.res.energy - expected_energy) < 1e-10:
print "OK, energy has the expected value"
else:
print "ERROR!"
print "Expected energy value: {}".format(expected_energy)
print "Actual energy value: {}".format(calc.res.energy)
sys.exit(3)

#===============================================================================
def get_force_eval():
return {
Expand Down

0 comments on commit 05e85f8

Please sign in to comment.