Skip to content

Commit

Permalink
add ability to pass more flags to crest
Browse files Browse the repository at this point in the history
  • Loading branch information
corinwagen committed Aug 1, 2022
1 parent 0c961c4 commit c0f23c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions cctk/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -1664,7 +1664,7 @@ def compute_energy(self, nprocs=1):
energy = opt.get_energy(self, nprocs=nprocs)
return energy

def csearch(self, nprocs=1, constraints=[], logfile=None, noncovalent=False, use_tempdir=True, gfn=2):
def csearch(self, nprocs=1, constraints=[], logfile=None, noncovalent=False, use_tempdir=True, gfn=2, additional_flags=None):
"""
Optimize molecule at the GFN2-xtb level of theory.
Expand All @@ -1674,14 +1674,15 @@ def csearch(self, nprocs=1, constraints=[], logfile=None, noncovalent=False, use
noncovalent (bool): whether or not to use non-covalent settings
logfile (str): file to write ongoing ``crest`` output to
use_tempdir (bool): write intermediate files to hidden directory (as opposed to current directory)
gfn (int or ``ff``): level of theory, either 1, 2, or ``ff``:w
gfn (int or ``ff``): level of theory, either 1, 2, or ``ff``
additional_flags (str): additional flags for command line
Returns
ConformationalEnsemble
"""
import cctk.optimize as opt
assert isinstance(nprocs, int), "nprocs must be int!"
return opt.csearch(molecule=self, nprocs=nprocs, constraints=constraints, noncovalent=noncovalent, logfile=logfile, use_tempdir=use_tempdir, gfn=gfn)
return opt.csearch(molecule=self, nprocs=nprocs, constraints=constraints, noncovalent=noncovalent, logfile=logfile, use_tempdir=use_tempdir, gfn=gfn, additional_flags=additional_flags)

def num_neighbors_by_atom(self):
"""
Expand Down
6 changes: 5 additions & 1 deletion cctk/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def csearch(use_tempdir=True, **kwargs):
nprocs (int): number of processors to use
noncovalent (Bool): whether or not to use non-covalent settings
logfile (str): file to write ongoing ``crest`` output to
additional_flags (str): flags to pass to command line
Returns:
cctk.ConformationalEnsemble
Expand All @@ -139,7 +140,7 @@ def csearch(use_tempdir=True, **kwargs):

return ensemble

def _do_csearch(molecule, directory, gfn=2, nprocs=1, logfile=None, noncovalent=False, constraints=None):
def _do_csearch(molecule, directory, gfn=2, nprocs=1, logfile=None, noncovalent=False, constraints=None, additional_flags=None):
assert isinstance(molecule, cctk.Molecule), "need a valid molecule!"
assert isinstance(nprocs, int)
assert isinstance(logfile, str)
Expand All @@ -163,6 +164,9 @@ def _do_csearch(molecule, directory, gfn=2, nprocs=1, logfile=None, noncovalent=
else:
command = f"crest xtb-in.xyz --gfn{gfn} --chrg {molecule.charge} --uhf {molecule.multiplicity - 1} -T {nprocs} {nci}"

if additional_flags is not None:
command = command + " " + additional_flags

if logfile:
with open(logfile, "w") as f:
result = sp.run(command, stdout=f, stderr=f, cwd=directory, shell=True)
Expand Down

0 comments on commit c0f23c4

Please sign in to comment.