Commit 0746deda authored by Jason Swails's avatar Jason Swails
Browse files

Add support for triclinic boxes to the Amber and CHARMM file parsers.

parent 10be282a
...@@ -39,6 +39,7 @@ import forcefield as ff ...@@ -39,6 +39,7 @@ import forcefield as ff
import element as elem import element as elem
import simtk.unit as unit import simtk.unit as unit
import simtk.openmm as mm import simtk.openmm as mm
from simtk.openmm.app.internal.unitcell import computePeriodicBoxVectors
# Enumerated values for implicit solvent model # Enumerated values for implicit solvent model
...@@ -141,7 +142,8 @@ class AmberPrmtopFile(object): ...@@ -141,7 +142,8 @@ class AmberPrmtopFile(object):
# Set the periodic box size. # Set the periodic box size.
if prmtop.getIfBox(): if prmtop.getIfBox():
top.setUnitCellDimensions(tuple(x.value_in_unit(unit.nanometer) for x in prmtop.getBoxBetaAndDimensions()[1:4])*unit.nanometer) box = prmtop.getBoxBetaAndDimensions()
top.setPeriodicBoxVectors(computePeriodicBoxVectors(*(box[1:4] + box[0:1]*3)))
def createSystem(self, nonbondedMethod=ff.NoCutoff, nonbondedCutoff=1.0*unit.nanometer, def createSystem(self, nonbondedMethod=ff.NoCutoff, nonbondedCutoff=1.0*unit.nanometer,
constraints=None, rigidWater=True, implicitSolvent=None, constraints=None, rigidWater=True, implicitSolvent=None,
......
...@@ -52,6 +52,7 @@ except: ...@@ -52,6 +52,7 @@ except:
import simtk.unit as units import simtk.unit as units
import simtk.openmm import simtk.openmm
from simtk.openmm.app import element as elem from simtk.openmm.app import element as elem
from simtk.openmm.app.internal.unitcell import computePeriodicBoxVectors
from simtk.openmm.vec3 import Vec3 from simtk.openmm.vec3 import Vec3
import customgbforces as customgb import customgbforces as customgb
...@@ -691,7 +692,6 @@ def readAmberSystem(prmtop_filename=None, prmtop_loader=None, shake=None, gbmode ...@@ -691,7 +692,6 @@ def readAmberSystem(prmtop_filename=None, prmtop_loader=None, shake=None, gbmode
>>> system = readAmberSystem(prmtop_filename) >>> system = readAmberSystem(prmtop_filename)
""" """
if prmtop_filename is None and prmtop_loader is None: if prmtop_filename is None and prmtop_loader is None:
raise Exception("Must specify a filename or loader") raise Exception("Must specify a filename or loader")
if prmtop_filename is not None and prmtop_loader is not None: if prmtop_filename is not None and prmtop_loader is not None:
......
...@@ -32,7 +32,7 @@ __author__ = "Peter Eastman" ...@@ -32,7 +32,7 @@ __author__ = "Peter Eastman"
__version__ = "1.0" __version__ = "1.0"
from simtk.openmm import Vec3 from simtk.openmm import Vec3
from simtk.unit import nanometers, is_quantity, norm, dot from simtk.unit import nanometers, is_quantity, norm, dot, radians
import math import math
...@@ -43,12 +43,12 @@ def computePeriodicBoxVectors(a_length, b_length, c_length, alpha, beta, gamma): ...@@ -43,12 +43,12 @@ def computePeriodicBoxVectors(a_length, b_length, c_length, alpha, beta, gamma):
instances) instances)
""" """
if u.is_quantity(a_length): a_length = a_length.value_in_unit(u.nanometers) if is_quantity(a_length): a_length = a_length.value_in_unit(nanometers)
if u.is_quantity(b_length): a_length = a_length.value_in_unit(u.nanometers) if is_quantity(b_length): b_length = b_length.value_in_unit(nanometers)
if u.is_quantity(c_length): a_length = a_length.value_in_unit(u.nanometers) if is_quantity(c_length): c_length = c_length.value_in_unit(nanometers)
if u.is_quantity(alpha): alpha = alpha.value_in_unit(u.radians) if is_quantity(alpha): alpha = alpha.value_in_unit(radians)
if u.is_quantity(beta): beta = beta.value_in_unit(u.radians) if is_quantity(beta): beta = beta.value_in_unit(radians)
if u.is_quantity(gamma): gamma = gamma.value_in_unit(u.radians) if is_quantity(gamma): gamma = gamma.value_in_unit(radians)
# Compute the vectors. # Compute the vectors.
...@@ -84,8 +84,10 @@ def computeLengthsAndAngles(periodicBoxVectors): ...@@ -84,8 +84,10 @@ def computeLengthsAndAngles(periodicBoxVectors):
Lengths are returned in nanometers and angles in radians. Lengths are returned in nanometers and angles in radians.
""" """
if is_quantity(periodicBoxVectors):
(a, b, c) = vectors.value_in_unit(nanometers) (a, b, c) = vectors.value_in_unit(nanometers)
else:
a, b, c = vectors
a_length = norm(a) a_length = norm(a)
b_length = norm(b) b_length = norm(b)
c_length = norm(c) c_length = norm(c)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment