Commit a52c30a5 authored by peastman's avatar peastman
Browse files

Replace nonstandard atom and residue names when loading PSF files

parent fc7382ad
......@@ -8,7 +8,7 @@ Structures at Stanford, funded under the NIH Roadmap for Medical Research,
grant U54 GM072970. See https://simtk.org. This code was originally part of
the ParmEd program and was ported for use with OpenMM.
Copyright (c) 2014-2016 the Authors
Copyright (c) 2014-2020 the Authors
Author: Jason M. Swails
Contributors: Jing Huang
......@@ -41,7 +41,7 @@ import sys
import simtk.openmm as mm
from simtk.openmm.vec3 import Vec3
import simtk.unit as u
from simtk.openmm.app import (forcefield as ff, Topology, element)
from simtk.openmm.app import (forcefield as ff, Topology, element, PDBFile)
from simtk.openmm.app.amberprmtopfile import HCT, OBC1, OBC2, GBn, GBn2
from simtk.openmm.app.internal.customgbforces import (GBSAHCTForce,
GBSAOBC1Force, GBSAOBC2Force, GBSAGBnForce, GBSAGBn2Force)
......@@ -219,6 +219,7 @@ class CharmmPsfFile(object):
atom_list = AtomList()
if IsDrudePSF:
drudeconsts_list = TrackedList()
PDBFile._loadNameReplacementTables()
for i in xrange(natom):
words = psfsections['NATOM'][1][i].split()
system = words[1]
......@@ -239,6 +240,12 @@ class CharmmPsfFile(object):
charge = conv(words[6], float, 'partial charge')
mass = conv(words[7], float, 'atomic mass')
props = words[8:]
if resname in PDBFile._residueNameReplacements:
resname = PDBFile._residueNameReplacements[resname]
if resname in PDBFile._atomNameReplacements:
atomReplacements = PDBFile._atomNameReplacements[resname]
if name in atomReplacements:
name = atomReplacements[name]
atom = residue_list.add_atom(system, resid, resname, name,
attype, charge, mass, inscode, props)
atom_list.append(atom)
......
......@@ -284,7 +284,7 @@ class TestCharmmFiles(unittest.TestCase):
+ ["H{}".format(i) for i in range(1,12)]
+ ["N{}".format(i) for i in range(1,4)]
)
tip3 = ["OH2", "H1", "H2"]
hoh = ["O", "H1", "H2"]
pot = ["POT"]
cla = ["CLA"]
psf = CharmmPsfFile('systems/charmm-solvated/isa_wat.3_kcl.m14.psf')
......@@ -292,8 +292,8 @@ class TestCharmmFiles(unittest.TestCase):
atoms = [atom.name for atom in residue.atoms()]
if residue.name == "M14":
self.assertEqual(sorted(m14), sorted(atoms))
elif residue.name == "TIP3":
self.assertEqual(sorted(tip3), sorted(atoms))
elif residue.name == "HOH":
self.assertEqual(sorted(hoh), sorted(atoms))
elif residue.name == "POT":
self.assertEqual(sorted(pot), sorted(atoms))
elif residue.name == "CLA":
......
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