Пример #1
0
 def _extensive_checks(self, parm):
     # Check the __contains__ methods of the various topologyobjects
     atoms = parm.atoms
     for bond in parm.bonds:
         self.assertEqual(sum([a in bond for a in atoms]), 2)
     for angle in parm.angles:
         self.assertEqual(sum([a in angle for a in atoms]), 3)
         self.assertEqual(sum([b in angle for b in parm.bonds]), 2)
     for dihedral in parm.dihedrals:
         self.assertEqual(sum([a in dihedral for a in atoms]), 4)
         self.assertEqual(sum([b in dihedral for b in parm.bonds]), 3)
     for residue in parm.residues:
         self.assertTrue(all([a in residue for a in residue.atoms]))
         self.assertEqual(sum([a in residue for a in atoms]), len(residue))
     if not parm.chamber: return
     # Chamber tests now
     for ub in parm.urey_bradleys:
         self.assertEqual(sum([a in ub for a in atoms]), 2)
         self.assertEqual(sum([b in ub for b in parm.bonds]), 2)
     for imp in parm.impropers:
         self.assertEqual(sum([a in imp for a in atoms]), 4)
         self.assertEqual(sum([b in imp for b in parm.bonds]), 3)
     if parm.has_cmap:
         for cmap in parm.cmaps:
             self.assertEqual(sum([a in cmap for a in atoms]), 5)
             self.assertEqual(sum([b in cmap for b in parm.bonds]), 4)
Пример #2
0
 def _extensive_checks(self, parm):
     # Check the __contains__ methods of the various topologyobjects
     atoms = parm.atoms
     for bond in parm.bonds:
         self.assertEqual(sum([a in bond for a in atoms]), 2)
     for angle in parm.angles:
         self.assertEqual(sum([a in angle for a in atoms]), 3)
         self.assertEqual(sum([b in angle for b in parm.bonds]), 2)
     for dihedral in parm.dihedrals:
         self.assertEqual(sum([a in dihedral for a in atoms]), 4)
         self.assertEqual(sum([b in dihedral for b in parm.bonds]), 3)
     for residue in parm.residues:
         self.assertTrue(all([a in residue for a in residue.atoms]))
         self.assertEqual(sum([a in residue for a in atoms]),
                          len(residue))
     if not parm.chamber: return
     # Chamber tests now
     for ub in parm.urey_bradleys:
         self.assertEqual(sum([a in ub for a in atoms]), 2)
         self.assertEqual(sum([b in ub for b in parm.bonds]), 2)
     for imp in parm.impropers:
         self.assertEqual(sum([a in imp for a in atoms]), 4)
         self.assertEqual(sum([b in imp for b in parm.bonds]), 3)
     if parm.has_cmap:
         for cmap in parm.cmaps:
             self.assertEqual(sum([a in cmap for a in atoms]), 5)
             self.assertEqual(sum([b in cmap for b in parm.bonds]), 4)
Пример #3
0
 def __init__(self, fname):
     self.natom = 0
     # Create the list of atoms
     self.atom_list = XyzFile._AtomList()
     f = open(fname, 'r')
     for line in f:
         if self.natom == 0:
             self.natom = int(line.strip())
             # Set up blank positions and connections arrays
             self.connections = [[] for i in xrange(self.natom)]
             continue
         words = line.split()
         if len(words) == 6 and all([is_float(x) for x in words]):
             # The first line after the number of atoms _could_ be the box
             # information. So capture that here and store the info
             self.box = [float(x) for x in words]
             continue
         self.atom_list.add(words[1], words[2], words[3],
                            words[4], words[5], words[6:])
     f.close()
