Skip to content

Commit

Permalink
Merge pull request #405 from RagnarB83/NEW
Browse files Browse the repository at this point in the history
CI now working with some basic tests: OpenMM, pyscf, xtb, geometric
  • Loading branch information
RagnarB83 authored Jan 25, 2024
2 parents aa5b4f8 + 0dd3925 commit a0c1c47
Show file tree
Hide file tree
Showing 6 changed files with 26,235 additions and 13 deletions.
25 changes: 18 additions & 7 deletions ash/interfaces/interface_OpenMM.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ def __init__(self, printlevel=2, platform='CPU', numcores=1, topoforce=False, fo
import openmm
import openmm.app
import openmm.unit
from packaging import version
if self.printlevel > 0:
print("Imported OpenMM library version:", openmm.__version__)
if float(openmm.__version__) < 8.0:
if version.parse(openmm.__version__) < version.parse("8.1"):
print("Warning: OpenMM version < 8.1. OpenMM 8.1 or higher is recommended")
print("Some features may not work as intended in older versions")
except ImportError:
Expand Down Expand Up @@ -344,7 +345,10 @@ def __init__(self, printlevel=2, platform='CPU', numcores=1, topoforce=False, fo
#OpenMM 8.1 allows us to do this easily by constructor, older versions requires hacky workarounds
# (see set_periodics_before_system_creation for those hacks)
#Note: https://github.com/openmm/openmm/issues/4078
if float(openmm.__version__) >= 8.1:
from packaging import version
#if float(openmm.__version__) >= 8.1:
if version.parse(openmm.__version__) >= version.parse("8.1"):

if PBCvectors is None:
temp_pbc_vecs=None
else:
Expand Down Expand Up @@ -856,6 +860,7 @@ def __init__(self, printlevel=2, platform='CPU', numcores=1, topoforce=False, fo
#Function that handles periodicity in forcefield objects (for Amber, CHARMM). TODO: Test GROMACS and XML
def set_periodics_before_system_creation(self,PBCvectors,periodic_cell_dimensions,CHARMMfiles,Amberfiles,use_parmed):
import openmm
from packaging import version
if use_parmed is True:
import parmed
print("Inspecting periodicity input before system creation")
Expand All @@ -882,7 +887,8 @@ def set_periodics_before_system_creation(self,PBCvectors,periodic_cell_dimension
print("Amber-prmtop getIfBox:", self.forcefield._prmtop.getIfBox())
self.forcefield._prmtop._raw_data['POINTERS'][27] = 1
print("Amber-prmtop getIfBox:", self.forcefield._prmtop.getIfBox())
if float(openmm.__version__) < 8.1:

if version.parse(openmm.__version__) < version.parse("8.1"):
print("Warning: Amber prmtop file detected and OpenMM version < 8.0")
print("Warning: Will assume cubic box and set PBC vectors in a hacky way")
self.forcefield._prmtop._raw_data["BOX_DIMENSIONS"] =np.array([0.0,0.0,0.0,0.0])
Expand Down Expand Up @@ -943,7 +949,7 @@ def set_periodics_before_system_creation(self,PBCvectors,periodic_cell_dimension
#Happens if no IFBOX defined in prmtop file but we still want periodicity
self.forcefield._prmtop._raw_data['POINTERS'][27] = 1

if float(openmm.__version__) < 8.1:
if version.parse(openmm.__version__) < version.parse("8.1"):
print("Warning: Amber prmtop file detected and OpenMM version < 8.1")
print("Warning: Will assume cubic box and set PBC vectors in a hacky way")
self.forcefield._prmtop._raw_data["BOX_DIMENSIONS"] =np.array([0.0,0.0,0.0,0.0])
Expand Down Expand Up @@ -2209,6 +2215,7 @@ def clean_up_constraints_list(fragment=None, constraints=None):
def OpenMM_Opt(fragment=None, theory=None, maxiter=1000, tolerance=1, enforcePeriodicBox=True,
traj_frequency=100, use_reporter=True):
import openmm
from packaging import version
module_init_time = time.time()
print_line_with_mainheader("OpenMM Optimization")

Expand All @@ -2226,7 +2233,8 @@ def OpenMM_Opt(fragment=None, theory=None, maxiter=1000, tolerance=1, enforcePer
print("Number of atoms:", fragment.numatoms)
print("Max iterations:", maxiter)
print(f"Tolerance: {tolerance} kj/mol/nm:")
if float(openmm.__version__) >= 8.1:
#if float(openmm.__version__) >= 8.1:
if version.parse(openmm.__version__) >= version.parse("8.1"):
print("Will write to trajectory every {} iterations".format(traj_frequency))

print("OpenMM autoconstraints:", openmmobject.autoconstraints)
Expand Down Expand Up @@ -2269,7 +2277,8 @@ def OpenMM_Opt(fragment=None, theory=None, maxiter=1000, tolerance=1, enforcePer
#New in OpenMM 8.1: reporters for minimizer
#StateDataReporter
#############################################
if float(openmm.__version__ ) >= 8.1 and use_reporter is True:
#if float(openmm.__version__ ) >= 8.1 and use_reporter is True:
if version.parse(openmm.__version__) >= version.parse("8.1") and use_reporter is True:
class Reporter(openmm.openmm.MinimizationReporter):
def report(self, iteration,x,grad,args):
try:
Expand Down Expand Up @@ -2356,7 +2365,9 @@ def get_state(self):
print("")
#####################################
print("Starting minimization.")
if float(openmm.__version__) >= 8.1 and use_reporter is True:
#if float(openmm.__version__) >= 8.1 and use_reporter is True:
if version.parse(openmm.__version__) >= version.parse("8.1") and use_reporter is True:

print("OpenMM versions >= 8.1. Will use a reporter to output progress")
print("OpenMM_Opt trajectory will be written to: OpenMMOpt_traj.xyz")
#Removing possible old traj file
Expand Down
8 changes: 4 additions & 4 deletions ash/interfaces/interface_pyscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2159,7 +2159,7 @@ def prepare_run(self, current_coords=None, current_MM_coords=None, MMcharges=Non


#Setting number of electrons for system (used by load_chkfile etc)
self.num_electrons = int(ash.modules.module_coords.nucchargelist(elems) - charge)
self.num_electrons = int(ash.modules.module_coords.nucchargelist(qm_elems) - charge)
print("Number of electrons:", self.num_electrons)
print()

Expand Down Expand Up @@ -2226,7 +2226,7 @@ def prepare_run(self, current_coords=None, current_MM_coords=None, MMcharges=Non
#FROZEN ORBITALS in CC
##############################
if self.CC or self.MP2:
self.set_frozen_core_settings(elems)
self.set_frozen_core_settings(qm_elems)

##############################
#EMBEDDING OPTIONS
Expand Down Expand Up @@ -2407,7 +2407,7 @@ def actualrun(self, current_coords=None, current_MM_coords=None, MMcharges=None,
#NOTE: this is not entirely correct since occupied orbitals are natural orbitals rather than frozen HF orbitals as in the original method
#Not sure how much it matters
if self.FNO is True:
mo_coefficients = self.setup_FNO(elems=elems)
mo_coefficients = self.setup_FNO(elems=qm_elems)
#Calling CC run function
self. CC_energy,self.ccobject = self.run_CC(self.mf,frozen_orbital_indices=self.frozen_orbital_indices, CCmethod=self.CCmethod,
CC_direct=self.CC_direct, mo_coefficients=mo_coefficients)
Expand All @@ -2420,7 +2420,7 @@ def actualrun(self, current_coords=None, current_MM_coords=None, MMcharges=None,
#####################
if self.CAS is True:
print("CAS run is on!")
self.run_CAS(elems=elems)
self.run_CAS(elems=qm_elems)
else:
if self.printlevel >1:
print("No post-SCF job.")
Expand Down
Loading

0 comments on commit a0c1c47

Please sign in to comment.