Commit 5782cb5c authored by peastman's avatar peastman Committed by GitHub
Browse files

Merge pull request #1548 from peastman/gromacs

Bug fixes to reading Gromacs files
parents 1f7866ad da8a47dd
...@@ -6,7 +6,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of ...@@ -6,7 +6,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of
Biological Structures at Stanford, funded under the NIH Roadmap for Biological Structures at Stanford, funded under the NIH Roadmap for
Medical Research, grant U54 GM072970. See https://simtk.org. Medical Research, grant U54 GM072970. See https://simtk.org.
Portions copyright (c) 2012-2015 Stanford University and the Authors. Portions copyright (c) 2012-2016 Stanford University and the Authors.
Authors: Lee-Ping Wang, Peter Eastman Authors: Lee-Ping Wang, Peter Eastman
Contributors: Contributors:
...@@ -35,6 +35,7 @@ __version__ = "1.0" ...@@ -35,6 +35,7 @@ __version__ = "1.0"
import os import os
import sys import sys
from simtk.openmm import Vec3 from simtk.openmm import Vec3
from simtk.openmm.app.internal.unitcell import reducePeriodicBoxVectors
from re import sub, match from re import sub, match
from simtk.unit import nanometers, angstroms, Quantity from simtk.unit import nanometers, angstroms, Quantity
from . import element as elem from . import element as elem
...@@ -100,7 +101,7 @@ def _construct_box_vectors(line): ...@@ -100,7 +101,7 @@ def _construct_box_vectors(line):
values = [float(i) for i in sline] values = [float(i) for i in sline]
if len(sline) == 3: if len(sline) == 3:
return (Vec3(values[0], 0, 0), Vec3(0, values[1], 0), Vec3(0, 0, values[2]))*nanometers return (Vec3(values[0], 0, 0), Vec3(0, values[1], 0), Vec3(0, 0, values[2]))*nanometers
return (Vec3(values[0], values[3], values[4]), Vec3(values[5], values[1], values[6]), Vec3(values[7], values[8], values[2]))*nanometers return reducePeriodicBoxVectors((Vec3(values[0], values[3], values[4]), Vec3(values[5], values[1], values[6]), Vec3(values[7], values[8], values[2]))*nanometers)
class GromacsGroFile(object): class GromacsGroFile(object):
"""GromacsGroFile parses a Gromacs .gro file and constructs a set of atom positions from it. """GromacsGroFile parses a Gromacs .gro file and constructs a set of atom positions from it.
......
...@@ -364,7 +364,7 @@ class GromacsTopFile(object): ...@@ -364,7 +364,7 @@ class GromacsTopFile(object):
# Bonded type and atomic number are both missing. # Bonded type and atomic number are both missing.
fields.insert(1, None) fields.insert(1, None)
fields.insert(1, None) fields.insert(1, None)
elif len(fields[4]) == 1 and len(fields[5]) > 1: elif len(fields[4]) == 1 and fields[4].isalpha():
if fields[1][0].isalpha(): if fields[1][0].isalpha():
# Atomic number is missing. # Atomic number is missing.
fields.insert(2, None) fields.insert(2, None)
...@@ -586,9 +586,9 @@ class GromacsTopFile(object): ...@@ -586,9 +586,9 @@ class GromacsTopFile(object):
# Create the System. # Create the System.
sys = mm.System() sys = mm.System()
boxSize = self.topology.getUnitCellDimensions() boxVectors = self.topology.getPeriodicBoxVectors()
if boxSize is not None: if boxVectors is not None:
sys.setDefaultPeriodicBoxVectors((boxSize[0], 0, 0), (0, boxSize[1], 0), (0, 0, boxSize[2])) sys.setDefaultPeriodicBoxVectors(*boxVectors)
elif nonbondedMethod in (ff.CutoffPeriodic, ff.Ewald, ff.PME): elif nonbondedMethod in (ff.CutoffPeriodic, ff.Ewald, ff.PME):
raise ValueError('Illegal nonbonded method for a non-periodic system') raise ValueError('Illegal nonbonded method for a non-periodic system')
nb = mm.NonbondedForce() nb = mm.NonbondedForce()
......
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