"vscode:/vscode.git/clone" did not exist on "3e36fd7e32f0b474f41572e012ac7816a4422384"
Commit d4abeb91 authored by Jason Swails's avatar Jason Swails
Browse files

Fix the handling and units of box lengths (they are not independent from

boxVectors, so they should be a property computed from the vectors). Also make
sure that any attempts to change the boxVectors correspondingly deletes the
cached copies of the box lengths so they are recomputed if necessary.
parent c79b07cf
...@@ -755,6 +755,12 @@ class CharmmPsfFile(object): ...@@ -755,6 +755,12 @@ class CharmmPsfFile(object):
- alpha, beta, gamma (floats, optional) : Angles between the - alpha, beta, gamma (floats, optional) : Angles between the
periodic cells. periodic cells.
""" """
try:
# Since we are setting the box, delete the cached box lengths if we
# have them to make sure they are recomputed if desired.
del self._boxLengths
except AttributeError:
pass
self.box_vectors = _box_vectors_from_lengths_angles(a, b, c, self.box_vectors = _box_vectors_from_lengths_angles(a, b, c,
alpha, beta, gamma) alpha, beta, gamma)
# If we already have a _topology instance, then we have possibly changed # If we already have a _topology instance, then we have possibly changed
...@@ -1422,9 +1428,30 @@ class CharmmPsfFile(object): ...@@ -1422,9 +1428,30 @@ class CharmmPsfFile(object):
@property @property
def boxLengths(self): def boxLengths(self):
""" Return tuple of 3 units """ """ Return tuple of 3 units """
try:
# See if we have a cached version
return self._boxLengths
except AttributeError:
pass
if self.box_vectors is not None: if self.box_vectors is not None:
return (self.box_vectors[0][0], self.box_vectors[0][1], # Get the lengths of each vector
self.box_vectors[0][2]) if u.is_quantity(self.box_vectors):
# Unlikely -- each vector is like a quantity
vecs = self.box_vectors.value_in_unit(u.nanometers)
elif u.is_quantity(self.box_vectors[0]):
# Assume all box vectors are quantities
vecs = [x.value_in_unit(u.nanometers) for x in self.box_vectors]
else:
# Assume nanometers
vecs = self.box_vectors
a = sqrt(vecs[0][0]*vecs[0][0] + vecs[0][1]*vecs[0][1] +
vecs[0][2]*vecs[0][2])
b = sqrt(vecs[1][0]*vecs[1][0] + vecs[1][1]*vecs[1][1] +
vecs[1][2]*vecs[1][2])
c = sqrt(vecs[2][0]*vecs[2][0] + vecs[2][1]*vecs[2][1] +
vecs[2][2]*vecs[2][2])
self._boxLengths = (a, b, c) * u.nanometers
return self._boxLengths
return None return None
@boxLengths.setter @boxLengths.setter
...@@ -1440,6 +1467,12 @@ class CharmmPsfFile(object): ...@@ -1440,6 +1467,12 @@ class CharmmPsfFile(object):
@boxVectors.setter @boxVectors.setter
def boxVectors(self, stuff): def boxVectors(self, stuff):
""" Sets the box vectors """ """ Sets the box vectors """
try:
# We may be changing the box, so delete the cached box lengths to
# make sure they are recomputed if desired
del self._boxLengths
except AttributeError:
pass
self.box_vectors = stuff self.box_vectors = stuff
def deleteCmap(self): def deleteCmap(self):
......
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