forked from shirtsgroup/InterMol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adjusted ignorecase behavior for .git/config
- Loading branch information
Showing
371 changed files
with
3,468,359 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
""" | ||
... module:: Atom | ||
:platform: Unix | ||
.. moduleuthor:: Christoph Klein <[email protected]>, Christopher | ||
Lee <[email protected]> | ||
""" | ||
import intermol.unit as units | ||
from converter import convert_units | ||
|
||
|
||
class Atom(object): | ||
__slots__ = ['index', 'name', 'residue_index', 'residue_name', | ||
'_position', '_velocity', '_force', '_atomtype', 'bondtype', 'Z', | ||
'cgnr', '_mass', '_charge', 'ptype', '_sigma', '_epsilon'] | ||
def __init__(self, index, name=None, residue_index=-1, residue_name=None): | ||
"""Create an Atom object | ||
Args: | ||
index (int): index of atom in the molecule | ||
name (str): name of the atom (eg., N, C, H, O) | ||
residue_index (int): index of residue in the molecule | ||
residue_name (str): name of the residue (eg., THR, CYS) | ||
""" | ||
self.index = index | ||
self.name = name | ||
self.residue_index = residue_index | ||
self.residue_name = residue_name | ||
self._position = [0 * units.nanometers, | ||
0 * units.nanometers, | ||
0 * units.nanometers] | ||
self._velocity = [0 * units.nanometers / units.picosecond, | ||
0 * units.nanometers / units.picosecond, | ||
0 * units.nanometers / units.picosecond] | ||
self._force = [0 * units.kilojoules_per_mole / units.nanometers, | ||
0 * units.kilojoules_per_mole / units.nanometers, | ||
0 * units.kilojoules_per_mole / units.nanometers] | ||
|
||
# These are added after data is read in and come from [ atomtypes ] | ||
self._atomtype = dict() | ||
self.bondtype = None | ||
self.Z = None | ||
self.cgnr = None | ||
self._mass = dict() | ||
self._charge = dict() | ||
self.ptype = "A" | ||
self._sigma = dict() | ||
self._epsilon = dict() | ||
|
||
def getAtomType(self, index=None): | ||
"""Gets the atomtype | ||
Args: | ||
index (str): the value corresponding with type precedence (A Type, B Type) | ||
Returns: | ||
atomtype (list, str): Returns the atomtype list or the value at | ||
index if index is specified | ||
""" | ||
if index: | ||
return self._atomtype[index] | ||
return self._atomtype | ||
|
||
def setAtomType(self, index, atomtype): | ||
"""Sets the atomtype | ||
Args: | ||
atomtype (str): the atomtype of the atom | ||
index (str): the value corresponding with type precedence (A Type, B Type) | ||
""" | ||
self._atomtype[index] = atomtype | ||
|
||
|
||
|
||
def setSigma(self, index, sigma): | ||
"""Sets the sigma | ||
Args: | ||
sigma (float): sigma of the atom | ||
index (int): index to insert at | ||
""" | ||
self._sigma[index] = sigma | ||
|
||
def getSigma(self, index=None): | ||
""" | ||
""" | ||
if index: | ||
return self._sigma[index] | ||
return self._sigma | ||
|
||
def setEpsilon(self, index, epsilon): | ||
"""Sets the epsilon | ||
Args: | ||
epsilon (float): epsilon of the atom | ||
index(int): index corresponding to epsilon | ||
""" | ||
self._epsilon[index] = epsilon | ||
|
||
def getEpsilon(self, index=None): | ||
""" | ||
""" | ||
if index: | ||
return self._epsilon[index] | ||
return self._epsilon | ||
|
||
def setCgnr(self, index, cgnr): | ||
"""Sets the Cgnr | ||
Args: | ||
cgnr (int): The charge group number | ||
index (int): the value corresponding with cgnr precedence | ||
""" | ||
self._cgnr[index] = cgnr | ||
|
||
def getCgnr(self, index=None): | ||
"""Gets the Cgnr | ||
Args: | ||
index (int): the index to retrieve, defaults to None | ||
Returns: | ||
cngr (dict, int): returns the index or the dictionary depending | ||
on if index is set | ||
""" | ||
if index: | ||
return self._cgnr[index] | ||
return self._cgnr | ||
|
||
|
||
def setPosition(self, x, y, z): | ||
"""Sets the position of the atom | ||
Args: | ||
x (float): x position | ||
y (float): y position | ||
z (float): z position | ||
""" | ||
unit = units.nanometers | ||
x = convert_units(x, unit) | ||
y = convert_units(y, unit) | ||
z = convert_units(z, unit) | ||
self._position = [x, y, z] | ||
|
||
def getPosition(self): | ||
"""Gets the position for the atom | ||
Returns: | ||
Tuple [x, y, z] | ||
""" | ||
return self._position | ||
|
||
def setVelocity(self, vx, vy, vz): | ||
"""Sets the velocity of the atom | ||
Args: | ||
vx (float): x velocity | ||
vy (float): y velocity | ||
vz (float): z velocity | ||
""" | ||
unit = units.nanometers / units.picoseconds | ||
vx = convert_units(vx, unit) | ||
vy = convert_units(vy, unit) | ||
vz = convert_units(vz, unit) | ||
self._velocity = [vx, vy, vz] | ||
|
||
def getVelocity(self): | ||
"""Gets the velocity of the atom | ||
Returns: | ||
Tuple [vx, vy, vz] | ||
""" | ||
return self._velocity | ||
|
||
def setForce(self, fx, fy, fz): | ||
"""Sets the force of the atom | ||
Args: | ||
fx (float): x force | ||
fy (float): y force | ||
fz (float): z force | ||
""" | ||
unit = units.kilojoules_per_mole * units.nanometers**(-1) | ||
fx = convert_units(fx, unit) | ||
fy = convert_units(fy, unit) | ||
fz = convert_units(fz, unit) | ||
self._force = [fx, fy, fz] | ||
|
||
def getForce(self): | ||
"""Gets the force of the atom | ||
Returns: | ||
Tuple [fx, fy, fz] | ||
""" | ||
return self._force | ||
|
||
def setMass(self, index, mass): | ||
"""Sets the mass of the atom | ||
Args: | ||
mass (float): mass of the atom | ||
index (str): the index corresponding with mass precedence (A Mass, B Mass) | ||
""" | ||
unit = units.amu | ||
self._mass[index] = convert_units(mass, unit) | ||
|
||
def getMass(self, index=None): | ||
"""Gets the mass of the atom | ||
Returns: | ||
mass (float): mass of the atom | ||
index (str): index to retrieve | ||
""" | ||
if index: | ||
return self._mass[index] | ||
return self._mass | ||
|
||
def setCharge(self, index, charge): | ||
"""Sets the charge of the atom | ||
Args: | ||
charge (float): Charge of the atom | ||
index (int): the index corresponding with charge precedence | ||
""" | ||
unit = units.elementary_charge | ||
self._charge[index] = convert_units(charge, unit) | ||
|
||
def getCharge(self, index=None): | ||
"""Gets the charge of the atom | ||
Args: | ||
index (int): index of the charge to retrieve defaults to None | ||
Returns: | ||
charge (float): Charge of the atom | ||
""" | ||
if index: | ||
return self._charge[index] | ||
return self._charge | ||
|
||
def __repr__(self): | ||
return 'Atom({0}, {1})'.format(self.index, self.name) | ||
|
||
def __cmp__(self, other): | ||
return self.index - other.index | ||
|
||
def __eq__(self, other): | ||
return self.index == other.index | ||
|
||
def __hash__(self): | ||
return hash(self.index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import intermol.unit as units | ||
|
||
def convert_units(arg, unit): | ||
"""Checks compatibility and converts units using simtk.units package | ||
Args: | ||
arg (Quantity): quantity to be converted | ||
unit (Unit): Unit to be converted to | ||
Returns: | ||
arg (Quantity): Quantity scaled to the new unit | ||
""" | ||
conversionFactor = (arg.unit).conversion_factor_to(unit) | ||
arg = arg * conversionFactor | ||
return arg._value * unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import intermol.unit as units | ||
|
||
#============================================================================= | ||
# EXCEPTIONS | ||
#============================================================================= | ||
|
||
|
||
class UnitsException(Exception): | ||
"""Exception denoting that an argument has the incorrect units.""" | ||
def __init__(self, value): | ||
self.value = value | ||
|
||
def __str__(self): | ||
return repr(self.value) | ||
|
||
|
||
class ValueException(Exception): | ||
"""Exception denoting that an argument has the incorrect value.""" | ||
def __init__(self, value): | ||
self.value = value | ||
|
||
def __str__(self): | ||
return repr(self.value) | ||
|
||
#============================================================================= | ||
# DECORATOR | ||
#============================================================================= | ||
|
||
|
||
#TODO: Do we need to use 'from functools import wraps' to help us here? | ||
def accepts(*types): | ||
""" | ||
Decorator for class methods that should accept only specified types. | ||
EXAMPLE | ||
@accepts(float, int) | ||
def function(a, b): | ||
return b*a | ||
""" | ||
def check_accepts(f): | ||
nargs = (f.func_code.co_argcount - 1) # exclude self | ||
assert len(types) == nargs, ("Incorrect number of args supplied in " | ||
"@accepts decorator for class method %s" % (f.func_name)) | ||
|
||
def new_f(*args, **kwds): | ||
for (a, t) in zip(args[1:], types): | ||
if a is not None: | ||
assert isinstance(a, t), "arg %r does not match %s" % (a, t) | ||
return f(*args, **kwds) | ||
|
||
new_f.func_name = f.func_name # copy function name | ||
new_f.func_doc = f.func_doc # copy docstring | ||
return new_f | ||
|
||
return check_accepts | ||
|
||
|
||
def accepts_compatible_units(*units): | ||
""" | ||
Decorator for class methods that should accept only arguments compatible with specified units. | ||
Each argument of the function will be matched with an argument of @acceptunits. | ||
Those arguments of the function that correspond @acceptunits which are not None | ||
will be checked to ensure they are compatible with the specified units. | ||
EXAMPLE | ||
@acceptsunits(units.meter, None, units.kilocalories_per_mole) | ||
def function(a, b, c): pass | ||
function(1.0 * units.angstrom, 3, 1.0 * units.kilojoules_per_mole) | ||
""" | ||
def check_units(f): | ||
nargs = (f.func_code.co_argcount - 1) # exclude self | ||
assert len(units) == nargs, "incorrect number of units supplied in @accepts_compatible_units decorator for class method %s" % (f.func_name) | ||
def new_f(*args, **kwds): | ||
for (a, u) in zip(args[1:], units): | ||
if u is not None: | ||
assert (a.unit).is_compatible(u), "arg %r does not have units compatible with %s" % (a,u) | ||
return f(*args, **kwds) | ||
new_f.func_name = f.func_name # copy function name | ||
new_f.func_doc = f.func_doc # copy docstring | ||
return new_f | ||
return check_units | ||
|
||
def returns(rtype): | ||
""" | ||
Decorator for functions that should only return specific types. | ||
EXAMPLE | ||
@returns(int) | ||
def function(): return 7 | ||
""" | ||
|
||
def check_returns(f): | ||
def new_f(*args, **kwds): | ||
result = f(*args, **kwds) | ||
assert isinstance(result, rtype), "return value %r does not match %s" % (result,rtype) | ||
return result | ||
new_f.func_name = f.func_name # copy function name | ||
new_f.func_doc = f.func_doc # copy docstring | ||
return new_f | ||
return check_returns |
Oops, something went wrong.