Unverified Commit 2ff59259 authored by peastman's avatar peastman Committed by GitHub
Browse files

Merge pull request #2357 from peastman/psfbox

Improved API for setting periodic box vectors in CharmmPsfFile
parents 37d4b472 202be04d
......@@ -166,7 +166,7 @@ class CharmmPsfFile(object):
GB_FORCE_GROUP = 6
@_catchindexerror
def __init__(self, psf_name):
def __init__(self, psf_name, periodicBoxVectors=None, unitCellDimensions=None):
"""Opens and parses a PSF file, then instantiates a CharmmPsfFile
instance from the data.
......@@ -174,6 +174,11 @@ class CharmmPsfFile(object):
----------
psf_name : str
Name of the PSF file (it must exist)
periodicBoxVectors : tuple of Vec3
the vectors defining the periodic box
unitCellDimensions : Vec3
the dimensions of the crystallographic unit cell. For
non-rectangular unit cells, specify periodicBoxVectors instead.
Raises
------
......@@ -449,7 +454,14 @@ class CharmmPsfFile(object):
self.group_list = group_list
self.title = title
self.flags = psf_flags
self.box_vectors = None
if unitCellDimensions is not None:
if periodicBoxVectors is not None:
raise ValueError("specify either periodicBoxVectors or unitCellDimensions, but not both")
if u.is_quantity(unitCellDimensions):
unitCellDimensions = unitCellDimensions.value_in_unit(u.nanometers)
self.box_vectors = (Vec3(unitCellDimensions[0], 0, 0), Vec3(0, unitCellDimensions[1], 0), Vec3(0, 0, unitCellDimensions[2]))*u.nanometers
else:
self.box_vectors = periodicBoxVectors
@staticmethod
def _convert(string, type, message):
......
......@@ -93,12 +93,10 @@ class TestCharmmFiles(unittest.TestCase):
def test_NBFIX(self):
"""Tests CHARMM systems with NBFIX Lennard-Jones modifications"""
warnings.filterwarnings('ignore', category=CharmmPSFWarning)
psf = CharmmPsfFile('systems/ala3_solv.psf')
psf = CharmmPsfFile('systems/ala3_solv.psf', unitCellDimensions=Vec3(32.7119500, 32.9959600, 33.0071500)*angstroms)
crd = CharmmCrdFile('systems/ala3_solv.crd')
params = CharmmParameterSet('systems/par_all36_prot.prm',
'systems/toppar_water_ions.str')
# Box dimensions (found from bounding box)
psf.setBox(32.7119500*angstroms, 32.9959600*angstroms, 33.0071500*angstroms)
# Turn off charges so we only test the Lennard-Jones energies
for a in psf.atom_list:
......@@ -169,12 +167,11 @@ class TestCharmmFiles(unittest.TestCase):
def testSystemOptions(self):
""" Test various options in CharmmPsfFile.createSystem """
warnings.filterwarnings('ignore', category=CharmmPSFWarning)
psf = CharmmPsfFile('systems/ala3_solv.psf')
psf = CharmmPsfFile('systems/ala3_solv.psf',
periodicBoxVectors=(Vec3(32.7119500, 0, 0)*angstroms, Vec3(0, 32.9959600, 0)*angstroms, Vec3(0, 0, 33.0071500)*angstroms))
crd = CharmmCrdFile('systems/ala3_solv.crd')
params = CharmmParameterSet('systems/par_all36_prot.prm',
'systems/toppar_water_ions.str')
# Box dimensions (found from bounding box)
psf.setBox(32.7119500*angstroms, 32.9959600*angstroms, 33.0071500*angstroms)
# Check some illegal options
self.assertRaises(ValueError, lambda:
......
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