Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bananenpampe committed Mar 1, 2024
1 parent 06a9309 commit 216e0d5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions docs/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ COSMO Software Cookbook
examples/lode_linear/lode_tutorial
examples/sample_selection/sample_selection
examples/gaas_map/gaas_map
example/cp2k_run_batch/setup_reftraj
7 changes: 3 additions & 4 deletions examples/cp2k_run_batch/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ CP2K bash computation
============================

This is an example of a batch calculation using CP2K.
The inputs are a set of structures in `./data/example.xyz` using the parameters defined
in `./data/reftraj_template.cp2k` importing basisset and pseudopotentials from `./data/basis/`.


The inputs are a set of structures in `./data/example.xyz`
using the parameters defined in `./data/reftraj_template.cp2k`
importing basisset and pseudopotentials from `./data/basis/`.
40 changes: 22 additions & 18 deletions examples/cp2k_run_batch/setup_reftraj.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
.. start-body
This is an example of a batch calculation using CP2K.
The inputs are a set of structures in `./data/example.xyz` using the parameters defined
in `./data/reftraj_template.cp2k` importing basisset and pseudopotentials from `./data/basis/`.
The inputs are a set of structures in `./data/example.xyz` using the parameters defined
in `./data/reftraj_template.cp2k` importing basisset and
pseudopotentials from `./data/basis/`.
The script will create a directory `./production` containing subdirectories for each stoichiometry.
This is only necessary, because CP2K can only run calculations using a single stoichiometry at a time, using the reftraj functionality.
The script will create a directory `./production`
containing subdirectories for each stoichiometry.
This is only necessary, because CP2K can only run calculations
using a single stoichiometry at a time, using the reftraj functionality.
The reference paramaters are taken from: Cheng et al. Ab initio thermodynamics of liquid and solid water 2019.
The reference paramaters are taken from:
Cheng et al. Ab initio thermodynamics of liquid and solid water 2019.
"""

import os
Expand All @@ -25,9 +29,7 @@

import ase.io
import numpy as np
from ase.build import molecule
from ase.calculators.cp2k import CP2K
from numpy.testing import assert_allclose


# %%
Expand Down Expand Up @@ -57,7 +59,7 @@ def write_reftraj(fname: str, frames: Union[ase.Atoms, List[ase.Atoms]]):
f"{frames[0].get_chemical_formula()}. "
"CP2K does not support changing atom types within a reftraj run!"
)
n_atoms = len(atoms)

out += f"{len(atoms):>8}\n i = {i+1:>8}, time = {0:>12.3f}\n"
for atom in atoms:
pos = atom.position
Expand All @@ -74,7 +76,11 @@ def write_cellfile(fname: str, frames: Union[ase.Atoms, List[ase.Atoms]]):
if isinstance(frames, ase.Atoms):
frames = [frames]

out = "# Step Time [fs] Ax [Angstrom] Ay [Angstrom] Az [Angstrom] Bx [Angstrom] By [Angstrom] Bz [Angstrom] Cx [Angstrom] Cy [Angstrom] Cz [Angstrom] Volume [Angstrom^3]\n"
out = "# Step Time [fs] Ax [Angstrom] Ay [Angstrom]\
Az [Angstrom] Bx [Angstrom] By [Angstrom]\
Bz [Angstrom] Cx [Angstrom]\
Cy [Angstrom] Cz [Angstrom]\
Volume [Angstrom^3]\n"
for i, atoms in enumerate(frames):
out += f"{i+1:>8}{0:>12.3f}"
out += "".join([f"{c:>20.10f}" for c in atoms.cell.flatten()])
Expand All @@ -95,9 +101,10 @@ def write_cp2k_in(fname: str, project: str, last_snapshot: int, cell: List[float
cp2k_in = f.read()

warnings.warn(
"Due to the small size of the test structure and convergence issues, we have\
decreased the size of the CUTOFF_RADIUS from 6.0 to 3.0. \
For actual production calculations adapt the template!"
"Due to the small size of the test structure and convergence issues, we have \
decreased the size of the CUTOFF_RADIUS from 6.0 to 3.0. \
For actual production calculations adapt the template!",
stacklevel=2,
)

cp2k_in = cp2k_in.replace("//PROJECT//", project)
Expand All @@ -118,7 +125,7 @@ def write_cp2k_in(fname: str, project: str, last_snapshot: int, cell: List[float
def mkdir_force(*args, **kwargs):
try:
os.mkdir(*args, **kwargs)
except OSError as e:
except OSError:
pass


Expand Down Expand Up @@ -175,7 +182,7 @@ def mkdir_force(*args, **kwargs):
#

# run the bash script directly from this script
subprocess.run(f"bash run_calcs.sh", shell=True)
subprocess.run("bash run_calcs.sh", shell=True)


# %%
Expand All @@ -184,9 +191,6 @@ def mkdir_force(*args, **kwargs):
# :language: bash
# .. download:: Download the script <run_calcs.sh>

# alternatively do:
# subprocess.run(f"cd ./production && for i in $(find . -mindepth 1 -type d); do cd \"$i\"; cp2k.ssmp -i in.cp2k ; cd -; done", shell=True)

# %%
# Load results
# ============
Expand Down Expand Up @@ -260,7 +264,7 @@ def mkdir_force(*args, **kwargs):
# multiplicity=None,
poisson_solver=None,
print_level=None,
command=f"./cp2k_shell.ssmp --shell",
command="./cp2k_shell.ssmp --shell",
)

atoms = ase.io.read("./data/example.xyz")
Expand Down

0 comments on commit 216e0d5

Please sign in to comment.