Пример #4
0
 def testCharmmPsf(self):
     """ Test CHARMM PSF file parsing """
     cpsf = psf.CharmmPsfFile(get_fn('ala_ala_ala.psf'))
     self.assertEqual(len(cpsf.atoms), 33)
     for i, atom in enumerate(cpsf.atoms):
         self.assertEqual(atom.idx, i)
         self.assertEqual(atom.residue.name, 'ALA')
         self.assertTrue(atom in atom.residue)  # tests __contains__
     # Check the bond, angle, and torsion partners of the first N atom
     a = cpsf.atoms[0]
     for atom in a.bond_partners:
         self.assertTrue(atom.name in ['HT3', 'HT2', 'CA', 'HT1'])
         self.assertEqual(atom.residue.idx, 0)
         self.assertTrue(atom.type in [2, 22])
     for atom in a.angle_partners:
         self.assertTrue(atom.name in ['HA', 'CB', 'C'])
         self.assertTrue(atom.type in [6, 24, 20])
         self.assertEqual(atom.residue.idx, 0)
     for atom in a.dihedral_partners:
         self.assertTrue(atom.name in ['HB1', 'HB2', 'HB3', 'O', 'N'])
         if atom.name == 'N':
             self.assertEqual(atom.residue.idx, 1)
         else:
             self.assertEqual(atom.residue.idx, 0)
         self.assertTrue(atom.type in [3, 70, 54])
     # Check some atom properties
     self.assertRaises(exceptions.MissingParameter,
                       lambda: str(a.atom_type))
     self.assertTrue(all([isinstance(b, to.Bond) for b in a.bonds]))
     self.assertTrue(all([isinstance(an, to.Angle) for an in a.angles]))
     self.assertTrue(all([isinstance(d, to.Dihedral) for d in a.dihedrals]))
     self.assertEqual(len(a.angle_partners), 3)
     self.assertEqual(len(a.angles), 9)
     self.assertEqual(len(a.bond_partners), 4)
     self.assertEqual(len(a.bonds), 4)
     self.assertEqual(len(a.cmaps), 0)
     self.assertEqual(len(a.dihedral_partners), 5)
     self.assertEqual(len(a.dihedrals), 14)
     self.assertEqual(len(a.impropers), 0)
     self.assertEqual(len(a.name), 1)
     self.assertEqual(len(a.props), 3)
     self.assertEqual(len(a.residue), 12)
     self.assertEqual(len(a.segid), 3)
     self.assertEqual(len(a.urey_bradleys), 0)
     # Check attributes of the psf file
     self.assertEqual(len(cpsf.acceptors), 4)
     self.assertEqual(len(cpsf.angles), 57)
     self.assertEqual(len(cpsf.atoms), 33)
     self.assertEqual(len(cpsf.bonds), 32)
     self.assertEqual(len(cpsf.cmaps), 1)
     self.assertEqual(len(cpsf.dihedrals), 74)
     self.assertEqual(len(cpsf.donors), 5)
     self.assertEqual(len(cpsf.flags), 2)
     self.assertEqual(len(cpsf.groups), 9)
     self.assertEqual(len(cpsf.impropers), 5)
     self.assertEqual(len(cpsf.residues), 3)
     self.assertEqual(len(cpsf.title), 2)
     # Check the __contains__ methods of valence terms (make sure the correct
     # number of atoms are in each valence term)
     atoms = cpsf.atoms
     bonds = cpsf.bonds
     for bond in cpsf.bonds:
         self.assertEqual(sum([int(a in bond) for a in atoms]), 2)
     # Other valence terms can also contain bonds
     for i, angle in enumerate(cpsf.angles):
         self.assertEqual(sum([int(a in angle) for a in atoms]), 3)
         self.assertEqual(sum([int(b in angle) for b in bonds]), 2)
     for dih in cpsf.dihedrals:
         self.assertEqual(sum([int(a in dih) for a in atoms]), 4)
         self.assertEqual(sum([int(b in dih) for b in bonds]), 3)
     for imp in cpsf.impropers:
         self.assertEqual(sum([int(a in imp) for a in atoms]), 4)
         self.assertEqual(sum([int(b in imp) for b in bonds]), 3)
     for cmap in cpsf.cmaps:
         self.assertEqual(sum([int(a in cmap) for a in atoms]), 5)
         self.assertEqual(sum([int(b in cmap) for b in bonds]), 4)
