def evaluatorTerms(self, universe, subset1, subset2, global_data): # The energy for subsets is defined as consisting only # of interactions within that subset, so the contribution # of an external field is zero. Therefore we just return # an empty list of energy terms. if subset1 is not None or subset2 is not None: return [] # Collect the scaling_factor into an array scaling_factor = ParticleScalar(universe) for o in universe: for a in o.atomList(): scaling_factor[a] = o.getAtomProperty(a, self.scaling_property) scaling_factor.scaleBy(self.scaling_prefactor) # Here we pass all the parameters to # the energy term code that handles energy calculations. return [TrilinearThreshGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], \ self.strength, scaling_factor, self.grid_name, self.max_val, self.Ethresh)]
def evaluatorTerms(self, universe, subset1, subset2, global_data): # The energy for subsets is defined as consisting only # of interactions within that subset, so the contribution # of an external field is zero. Therefore we just return # an empty list of energy terms. if subset1 is not None or subset2 is not None: return [] # Collect the scaling_factor into an array scaling_factor = ParticleScalar(universe) for o in universe: for a in o.atomList(): scaling_factor[a] = o.getAtomProperty(a, self.scaling_property) scaling_factor.scaleBy(self.scaling_prefactor) # Here we pass all the parameters to # the energy term code that handles energy calculations. return [TrilinearISqrtGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], \ self.strength, scaling_factor, self.grid_name)]
def evaluatorTerms(self, universe, subset1, subset2, global_data): # The energy for subsets is defined as consisting only # of interactions within that subset, so the contribution # of an external field is zero. Therefore we just return # an empty list of energy terms. if subset1 is not None or subset2 is not None: return [] # Collect the charges into an array charges = ParticleScalar(universe) for o in universe: for a in o.atomList(): charges[a] = o.getAtomProperty(a, self.charge_property) # Here we pass all the parameters to # the energy term code that handles energy calculations. return [ElectricFieldTerm(universe, self.strength, charges)]
def evaluatorTerms(self, universe, subset1, subset2, global_data): # The energy for subsets is defined as consisting only # of interactions within that subset, so the contribution # of an external field is zero. Therefore we just return # an empty list of energy terms. if subset1 is not None or subset2 is not None: return [] # Collect the scaling_factor into an array scaling_factor = ParticleScalar(universe) for o in universe: for a in o.atomList(): scaling_factor[a] = o.getAtomProperty(a, self.params['scaling_property']) scaling_factor.scaleBy(self.params['scaling_prefactor']) # Here we pass all the parameters to # the energy term code that handles energy calculations. if self.params['interpolation_type']=='Trilinear': if self.params['energy_thresh']>0: if self.params['inv_power'] is not None: raise NotImplementedError else: from MMTK_trilinear_thresh_grid import TrilinearThreshGridTerm return [TrilinearThreshGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'], self.params['energy_thresh'])] elif self.params['inv_power'] is not None: if self.params['inv_power']==-2: from MMTK_trilinear_isqrt_grid import TrilinearISqrtGridTerm return [TrilinearISqrtGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'])] else: from MMTK_trilinear_transform_grid import TrilinearTransformGridTerm return [TrilinearTransformGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, self.params['name'], self.params['inv_power'])] else: from MMTK_trilinear_grid import TrilinearGridTerm return [TrilinearGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'])] elif self.params['interpolation_type']=='BSpline': if self.params['inv_power'] is not None: from MMTK_BSpline_transform_grid import BSplineTransformGridTerm return [BSplineTransformGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'], self.params['inv_power'])] else: from MMTK_BSpline_grid import BSplineGridTerm return [BSplineGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'])] elif self.params['interpolation_type']=='CatmullRom': if self.params['inv_power'] is not None: from MMTK_CatmullRom_transform_grid import CatmullRomTransformGridTerm return [CatmullRomTransformGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'], self.params['inv_power'])] else: from MMTK_CatmullRom_grid import CatmullRomGridTerm return [CatmullRomGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'])] elif self.params['interpolation_type']=='Tricubic': raise NotImplementedError
def evaluatorTerms(self, universe, subset1, subset2, global_data): # The energy for subsets is defined as consisting only # of interactions within that subset, so the contribution # of an external field is zero. Therefore we just return # an empty list of energy terms. if subset1 is not None or subset2 is not None: return [] # Collect the scaling_factor into an array scaling_factor = ParticleScalar(universe) for o in universe: for a in o.atomList(): scaling_factor[a] = o.getAtomProperty( a, self.params['scaling_property']) scaling_factor.scaleBy(self.params['scaling_prefactor']) # Here we pass all the parameters to # the energy term code that handles energy calculations. if self.params['interpolation_type'] == 'Trilinear': if self.params['energy_thresh'] > 0: if self.params['inv_power'] is not None: raise NotImplementedError else: from MMTK_trilinear_thresh_grid import TrilinearThreshGridTerm return [TrilinearThreshGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'], self.params['energy_thresh'])] elif self.params['inv_power'] is not None: if self.params['inv_power'] == 4: from MMTK_trilinear_one_fourth_grid import TrilinearOneFourthGridTerm return [TrilinearOneFourthGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'])] else: from MMTK_trilinear_transform_grid import TrilinearTransformGridTerm return [TrilinearTransformGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, self.params['name'], self.params['inv_power'])] else: from MMTK_trilinear_grid import TrilinearGridTerm return [TrilinearGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'])] elif self.params['interpolation_type'] == 'BSpline': if self.params['inv_power'] is not None: from MMTK_BSpline_transform_grid import BSplineTransformGridTerm return [BSplineTransformGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'], self.params['inv_power'])] else: from MMTK_BSpline_grid import BSplineGridTerm return [BSplineGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'])] elif self.params['interpolation_type'] == 'CatmullRom': if self.params['inv_power'] is not None: from MMTK_CatmullRom_transform_grid import CatmullRomTransformGridTerm return [CatmullRomTransformGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'], self.params['inv_power'])] else: from MMTK_CatmullRom_grid import CatmullRomGridTerm return [CatmullRomGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'])] elif self.params['interpolation_type'] == 'Tricubic': if self.params['inv_power'] is not None: from MMTK_Tricubic_transform_grid import TricubicTransformGridTerm return [TricubicTransformGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'], self.params['inv_power'])] else: from MMTK_Tricubic_grid import TricubicGridTerm return [TricubicGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'])] print self.params['interpolation_type'] + ' interpolation is unknown' raise NotImplementedError
def evaluatorTerms(self, universe, subset1, subset2, global_data): # The energy for subsets is defined as consisting only # of interactions within that subset, so the contribution # of an external field is zero. Therefore we just return # an empty list of energy terms. if subset1 is not None or subset2 is not None: return [] # Collect the scaling_factor into an array scaling_factor = ParticleScalar(universe) for o in universe: for a in o.atomList(): scaling_factor[a] = o.getAtomProperty(a, self.params['scaling_property']) scaling_factor.scaleBy(self.params['scaling_prefactor']) # Here we pass all the parameters to # the energy term code that handles energy calculations. if self.params['interpolation_type']=='Trilinear': if self.params['energy_thresh']>0: if self.params['inv_power'] is not None: raise NotImplementedError else: from MMTK_trilinear_thresh_grid import TrilinearThreshGridTerm return [TrilinearThreshGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'], self.params['energy_thresh'])] elif self.params['inv_power'] is not None: if self.params['inv_power']==4: # import time # import os.path # import MMTK_trilinear_one_fourth_grid # trilinear_grid_path = MMTK_trilinear_one_fourth_grid.__file__ # print """ # in {0} # last modified {1} # """.format(trilinear_grid_path, \ # time.ctime(os.path.getmtime(trilinear_grid_path))) from MMTK_trilinear_one_fourth_grid import TrilinearOneFourthGridTerm return [TrilinearOneFourthGridTerm(universe._spec, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], \ scaling_factor.array, \ self.params['name'])] else: from MMTK_trilinear_transform_grid import TrilinearTransformGridTerm return [TrilinearTransformGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, self.params['name'], self.params['inv_power'])] else: # print "self.params['name']", self.params['name'] if self.use_C: # import time # import os.path # import MMTK_trilinear_grid # trilinear_grid_path = MMTK_trilinear_grid.__file__ # print """ # in {0} # last modified {1} # """.format(trilinear_grid_path, \ # time.ctime(os.path.getmtime(trilinear_grid_path))) from MMTK_trilinear_grid import TrilinearGridTerm return [TrilinearGridTerm(universe._spec, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], \ scaling_factor.array, \ self.params['name'])] else: # This is for debugging from MMTK_trilinear_grid_cython import TrilinearGridTerm as TrilinearGridTerm_cython return [TrilinearGridTerm_cython(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], \ scaling_factor, \ self.params['name'])] elif self.params['interpolation_type']=='BSpline': if self.params['inv_power'] is not None: from MMTK_BSpline_transform_grid import BSplineTransformGridTerm return [BSplineTransformGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'], self.params['inv_power'])] else: from MMTK_BSpline_grid import BSplineGridTerm return [BSplineGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'])] elif self.params['interpolation_type']=='CatmullRom': if self.params['inv_power'] is not None: from MMTK_CatmullRom_transform_grid import CatmullRomTransformGridTerm return [CatmullRomTransformGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'], self.params['inv_power'])] else: from MMTK_CatmullRom_grid import CatmullRomGridTerm return [CatmullRomGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'])] elif self.params['interpolation_type']=='Tricubic': if self.params['inv_power'] is not None: from MMTK_Tricubic_transform_grid import TricubicTransformGridTerm return [TricubicTransformGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'], self.params['inv_power'])] else: from MMTK_Tricubic_grid import TricubicGridTerm return [TricubicGridTerm(universe, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.params['strength'], scaling_factor, \ self.params['name'])] print self.params['interpolation_type'] + ' interpolation is unknown' raise NotImplementedError
def evaluatorTerms(self, universe, subset1, subset2, global_data): # The energy for subsets is defined as consisting only # of interactions within that subset, so the contribution # of an external field is zero. Therefore we just return # an empty list of energy terms. if subset1 is not None or subset2 is not None: return [] import numpy as np if (self.prmtopFN is not None) and \ (self.inv_prmtop_atom_order is not None): # Get charges, radii, and scale factors from OpenMM import simtk.openmm import simtk.openmm.app as OpenMM_app prmtop = OpenMM_app.AmberPrmtopFile(self.prmtopFN) OMM_system = prmtop.createSystem(\ nonbondedMethod=OpenMM_app.CutoffNonPeriodic, \ nonbondedCutoff=1.5, \ constraints=None, \ implicitSolvent=OpenMM_app.OBC2) f = OMM_system.getForces()[-2] numParticles = f.getNumParticles() charges = np.zeros(numParticles) atomicRadii = np.zeros(numParticles) scaleFactors = np.zeros(numParticles) for n in range(numParticles): (charge, radius, scaleFactor) = f.getParticleParameters(n) charges[n] = charge / simtk.unit.elementary_charge atomicRadii[n] = radius / simtk.unit.nanometer scaleFactors[n] = scaleFactor charges = charges[self.inv_prmtop_atom_order] atomicRadii = atomicRadii[self.inv_prmtop_atom_order] scaleFactors = scaleFactors[self.inv_prmtop_atom_order] else: # Get charges, radii, and scale factors from the ligand database (preferred) charges_ps = ParticleScalar(universe) atomicRadii_ps = ParticleScalar(universe) scaleFactors_ps = ParticleScalar(universe) for o in universe: for a in o.atomList(): charges_ps[a] = o.getAtomProperty(a, 'amber_charge') atomicRadii_ps[a] = o.getAtomProperty( a, 'scaling_factor_BornRadii') scaleFactors_ps[a] = o.getAtomProperty( a, 'scaling_factor_BornScreening') charges = charges_ps.array atomicRadii = atomicRadii_ps.array scaleFactors = scaleFactors_ps.array numParticles = charges.shape[0] # import time # import os.path # import MMTK_OBC # OBCpath = MMTK_OBC.__file__ # print """ # in {0} # last modified {1} # """.format(OBCpath, time.ctime(os.path.getmtime(OBCpath))) # Here we pass all the parameters as "simple" data types to # the C code that handles energy calculations. if self.useDesolvationGrid: # With desolvation grid from MMTK_OBC_desolv import OBCDesolvTerm return [OBCDesolvTerm(universe._spec, numParticles, self.strength, \ charges, atomicRadii, scaleFactors, \ self.grid_data['spacing'], self.grid_data['counts'], \ self.grid_data['vals'], self.r_min, self.r_max)] else: # No desolvation grid from MMTK_OBC import OBCTerm return [OBCTerm(universe._spec, numParticles, self.strength, \ charges, atomicRadii, scaleFactors)]