"openmmapi/src/GayBerneForceImpl.cpp" did not exist on "27a2456b0fa62eb3df0c3dedbcd3af9ff86a1ec8"
Commit d8545b79 authored by Peter Eastman's avatar Peter Eastman
Browse files

PDBFile loads all frames in the file. Also fixed a bug.

parent 04fe2449
...@@ -176,7 +176,7 @@ class GromacsGroFile(object): ...@@ -176,7 +176,7 @@ class GromacsGroFile(object):
if self._numpyPositions is None: if self._numpyPositions is None:
self._numpyPositions = [None]*len(self._positions) self._numpyPositions = [None]*len(self._positions)
if self._numpyPositions[frame] is None: if self._numpyPositions[frame] is None:
self._numpyPositions[frame] = numpy.array(self._positions[frame].value_in_unit(nanometers))*nanometers self._numpyPositions[frame] = Quantity(numpy.array(self._positions[frame].value_in_unit(nanometers)), nanometers)
return self._numpyPositions[frame] return self._numpyPositions[frame]
return self._positions[frame] return self._positions[frame]
......
...@@ -65,13 +65,12 @@ class PDBFile(object): ...@@ -65,13 +65,12 @@ class PDBFile(object):
- file (string) the name of the file to load - file (string) the name of the file to load
""" """
top = Topology() top = Topology()
coords = [];
## The Topology read from the PDB file ## The Topology read from the PDB file
self.topology = top self.topology = top
# Load the PDB file # Load the PDB file
pdb = PdbStructure(open(file)) pdb = PdbStructure(open(file), load_all_models=True)
PDBFile._loadNameReplacementTables() PDBFile._loadNameReplacementTables()
# Build the topology # Build the topology
...@@ -119,10 +118,15 @@ class PDBFile(object): ...@@ -119,10 +118,15 @@ class PDBFile(object):
pass pass
newAtom = top.addAtom(atomName, element, r) newAtom = top.addAtom(atomName, element, r)
atomByNumber[atom.serial_number] = newAtom atomByNumber[atom.serial_number] = newAtom
self._positions = []
for model in pdb.iter_models(True):
coords = []
for atom in model.iter_atoms():
pos = atom.get_position().value_in_unit(nanometers) pos = atom.get_position().value_in_unit(nanometers)
coords.append(Vec3(pos[0], pos[1], pos[2])) coords.append(Vec3(pos[0], pos[1], pos[2]))
## The atom positions read from the PDB file self._positions.append(coords*nanometers)
self.positions = coords*nanometers ## The atom positions read from the PDB file. If the file contains multiple frames, these are the positions in the first frame.
self.positions = self._positions[0]
self.topology.setUnitCellDimensions(pdb.get_unit_cell_dimensions()) self.topology.setUnitCellDimensions(pdb.get_unit_cell_dimensions())
self.topology.createStandardBonds() self.topology.createStandardBonds()
self.topology.createDisulfideBonds(self.positions) self.topology.createDisulfideBonds(self.positions)
...@@ -147,17 +151,24 @@ class PDBFile(object): ...@@ -147,17 +151,24 @@ class PDBFile(object):
"""Get the Topology of the model.""" """Get the Topology of the model."""
return self.topology return self.topology
def getPositions(self, asNumpy=False): def getNumFrames(self):
"""Get the number of frames stored in the file."""
return len(self._positions)
def getPositions(self, asNumpy=False, frame=0):
"""Get the atomic positions. """Get the atomic positions.
Parameters: Parameters:
- asNumpy (boolean=False) if true, the values are returned as a numpy array instead of a list of Vec3s - asNumpy (boolean=False) if true, the values are returned as a numpy array instead of a list of Vec3s
- frame (int=0) the index of the frame for which to get positions
""" """
if asNumpy: if asNumpy:
if self._numpyPositions is None: if self._numpyPositions is None:
self._numpyPositions = numpy.array(self.positions.value_in_unit(nanometers))*nanometers self._numpyPositions = [None]*len(self._positions)
return self._numpyPositions if self._numpyPositions[frame] is None:
return self.positions self._numpyPositions[frame] = Quantity(numpy.array(self._positions[frame].value_in_unit(nanometers)), nanometers)
return self._numpyPositions[frame]
return self._positions[frame]
@staticmethod @staticmethod
def _loadNameReplacementTables(): def _loadNameReplacementTables():
......
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