Пример #5
0
 def testCharmmPsf(self):
     """ Test CHARMM PSF file parsing """
     cpsf = psf.CharmmPsfFile(get_fn('ala_ala_ala.psf'))
     self.assertEqual(len(cpsf.atoms), 33)
     for i, atom in enumerate(cpsf.atoms):
         self.assertEqual(atom.idx, i)
         self.assertEqual(atom.residue.name, 'ALA')
         self.assertTrue(atom in atom.residue) # tests __contains__
     # Check the bond, angle, and torsion partners of the first N atom
     a = cpsf.atoms[0]
     for atom in a.bond_partners:
         self.assertTrue(atom.name in ['HT3', 'HT2', 'CA', 'HT1'])
         self.assertEqual(atom.residue.idx, 0)
         self.assertTrue(atom.type in [2, 22])
     for atom in a.angle_partners:
         self.assertTrue(atom.name in ['HA', 'CB', 'C'])
         self.assertTrue(atom.type in [6, 24, 20])
         self.assertEqual(atom.residue.idx, 0)
     for atom in a.dihedral_partners:
         self.assertTrue(atom.name in ['HB1', 'HB2', 'HB3', 'O', 'N'])
         if atom.name == 'N':
             self.assertEqual(atom.residue.idx, 1)
         else:
             self.assertEqual(atom.residue.idx, 0)
         self.assertTrue(atom.type in [3, 70, 54])
     # Check some atom properties
     self.assertRaises(exceptions.MissingParameter, lambda: str(a.atom_type))
     self.assertTrue(all([isinstance(b, to.Bond) for b in a.bonds]))
     self.assertTrue(all([isinstance(an, to.Angle) for an in a.angles]))
     self.assertTrue(all([isinstance(d, to.Dihedral) for d in a.dihedrals]))
     self.assertEqual(len(a.angle_partners), 3)
     self.assertEqual(len(a.angles), 9)
     self.assertEqual(len(a.bond_partners), 4)
     self.assertEqual(len(a.bonds), 4)
     self.assertEqual(len(a.cmaps), 0)
     self.assertEqual(len(a.dihedral_partners), 5)
     self.assertEqual(len(a.dihedrals), 14)
     self.assertEqual(len(a.impropers), 0)
     self.assertEqual(len(a.name), 1)
     self.assertEqual(len(a.props), 3)
     self.assertEqual(len(a.residue), 12)
     self.assertEqual(len(a.segid), 3)
     self.assertEqual(len(a.urey_bradleys), 0)
     # Check attributes of the psf file
     self.assertEqual(len(cpsf.acceptors), 4)
     self.assertEqual(len(cpsf.angles), 57)
     self.assertEqual(len(cpsf.atoms), 33)
     self.assertEqual(len(cpsf.bonds), 32)
     self.assertEqual(len(cpsf.cmaps), 1)
     self.assertEqual(len(cpsf.dihedrals), 74)
     self.assertEqual(len(cpsf.donors), 5)
     self.assertEqual(len(cpsf.flags), 2)
     self.assertEqual(len(cpsf.groups), 9)
     self.assertEqual(len(cpsf.impropers), 5)
     self.assertEqual(len(cpsf.residues), 3)
     self.assertEqual(len(cpsf.title), 2)
     # Check the __contains__ methods of valence terms (make sure the correct
     # number of atoms are in each valence term)
     atoms = cpsf.atoms
     bonds = cpsf.bonds
     for bond in cpsf.bonds:
         self.assertEqual(sum([int(a in bond) for a in atoms]), 2)
     # Other valence terms can also contain bonds
     for i, angle in enumerate(cpsf.angles):
         self.assertEqual(sum([int(a in angle) for a in atoms]), 3)
         self.assertEqual(sum([int(b in angle) for b in bonds]), 2)
     for dih in cpsf.dihedrals:
         self.assertEqual(sum([int(a in dih) for a in atoms]), 4)
         self.assertEqual(sum([int(b in dih) for b in bonds]), 3)
     for imp in cpsf.impropers:
         self.assertEqual(sum([int(a in imp) for a in atoms]), 4)
         self.assertEqual(sum([int(b in imp) for b in bonds]), 3)
     for cmap in cpsf.cmaps:
         self.assertEqual(sum([int(a in cmap) for a in atoms]), 5)
         self.assertEqual(sum([int(b in cmap) for b in bonds]), 4)