pyPot
index


PyPot: base class used by potential terms written in Python.
 
to write a potential term in Python, define a class which derives from
pyPot.PyPot, and make sure to call the base class' constructor.
Then, the new class should define two methods: 
calcEnergy, and calcEnergyAndDerivList(derivList). The constructor is
PyPot(self,name,defaultSimulation=None). If simulation is omitted, it
defaults to simulation.currentSimulation().
 
Note that the derivList argument contains the sum of gradients up to
the position of the current term in a potList, so this should be
added to, and not cleared, or wholesale scaled in any user-defined
energy term. The derivList argument is indexed by atom, as seen below.
Alternatively, a method named calcEnergyAndDerivs(indexDerivList) can be
defined, where the indexing is instead done via atom index in the PyPot's
simulation. 
 
Here is a simple example of a potential term for a single bond:
 
from pyPot import PyPot ; from vec3 import norm, Vec3
class BondPot(PyPot):
    ''' example class to evaluate energy, derivs of a single bond
    '''
    def __init__(self,name,atom1,atom2,length,forcec=1):
        ''' constructor - force constant is optional.'''
        PyPot.__init__(self,name) #first call base class constructor
        self.a1 = atom1     ; self.a2     = atom2
        self.length = length; self.forcec = forcec
        return
    def calcEnergy(self):
        self.q1 = self.a1.pos() ; self.q2 = self.a2.pos()
        self.dist = norm(self.q1-self.q2)
        return 0.5 * self.scale() * self.forcec * (self.dist-self.length)**2
    def calcEnergyAndDerivList(self,derivs):
        energy = self.calcEnergy()
        deriv1 = Vec3(map(lambda x,y:x*y,
                       [self.forcec * (self.dist-self.length) / self.dist]*3 ,
                         ( self.q1[0]-self.q2[0], 
                           self.q1[1]-self.q2[1], 
                           self.q1[2]-self.q2[2] )))
        derivs[self.a1] += self.scale() * deriv1
        derivs[self.a2] -= self.scale() * deriv1
        return energy
    pass
 
# The term can be instantiated like:
p = BondPot('bond',AtomSel('resid 1 and name C')[0],
                   AtomSel('resid 1 and name O')[0], length=1.5)
 
 
 
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 4.0.2
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.

 
Classes
       
builtins.object
Modified
ModifiedBase
PyPot
PyPot_LetterClass

 
class Modified(builtins.object)
    Modified(*args, **kwargs)
 

 
  Methods defined here:
