Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smirnoff Interaction energy #288

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def get(self, mvals, AGrad=False, AHess=False):

def callM(mvals_, dielectric=False):
logger.info("\r")
pvals = self.FF.make(mvals_)
self.FF.make(mvals_)
return self.engine.interaction_energy(self.select1, self.select2)

logger.info("Executing\r")
Expand All @@ -193,7 +193,7 @@ def callM(mvals_, dielectric=False):
np.savetxt('M.txt',emm)
np.savetxt('Q.txt',self.eqm)
import pickle
pickle.dump((self.name, self.label, self.prefactor, self.eqm, emm), open("qm_vs_mm.p",'w'))
pickle.dump((self.name, self.label, self.prefactor, self.eqm, emm), open("qm_vs_mm.p",'wb'))
# select the qm and mm data that has >0 weight to plot
qm_data, mm_data = [], []
for i in range(len(self.eqm)):
Expand All @@ -206,8 +206,8 @@ def callM(mvals_, dielectric=False):
if AGrad or AHess:
for p in self.pgrad:
dV[p,:], _ = f12d3p(fdwrap(callM, mvals, p), h = self.h, f0 = emm)
# Create the force field one last time.
pvals = self.FF.make(mvals)
# # Create the force field one last time.
# pvals = self.FF.make(mvals)

Answer['X'] = np.dot(self.prefactor*D/self.divisor,D/self.divisor)
for p in self.pgrad:
Expand All @@ -218,15 +218,16 @@ def callM(mvals_, dielectric=False):
if not in_fd():
self.emm = emm
self.objective = Answer['X']
self.FF.make(mvals)

## QYD: try to clean up OpenMM engine.simulation objects to free up GPU memory
try:
if self.engine.name == 'openmm':
if hasattr(self.engine, 'simulation'): del self.engine.simulation
if hasattr(self.engine, 'A'): del self.engine.A
if hasattr(self.engine, 'B'): del self.engine.B
except:
pass
# try:
# if self.engine.name == 'openmm':
# if hasattr(self.engine, 'simulation'): del self.engine.simulation
# if hasattr(self.engine, 'A'): del self.engine.A
# if hasattr(self.engine, 'B'): del self.engine.B
# except:
# pass

return Answer

Expand Down
3 changes: 2 additions & 1 deletion src/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
logger.warning("OpenMM module import failed; check OpenMM package\n")

try:
from forcebalance.smirnoffio import AbInitio_SMIRNOFF, Liquid_SMIRNOFF, Vibration_SMIRNOFF, Hessian_SMIRNOFF, OptGeoTarget_SMIRNOFF, TorsionProfileTarget_SMIRNOFF, smirnoff_analyze_parameter_coverage
from forcebalance.smirnoffio import AbInitio_SMIRNOFF, Liquid_SMIRNOFF, Vibration_SMIRNOFF, Hessian_SMIRNOFF, OptGeoTarget_SMIRNOFF, TorsionProfileTarget_SMIRNOFF, smirnoff_analyze_parameter_coverage, Interaction_SMIRNOFF
except:
logger.warning(traceback.format_exc())
logger.warning("SMIRNOFF module import failed; check SMIRNOFF package\n")
Expand Down Expand Up @@ -112,6 +112,7 @@
'INTERACTION_GMX':Interaction_GMX,
'INTERACTION_TINKER':Interaction_TINKER,
'INTERACTION_OPENMM':Interaction_OpenMM,
'INTERACTION_SMIRNOFF': Interaction_SMIRNOFF,
'BINDINGENERGY_TINKER':BindingEnergy_TINKER,
'BINDINGENERGY_GMX':BindingEnergy_GMX,
'BINDINGENERGY_OPENMM':BindingEnergy_OpenMM,
Expand Down
2 changes: 2 additions & 0 deletions src/openmmio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from builtins import zip
from builtins import range
import os

import openmm
from forcebalance import BaseReader
from forcebalance.abinitio import AbInitio
from forcebalance.binding import BindingEnergy
Expand Down
29 changes: 19 additions & 10 deletions src/smirnoffio.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,16 +795,25 @@ def submit_jobs(self, mvals, AGrad=False, AHess=False):
# ## Initialize base class.
# super(BindingEnergy_OpenMM,self).__init__(options,tgt_opts,forcefield)

# class Interaction_SMIRNOFF(Interaction):
# """ Interaction matching using OpenMM. """
# def __init__(self,options,tgt_opts,forcefield):
# ## Default file names for coordinates and key file.
# self.set_option(tgt_opts,'coords',default="all.pdb")
# self.set_option(tgt_opts,'openmm_precision','precision',default="double", forceprint=True)
# self.set_option(tgt_opts,'openmm_platform','platname',default="Reference", forceprint=True)
# self.engine_ = OpenMM
# ## Initialize base class.
# super(Interaction_OpenMM,self).__init__(options,tgt_opts,forcefield)
class Interaction_SMIRNOFF(Interaction):
""" Interaction matching using OpenMM. """
def __init__(self,options,tgt_opts,forcefield):
## Default file names for coordinates and key file.
# file for the whole topology
self.set_option(tgt_opts, 'pdb', default="top.pdb")
# cords of the system along some scan coordinate
self.set_option(tgt_opts,'coords',default="scan.xyz")
# a list of the separate mol2 files
self.set_option(tgt_opts, 'mol2', forceprint=True)
self.set_option(tgt_opts,'openmm_precision','precision',default="double", forceprint=True)
self.set_option(tgt_opts,'openmm_platform','platname',default="Reference", forceprint=True)
self.engine_ = SMIRNOFF
## Initialize base class.
super(Interaction_SMIRNOFF,self).__init__(options,tgt_opts,forcefield)

def submit_jobs(self, mvals, AGrad=False, AHess=False):
# we update the self.pgrads here so it's not overwritten in rtarget.py
smirnoff_update_pgrads(self)

# class Moments_SMIRNOFF(Moments):
# """ Multipole moment matching using OpenMM. """
Expand Down