Skip to content

Commit

Permalink
feat(ai2bmd): option to exclude solvent in output
Browse files Browse the repository at this point in the history
add option to control if solvent atoms should be written to output
trajectory file. default is 'True'.

fixes #32.
  • Loading branch information
bi-ran committed Dec 9, 2024
1 parent 79b1db8 commit ec7b172
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions scripts/ai2bmd
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ def parse_args(argv):
dest='solvent',
help="Do not use solvent",
)
parser.add_argument(
"--write-solvent",
action='store_true',
help="Write coordinates of solvent atoms in output",
)
parser.add_argument(
"--no-write-solvent",
action='store_false',
dest='write_solvent',
help="Do not write coordinates of solvent atoms in output",
)
parser.add_argument(
"--preprocess-method",
type=str,
Expand Down
6 changes: 6 additions & 0 deletions src/AIMD/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def init(argv=None):
default=True,
help="Use solvent or not",
)
parser.add_argument(
"--write-solvent",
action=argparse.BooleanOptionalAction,
default=True,
help="Write coordinates of solvent atoms in output",
)
parser.add_argument(
"--preprocess-method",
type=str,
Expand Down
1 change: 1 addition & 0 deletions src/AIMD/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def simulate(

observer = MDObserver(
a=self.prot,
q=self.qmatoms,
md=MolDyn,
traj=moldyn_traj,
rng=rng_pool,
Expand Down
9 changes: 7 additions & 2 deletions src/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from ase.io.trajectory import TrajectoryWriter
from ase.md.md import MolecularDynamics

from AIMD import arguments


def record_time(func):
def wrapper(*args, **kwargs):
Expand Down Expand Up @@ -115,20 +117,23 @@ class MDObserver:
MolecularDynamics object, notified at every step.
"""

def __init__(self, a: Atoms, md: MolecularDynamics, traj: TrajectoryWriter, rng: RNGPool, step_offset: int, temp_k: int):
def __init__(self, a: Atoms, q: Atoms, md: MolecularDynamics, traj: TrajectoryWriter, rng: RNGPool, step_offset: int, temp_k: int):
self.a = a
self.q = q
self.md = md
self.traj = traj
self.rng = rng
self.step_offset = step_offset
self.copy = None
self.temp_k = temp_k

self.atoms = a if arguments.get().write_solvent else q

def get_md_step(self):
return self.step_offset + self.md.nsteps

def save_traj_copy(self):
self.copy = self.a.copy()
self.copy = self.atoms.copy()

@delay_work
def write_traj(self):
Expand Down

0 comments on commit ec7b172

Please sign in to comment.