__call__(self, *args, **kwargs) -> 'int'
Call self as a function.
__init__(self, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.
__repr__ = _swig_repr(self)
asString(self, *args, **kwargs) -> 'String'
clear(self, *args, **kwargs) -> 'void'
set(self, *args, **kwargs) -> 'void'
update(self, *args, **kwargs) -> 'void'
value(self, *args, **kwargs) -> 'int'

Static methods defined here:
__swig_destroy__ = delete_Modified(...)

Data descriptors defined here:
__dict__

 
dictionary for instance variables (if defined)
__weakref__

 
list of weak references to the object (if defined)
thisown

 
The membership flag

Data and other attributes defined here:
MOD_SELF = 1
MOD_SIMULATION = 2

 
class ModifiedBase(builtins.object)
    ModifiedBase(*args, **kwargs)
 

 
  Methods defined here:
__init__(self, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.
__repr__ = _swig_repr(self)
registerTo(self, *args, **kwargs) -> 'void'
unRegister(self, *args, **kwargs) -> 'void'
updateValues(self, *args, **kwargs) -> 'void'

Static methods defined here:
__swig_destroy__ = delete_ModifiedBase(...)

Data descriptors defined here:
__dict__

 
dictionary for instance variables (if defined)
__weakref__

 
list of weak references to the object (if defined)
modified

 
registeredSimulations

 
thisown

 
The membership flag

 
class PyPot(builtins.object)
    PyPot(*args, **kwargs)
 

 
  Methods defined here:
__deref__(self, *args, **kwargs) -> 'PyPot *'
__init__ = construct(self, *args, **kwargs)
__oldinit__ = __init__(self, *args, **kwargs)
__ref__(self, *args, **kwargs) -> 'PyPot &'
__repr__ = _swig_repr(self)
calcEnergy(self, *args, **kwargs) -> 'float_type'
calcEnergyAndDerivs(self, *args, **kwargs) -> 'float_type'
decrRefCnt(self, *args, **kwargs) -> 'void'
incrRefCnt(self, *args, **kwargs) -> 'void'
instanceData(self, *args, **kwargs) -> 'PyObject *'
instanceName(self, *args, **kwargs) -> 'char const *'
numRestraints(self, *args, **kwargs) -> 'int'
potName(self, *args, **kwargs) -> 'char const *'
pyXplorHelp(self, *args, **kwargs) -> 'String'
pythonPot(self, *args, **kwargs) -> 'PyObject *'
refCnt(self, *args, **kwargs) -> 'int'
registerInstanceData(self, *args, **kwargs) -> 'void'
registerTo(self, *args, **kwargs) -> 'void'
resetInstanceName(self, *args, **kwargs) -> 'void'
resetPotName(self, *args, **kwargs) -> 'void'
rms(self, *args, **kwargs) -> 'float_type'
scale(self, *args, **kwargs) -> 'float_type const'
setScale(self, *args, **kwargs) -> 'void'
setThreshold(self, *args, **kwargs) -> 'void'
threshold(self, *args, **kwargs) -> 'float_type const'
unRegister(self, *args, **kwargs) -> 'void'
updateDelta(self, *args, **kwargs) -> 'void'
updateValues(self, *args, **kwargs) -> 'void'
violations(self, *args, **kwargs) -> 'float_type'

Static methods defined here:
__swig_destroy__ = delete_PyPot(...)

Data descriptors defined here:
__dict__

 
dictionary for instance variables (if defined)
__weakref__

 
list of weak references to the object (if defined)
instanceDataCleanup

 
instanceDataCreate

 
instanceData_

 
modified

 
registeredSimulations

 
thisown

 
The membership flag

 
class PyPot_LetterClass(builtins.object)
    PyPot_LetterClass(*args, **kwargs)
 

 
  Methods defined here:
__init__(self, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.
__repr__ = _swig_repr(self)
numRestraints(self, *args, **kwargs) -> 'int'
pyXplorHelp(self, *args, **kwargs) -> 'String'
pythonPot(self, *args, **kwargs) -> 'PyObject *'
rms(self, *args, **kwargs) -> 'float_type'
violations(self, *args, **kwargs) -> 'float_type'

Static methods defined here:
__swig_destroy__ = delete_PyPot_LetterClass(...)

Data descriptors defined here:
__dict__

 
dictionary for instance variables (if defined)
__weakref__

 
list of weak references to the object (if defined)
thisown

 
The membership flag

 
realPyPot = class PyPot(builtins.object)
    realPyPot(*args, **kwargs)
 

 
  Methods defined here:
__deref__(self, *args, **kwargs) -> 'PyPot *'
__init__ = construct(self, *args, **kwargs)
__oldinit__ = __init__(self, *args, **kwargs)
__ref__(self, *args, **kwargs) -> 'PyPot &'
__repr__ = _swig_repr(self)
calcEnergy(self, *args, **kwargs) -> 'float_type'
calcEnergyAndDerivs(self, *args, **kwargs) -> 'float_type'
decrRefCnt(self, *args, **kwargs) -> 'void'
incrRefCnt(self, *args, **kwargs) -> 'void'
instanceData(self, *args, **kwargs) -> 'PyObject *'
instanceName(self, *args, **kwargs) -> 'char const *'
numRestraints(self, *args, **kwargs) -> 'int'
potName(self, *args, **kwargs) -> 'char const *'
pyXplorHelp(self, *args, **kwargs) -> 'String'
pythonPot(self, *args, **kwargs) -> 'PyObject *'
refCnt(self, *args, **kwargs) -> 'int'
registerInstanceData(self, *args, **kwargs) -> 'void'
registerTo(self, *args, **kwargs) -> 'void'
resetInstanceName(self, *args, **kwargs) -> 'void'
resetPotName(self, *args, **kwargs) -> 'void'
rms(self, *args, **kwargs) -> 'float_type'
scale(self, *args, **kwargs) -> 'float_type const'
setScale(self, *args, **kwargs) -> 'void'
setThreshold(self, *args, **kwargs) -> 'void'
threshold(self, *args, **kwargs) -> 'float_type const'
unRegister(self, *args, **kwargs) -> 'void'
updateDelta(self, *args, **kwargs) -> 'void'
updateValues(self, *args, **kwargs) -> 'void'
violations(self, *args, **kwargs) -> 'float_type'

Static methods defined here:
__swig_destroy__ = delete_PyPot(...)

Data descriptors defined here:
__dict__

 
dictionary for instance variables (if defined)
__weakref__

 
list of weak references to the object (if defined)
instanceDataCleanup

 
instanceDataCreate

 
instanceData_

 
modified

 
registeredSimulations

 
thisown

 
The membership flag

 
Functions
       
construct(self, *args, **kwargs)
fromPy(*args, **kwargs) -> 'void'
oldConstructor = __init__(self, *args)
pyXplorHelp(*args) -> 'String'