def testPdbWriteXtal(self): """ Test PDB file writing from a Xtal structure """ pdbfile = read_PDB(self.pdb) self._check4lzt(pdbfile) output = StringIO() pdbfile.write_pdb(output, renumber=False) output.seek(0) pdbfile2 = read_PDB(output) self._check4lzt(pdbfile2, check_meta=False) self._compareInputOutputPDBs(pdbfile, pdbfile2) output = reset_stringio(output) write_PDB(pdbfile, output) output.seek(0) pdbfile3 = read_PDB(output) self._check4lzt(pdbfile3, check_meta=False) self._compareInputOutputPDBs(pdbfile, pdbfile3, True) # Now check that renumbering is done correctly. 4lzt skips residues 130 # through 200 for res1, res2 in zip(pdbfile.residues, pdbfile3.residues): if res1.idx < 129: self.assertEqual(res1.number, res2.number) elif res1.idx < 135: self.assertEqual(res1.number, res2.number + 71) else: # Some residue numbers are skipped in the water numbering self.assertGreaterEqual(res1.number, res2.number + 71 + 794)
def testMol2FileWithNoTypeNames(self): """ Tests writing a Mol2 without types uses names instead """ struct = read_PDB(get_fn('2koc.pdb')) output = StringIO() formats.Mol2File.write(struct, output) output.seek(0) mol2 = formats.Mol2File.parse(output, structure=True)
def testCopyingDefaults(self): """ Tests that copying GromacsTopologyFile copies Defaults too """ parm = load_file(get_fn('159.top')) newfile = StringIO() copy.copy(parm).write(newfile) newfile.seek(0) newparm = GromacsTopologyFile(newfile) self.assertEqual(parm.defaults, newparm.defaults)
def testGetitemDefaults(self): """ Tests that GromacsTopologyFile[] sets Defaults correctly """ parm = load_file(get_fn('159.top')) newfile = StringIO() parm[0,:].write(newfile) newfile.seek(0) newparm = GromacsTopologyFile(newfile) self.assertEqual(parm.defaults, newparm.defaults)
def test_ifndef(self): """ Tests CPreProcessor #ifndef/#else#endif preprocessing """ f = StringIO('#ifndef MY_DEFINE\nMY_DEFINE is not set\n' '#else\nPPVAR is set to MY_DEFINE\n#endif\n') pp = CPreProcessor(f) # no defines self.assertEqual(pp.read().strip(), 'MY_DEFINE is not set') f.seek(0) pp = CPreProcessor(f, defines=dict(MY_DEFINE='SUCCESS')) self.assertEqual(pp.read().strip(), 'PPVAR is set to SUCCESS')
def test_missing_include(self): """ Tests CPreProcessor controllable behavior of missing #includes """ warnings.filterwarnings('error', category=PreProcessorWarning) f = StringIO("#include \"nofile.h\"\n") pp = CPreProcessor(f) self.assertRaises(PreProcessorError, lambda: pp.read()) f.seek(0) pp = CPreProcessor(f, notfound_fatal=False) self.assertRaises(PreProcessorWarning, lambda: pp.read())
def test_pp_regex(self): """ Tests CPreProcessor processing with whitespace """ f = StringIO("# define MY_DEFINE Something\nMY_DEFINE") self.assertEqual(CPreProcessor(f).read().strip(), "Something") f = StringIO("# ifdef MY_VAR \nMY_VAR\n#endif\n" "#\t\tdefine MY_VAR NoSpaces \n" "# ifdef MY_VAR \nMY_VAR\n#endif") f.seek(0) self.assertEqual(CPreProcessor(f).read().strip(), 'NoSpaces')
def test_not_implemented(self): """ Test error catching for PP features not implemented """ f = StringIO('#define MYVAR 1\n#if (MYVAR == 1)\nCORRECT\n#endif') pp = CPreProcessor(f) self.assertRaises(NotImplementedError, lambda: pp.seek(10)) self.assertRaises(NotImplementedError, pp.read) f = StringIO( '#ifdef MYVAR\n#elif defined(NOTMYVAR)\n#else\nline\#endif') pp = CPreProcessor(f) self.assertRaises(NotImplementedError, pp.read)
def test_bad_ifdef(self): """ Tests CPreProcessor error processing of bad #ifdef/#ifndef """ f = StringIO("#ifdef\n#endif") with CPreProcessor(f) as pp: self.assertRaises(PreProcessorError, pp.read) f = StringIO("#ifndef\n#endif") with CPreProcessor(f) as pp: self.assertRaises(PreProcessorError, pp.read) f = StringIO("#ifdef SOME_VAR\ndangling ifdef\n\n\n") with CPreProcessor(f) as pp: self.assertRaises(PreProcessorError, pp.read) warnings.filterwarnings('error', category=PreProcessorWarning) f = StringIO("#ifdef SOME_VAR misplaced comments\n#endif\n") with CPreProcessor(f) as pp: self.assertRaises(PreProcessorWarning, pp.read) f = StringIO("#ifdef SOME_VAR\n#endif misplaced comments\n") with CPreProcessor(f) as pp: self.assertRaises(PreProcessorWarning, pp.read) f = StringIO('#else\nNOVAR\n#endif') with CPreProcessor(f) as pp: self.assertRaises(PreProcessorError, pp.read) f = StringIO('#ifdef MYVAR\nline1\n#else extra tokens\nline2\n#endif') with CPreProcessor(f) as pp: self.assertRaises(PreProcessorWarning, pp.read) f = StringIO('#ifdef MYVAR\nline1\n#else\nline2\n#else\nline3\n#endif') with CPreProcessor(f) as pp: self.assertRaises(PreProcessorError, pp.read) f = StringIO('#endif\nline1\nline2') with CPreProcessor(f) as pp: self.assertRaises(PreProcessorError, pp.read)
def test_conservative_defines(self): """ Tests CPreProcessor #define token replacement """ # Check that it does not replace tokens inside quotes f = StringIO("'MY_VAR' is MY_VAR\n\"MY_VAR\" is MY_VAR still\n") pp = CPreProcessor(f, defines=dict(MY_VAR='set')) self.assertEqual(pp.read().strip(), "'MY_VAR' is set\n\"MY_VAR\" is set still") f = StringIO("This is NOT_MY_VAR, but 'MY_VAR' is MY_VAR\n") pp = CPreProcessor(f, defines=dict(MY_VAR='taken')) self.assertEqual(pp.read().strip(), "This is NOT_MY_VAR, but 'MY_VAR' is taken")
def testCIFModels(self): """ Test CIF parsing/writing NMR structure with 20 models (2koc) """ cif = download_CIF('2koc') self.assertEqual(cif.get_coordinates('all').shape, (20, 451, 3)) self.assertEqual(len(cif.atoms), 451) output = StringIO() write_CIF(cif, output) output.seek(0) pdbfile2 = read_CIF(output) self.assertEqual(len(pdbfile2.atoms), 451) self.assertEqual(pdbfile2.get_coordinates('all').shape, (20, 451, 3))
def testPdbWriteModels(self): """ Test PDB file writing from NMR structure with models """ pdbfile = read_PDB(self.models) self.assertEqual(pdbfile.get_coordinates('all').shape, (20, 451, 3)) self.assertEqual(len(pdbfile.atoms), 451) output = StringIO() write_PDB(pdbfile, output) output.seek(0) pdbfile2 = read_PDB(output) self.assertEqual(len(pdbfile2.atoms), 451) self.assertEqual(pdbfile2.get_coordinates('all').shape, (20, 451, 3)) self._compareInputOutputPDBs(pdbfile, pdbfile2)
def test_bad_define_undef(self): """ Tests CPreProcessor error processing of bad #define/#undef """ f = StringIO("#define\n") pp = CPreProcessor(f) self.assertRaises(PreProcessorError, lambda: pp.read()) f = StringIO("#undef\n") pp = CPreProcessor(f) self.assertRaises(PreProcessorError, lambda: pp.read()) warnings.filterwarnings('error', category=PreProcessorWarning) f = StringIO('#undef VAR1 misplaced comments\n') pp = CPreProcessor(f) self.assertRaises(PreProcessorWarning, lambda: pp.read())
def testPdbWriteSimple(self): """ Test PDB file writing on a very simple input structure """ pdbfile = read_PDB(self.simple) self.assertEqual(len(pdbfile.atoms), 33) self.assertEqual(len(pdbfile.residues), 3) output = StringIO() pdbfile.write_pdb(output) output.seek(0) pdbfile2 = read_PDB(output) self.assertEqual(len(pdbfile2.atoms), 33) self.assertEqual(len(pdbfile2.residues), 3) self._compareInputOutputPDBs(pdbfile, pdbfile2)
def test_undef(self): """ Tests CPreProcessor #undef preprocessing """ # This tests undef-ing both a defined and not-defined variable. f = StringIO("MY_DEFINE\n#define MY_DEFINE Changed\nMY_DEFINE\n" "#undef MY_DEFINE\nMY_DEFINE\n#undef NO_VARIABLE\n") pp = CPreProcessor(f) self.assertEqual(pp.read().strip(), "MY_DEFINE\nChanged\nMY_DEFINE") # Make sure undef does not occur where it shouldn't f = StringIO('#define MYVAR something\n#ifdef NOVAR\n#undef MYVAR\n' '#endif\nMYVAR') with CPreProcessor(f) as pp: self.assertEqual(pp.read().strip(), 'something')
def test_define_inside_ifdef(self): """ Tests CPreProcessor #define inside #ifdef/#ifndef """ f = StringIO("#ifdef MY_DEFINE\n#define MY_DEFINE " "Something\n#endif\nMY_DEFINE") pp = CPreProcessor(f) self.assertEqual(pp.read().strip(), "MY_DEFINE") f = StringIO("#ifdef MY_DEFINE\n# define MY_DEFINE Something\n" "#endif\nMY_DEFINE\n#ifndef MY_DEFINE\n" "# define MY_DEFINE Something special\n#endif\n" "MY_DEFINE") pp = CPreProcessor(f) self.assertEqual(pp.read().strip(), "MY_DEFINE\nSomething special")
def test_not_write_residues_with_same_templhash(self): """Test that no identical residues are written to XML, using the templhasher function.""" # TODO add testing for multiatomic residues when support for those added params = openmm.OpenMMParameterSet.from_parameterset( pmd.amber.AmberParameterSet(get_fn('atomic_ions.lib'))) new_residues = OrderedDict() for name in ('K', 'K+', 'NA', 'Na+', 'CL', 'Cl-'): new_residues[name] = params.residues[name] params.residues = new_residues ffxml = StringIO() params.write(ffxml) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 16)
def test_not_write_residues_with_same_templhash(self): """Test that no identical residues are written to XML, using the templhasher function.""" # TODO add testing for multiatomic residues when support for those added params = openmm.OpenMMParameterSet.from_parameterset( pmd.amber.AmberParameterSet(get_fn('atomic_ions.lib')) ) new_residues = OrderedDict() for name in ('K', 'K+', 'NA', 'Na+', 'CL', 'Cl-'): new_residues[name] = params.residues[name] params.residues = new_residues ffxml = StringIO() params.write(ffxml) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 16)
def test_write_xml_parameters_amber_write_unused(self): """ Test writing XML parameters loaded from part of the ff14SB forcefield files, using the write_unused argument""" params = openmm.OpenMMParameterSet.from_parameterset( pmd.amber.AmberParameterSet( get_fn('amino12.lib'), os.path.join(get_fn('parm'), 'parm10.dat'), os.path.join(get_fn('parm'), 'frcmod.ff14SB'))) ffxml = StringIO() params.write(ffxml) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 2178) ffxml = StringIO() params.write(ffxml, write_unused=False) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 1646)
def testAnisouWrite(self): """ Tests that write_PDB properly writes ANISOU records """ def check_aniso(pdbfile): aniso1 = [2066, 1204, 1269, 44, 126, 191] aniso2 = [2090, 1182, 921, 46, 64, 60] aniso3 = [3057, 3932, 5304, 126, -937, -661] self.assertEqual(len(aniso1), len(pdbfile.atoms[0].anisou)) for x, y in zip(aniso1, pdbfile.atoms[0].anisou): self.assertEqual(x/10000, y) self.assertEqual(len(aniso2), len(pdbfile.atoms[1].anisou)) for x, y in zip(aniso2, pdbfile.atoms[1].anisou): self.assertEqual(x/10000, y) self.assertEqual(len(aniso3), len(pdbfile.atoms[-1].anisou)) for x, y in zip(aniso3, pdbfile.atoms[-1].anisou): self.assertEqual(x/10000, y) pdbfile = read_PDB(self.pdb) check_aniso(pdbfile) output = StringIO() pdbfile.write_pdb(output) output.seek(0) pdbfile2 = read_PDB(output) # Should have no anisou records, since by default they are not written for atom in pdbfile2.atoms: self.assertIs(atom.anisou, None) output = reset_stringio(output) pdbfile.write_pdb(output, renumber=False, write_anisou=True) output.seek(0) # This one should have anisou records pdbfile3 = read_PDB(output) self._compareInputOutputPDBs(pdbfile, pdbfile3) for a1, a2 in zip(pdbfile.atoms, pdbfile3.atoms): if has_numpy(): self.assertEqual(a1.anisou.shape, a2.anisou.shape) else: self.assertEqual(len(a1.anisou), len(a2.anisou)) for x, y in zip(a1.anisou, a2.anisou): self.assertAlmostEqual(x, y, delta=1e-4) self.assertEqual(len(a1.other_locations), len(a2.other_locations)) for key in sorted(a1.other_locations.keys()): oa1 = a1.other_locations[key] oa2 = a2.other_locations[key] if has_numpy(): self.assertEqual(oa1.anisou.shape, oa2.anisou.shape) else: self.assertEqual(len(oa1.anisou), len(oa2.anisou)) for x, y in zip(oa1.anisou, oa2.anisou): self.assertAlmostEqual(x, y, delta=1e-4)
def testPdbWriteAltlocOptions(self): """ Test PDB file writing with different altloc options """ pdbfile = read_PDB(self.pdb) self._check4lzt(pdbfile) output = StringIO() pdbfile.write_pdb(output, renumber=False, altlocs='all') output.seek(0) pdbfile2 = read_PDB(output) self._check4lzt(pdbfile2, check_meta=False) self._compareInputOutputPDBs(pdbfile, pdbfile2) # Check that 'first' option works output = reset_stringio(output) pdbfile.write_pdb(output, renumber=False, altlocs='first') output.seek(0) pdbfile3 = read_PDB(output) self._check4lzt(pdbfile3, check_meta=False, has_altloc=False) self._compareInputOutputPDBs(pdbfile, pdbfile3, altloc_option='first') # Check that the 'occupancy' option works output = reset_stringio(output) write_PDB(pdbfile, output, renumber=False, altlocs='occupancy') output.seek(0) pdbfile4 = read_PDB(output) self._check4lzt(pdbfile4, check_meta=False, has_altloc=False) self._compareInputOutputPDBs(pdbfile, pdbfile4, altloc_option='occupancy') # Double-check 'first' vs. 'occupancy'. Residue 85 (SER) has a conformer # A that has an occupancy of 0.37 and conformer B with occupancy 0.63 self.assertEqual(pdbfile3.residues[84][4].xx, -4.162) self.assertEqual(pdbfile4.residues[84][4].xx, -4.157)
def test_override_level(self): """Test correct support for the override_level attribute of ResidueTemplates and correct writing to XML tag""" params = openmm.OpenMMParameterSet.from_parameterset( pmd.amber.AmberParameterSet(get_fn('atomic_ions.lib'))) new_residues = OrderedDict() new_residues['K'] = params.residues['K'] new_residues['NA'] = params.residues['NA'] new_residues['K'].override_level = 1 params.residues = new_residues ffxml = StringIO() params.write(ffxml) ffxml.seek(0) output_lines = ffxml.readlines() control_line1 = ' <Residue name="K" override="1">\n' control_line2 = ' <Residue name="NA">\n' self.assertEqual(output_lines[5], control_line1) self.assertEqual(output_lines[8], control_line2)
def test_overload_level(self): """Test correct support for the overload_level attribute of ResidueTemplates and correct writing to XML tag""" params = openmm.OpenMMParameterSet.from_parameterset( pmd.amber.AmberParameterSet(get_fn('atomic_ions.lib')) ) new_residues = OrderedDict() new_residues['K'] = params.residues['K'] new_residues['NA'] = params.residues['NA'] new_residues['K'].overload_level = 1 params.residues = new_residues ffxml = StringIO() params.write(ffxml) ffxml.seek(0) output_lines = ffxml.readlines() control_line1 = ' <Residue name="K" overload="1">\n' control_line2 = ' <Residue name="NA">\n' self.assertEqual(output_lines[5], control_line1) self.assertEqual(output_lines[8], control_line2)
def parse(filename): """ Parses XML file and returns deserialized object. The return value depends on the serialized object, summarized below - System : returns simtk.openmm.System - State : returns simtk.openmm.State - Integrator : returns simtk.openmm.Integrator subclass - ForceField : returns simtk.openmm.app.ForceField Parameters ---------- filename : str or file-like The file name or file object containing the XML-serialized object Returns ------- obj : System, State, Integrator, or ForceField The deserialized object Notes ----- OpenMM requires the entire contents of this file read into memory. As a result, this function may require a significant amount of memory. """ if isinstance(filename, string_types): with closing(genopen(filename, 'r')) as f: contents = f.read() else: contents = f.read() # ForceField is not handled by XmlSerializer if '<ForceField' in contents: obj = StringIO() obj.write(contents) obj.seek(0) return app.ForceField(obj) obj = mm.XmlSerializer.deserialize(contents) if isinstance(obj, (mm.System, mm.Integrator)): return obj elif isinstance(obj, mm.State): return _OpenMMStateContents(obj) return
def test_define(self): """ Tests CPreProcessor #define preprocessing """ f = StringIO('#ifdef MY_DEFINE\nPPVAR is set to MY_DEFINE\n' '#else\nMY_DEFINE is not set\n#endif\n' '#define MY_DEFINE SUCCESS\n#ifdef MY_DEFINE\n' 'PPVAR is set to MY_DEFINE\n#else\nMY_DEFINE is not set\n' '#endif\n') pp = CPreProcessor(f) self.assertEqual(pp.read().strip(), 'MY_DEFINE is not set\nPPVAR is set to SUCCESS') warnings.filterwarnings('error', category=PreProcessorWarning) f = StringIO('#define MYVAR something\nMYVAR\n#define MYVAR ' 'something_else\nMYVAR') with CPreProcessor(f) as pp: self.assertRaises(PreProcessorWarning, pp.read) warnings.filterwarnings('ignore', category=PreProcessorWarning) f.seek(0) with CPreProcessor(f) as pp: self.assertEqual(pp.read().strip(), 'something\nsomething_else')
def test_nested_ifs(self): """ Tests CPreProcessor nested #ifdef and #if """ f = StringIO(""" #ifdef MY_VAR line 1 # if 1 line 2 # endif /* 1 */ #else /* ! MY_VAR */ # if 0 line 3 # else /* ! 0 */ line 4 # endif /* 0 */ #endif /* MY_VAR */ """) pp = CPreProcessor(f) self.assertEqual(pp.read().strip(), "line 4") f.seek(0) pp = CPreProcessor(f, defines=dict(MY_VAR=1)) self.assertEqual(pp.read().strip(), "line 1\nline 2")
def test_gromacs_file(self): """ Test GromacsFile helper class """ f = StringIO('This is the first line \\\n this is still the first line' '\nThis is the second line') gf = GromacsFile(f) self.assertEqual(gf.readline(), 'This is the first line this is ' 'still the first line\n') self.assertEqual(gf.readline(), 'This is the second line') self.assertEqual(gf.readline(), '') f.seek(0) lines = [line for line in gf] self.assertEqual(lines[0], 'This is the first line this is ' 'still the first line\n') self.assertEqual(lines[1], 'This is the second line') # Try with comments now f = StringIO('This is the first line \\\n this is still the first line' ' ; and this is a comment\nThis is the second line ; and ' 'this is also a comment') gf = GromacsFile(f) self.assertEqual(gf.readline(), 'This is the first line this is still' ' the first line \n') self.assertEqual(gf.readline(), 'This is the second line \n') f.seek(0) lines = [line for line in gf] self.assertEqual(lines[0], 'This is the first line this is still' ' the first line \n') self.assertEqual(lines[1], 'This is the second line \n') f.seek(0) lines = gf.readlines() self.assertEqual(lines[0], 'This is the first line this is still' ' the first line \n') self.assertEqual(lines[1], 'This is the second line \n') f.seek(0) self.assertEqual(gf.read(), 'This is the first line this is still' ' the first line \nThis is the second line \n') # Error handling self.assertRaises(IOError, lambda: GromacsFile('some_file that does_not exist'))
def testMol2MultiWrite(self): """ Tests writing mol2 file of multi residues from ResidueTemplateContainer """ mol2 = formats.Mol2File.parse(get_fn('test_multi.mol2')) formats.Mol2File.write(mol2, get_fn('test_multi.mol2', written=True)) formats.Mol2File.write(mol2, get_fn('test_multi_sep.mol2', written=True), split=True) self.assertTrue(diff_files(get_saved_fn('test_multi.mol2'), get_fn('test_multi.mol2', written=True))) self.assertTrue(diff_files(get_saved_fn('test_multi_sep.mol2'), get_fn('test_multi_sep.mol2', written=True))) mol22 = formats.Mol2File.parse(get_fn('test_multi_sep.mol2', written=True)) self.assertEqual(len(mol2), len(mol22)) self.assertEqual([r.name for r in mol2], [r.name for r in mol22]) for r1, r2 in zip(mol2, mol22): self.assertEqual(len(r1.bonds), len(r2.bonds)) self.assertEqual(len(r1.atoms), len(r2.atoms)) self.assertFalse(r1.head is None and r1.tail is None) self.assertTrue(r2.head is None and r2.tail is None) f = StringIO() formats.Mol2File.write(mol2, f, mol3=True, split=True) f.seek(0) mol3 = formats.Mol2File.parse(f) self.assertEqual(len(mol2), len(mol3)) self.assertEqual([r.name for r in mol2], [r.name for r in mol3]) for r1, r2 in zip(mol2, mol3): self.assertEqual(len(r1.bonds), len(r2.bonds)) self.assertEqual(len(r1.atoms), len(r2.atoms)) self.assertFalse(r1.head is None and r1.tail is None) self.assertFalse(r2.head is None and r2.tail is None) if r1.head is None: self.assertIs(r2.head, None) else: self.assertEqual(r1.head.name, r2.head.name) if r1.tail is None: self.assertIs(r2.tail, None) else: self.assertEqual(r1.tail.name, r2.tail.name)
def test_include_dir(self): """ Tests CPreProcessor passing include directories to search """ f = StringIO('#include "pptest1.h"') pp = CPreProcessor(f, includes=[get_fn('pptest1')]) self.assertEqual( pp.read().strip(), """\ pptest1 line 1 pptest2 line 1 pptest3 line 1 pptest2 line 2 pptest1 line 2 pptest3 line 1 pptest1 line 3""")
def test_reporters_pbc(self): """ Test NetCDF and ASCII restart and trajectory reporters (w/ PBC) """ systemsolv = load_file(get_fn('ildn.solv.top'), xyz=get_fn('ildn.solv.gro')) system = systemsolv.createSystem(nonbondedMethod=app.PME, nonbondedCutoff=8 * u.angstroms) integrator = mm.LangevinIntegrator(300 * u.kelvin, 5.0 / u.picoseconds, 1.0 * u.femtoseconds) sim = app.Simulation(systemsolv.topology, system, integrator, Reference) sim.context.setPositions(systemsolv.positions) sim.reporters.extend([ NetCDFReporter(get_fn('traj.nc', written=True), 1, vels=True, frcs=True), MdcrdReporter(get_fn('traj.mdcrd', written=True), 1), RestartReporter(get_fn('restart.ncrst', written=True), 1, netcdf=True), RestartReporter(get_fn('restart.rst7', written=True), 1), StateDataReporter(get_fn('state.o', written=True), 1, volume=True, density=True, systemMass=1) ]) sim.step(5) for reporter in sim.reporters: reporter.finalize() ntraj = NetCDFTraj.open_old(get_fn('traj.nc', written=True)) atraj = AmberMdcrd(get_fn('traj.mdcrd', written=True), len(systemsolv.atoms), True, mode='r') nrst = NetCDFRestart.open_old(get_fn('restart.ncrst', written=True)) arst = AmberAsciiRestart(get_fn('restart.rst7', written=True), 'r') self.assertEqual(ntraj.frame, 5) self.assertEqual(atraj.frame, 5) self.assertTrue(ntraj.hasvels) self.assertTrue(ntraj.hasfrcs) for i in range(ntraj.frame): for x1, x2 in zip(ntraj.box[i], atraj.box[i]): self.assertAlmostEqual(x1, x2, places=3) self.assertEqual(len(nrst.box), 6) self.assertEqual(len(arst.box), 6) # Make sure the EnergyMinimizerReporter does not fail f = StringIO() rep = EnergyMinimizerReporter(f, volume=True) rep.report(sim) rep.finalize()
def test_nested_ifs(self): """ Tests CPreProcessor nested #ifdef and #if """ f = StringIO(""" #ifdef MY_VAR line 1 # if 1 line 2 # endif /* 1 */ #else /* ! MY_VAR */ # if 0 line 3 # else /* ! 0 */ line 4 # endif /* 0 */ #endif /* MY_VAR */ """) pp = CPreProcessor(f) self.assertEqual(pp.read().strip(), "line 4") f.seek(0) pp = CPreProcessor(f, defines=dict(MY_VAR=1)) self.assertEqual(pp.read().strip(), "line 1\nline 2") f = StringIO(""" #ifdef MY_VAR # ifndef MY_VAR_2 MY_VAR defined... MY_VAR_2 not # else MY_VAR defined... MY_VAR_2 also # endif #endif """) pp = CPreProcessor(f) self.assertEqual(pp.read().strip(), '') f.seek(0) pp = CPreProcessor(f, defines=dict(MY_VAR=1)) self.assertEqual(pp.read().strip(), '1 defined... MY_VAR_2 not') f.seek(0) pp = CPreProcessor(f, defines=dict(MY_VAR=1, MY_VAR_2=2)) self.assertEqual(pp.read().strip(), '1 defined... 2 also')
def test_write_xml_parameters_gaff(self): """ Test writing XML parameters loaded from Amber GAFF parameter files """ leaprc = StringIO("""\ parm10 = loadamberparams gaff.dat """) params = openmm.OpenMMParameterSet.from_parameterset( pmd.amber.AmberParameterSet.from_leaprc(leaprc)) citations = """\ Wang, J., Wang, W., Kollman P. A.; Case, D. A. "Automatic atom type and bond type perception in molecular mechanical calculations". Journal of Molecular Graphics and Modelling , 25, 2006, 247260. Wang, J., Wolf, R. M.; Caldwell, J. W.;Kollman, P. A.; Case, D. A. "Development and testing of a general AMBER force field". Journal of Computational Chemistry, 25, 2004, 1157-1174. """ params.write(get_fn('gaff.xml', written=True), provenance=dict(OriginalFile='gaff.dat', Reference=citations))
def test_if1_if0(self): """ Tests CPreProcessor use of #if 1 and #if 0 to serve as comments """ f = StringIO('#if 1\n#ifdef MY_DEFINE\nPPVAR is set to MY_DEFINE\n' '#else\nMY_DEFINE is not set\n#endif\n#endif\n') pp = CPreProcessor(f) # no defines self.assertEqual(pp.read().strip(), 'MY_DEFINE is not set') f.seek(0) pp = CPreProcessor(f, defines=dict(MY_DEFINE='SUCCESS')) self.assertEqual(pp.read().strip(), 'PPVAR is set to SUCCESS') f = StringIO('#if 0\n#ifdef MY_DEFINE\nPPVAR is set to MY_DEFINE\n' '#else\nMY_DEFINE is not set\n#endif\n#endif\n') pp = CPreProcessor(f) # no defines self.assertFalse(pp.read().strip()) f.seek(0) pp = CPreProcessor(f, defines=dict(MY_DEFINE='SUCCESS')) self.assertFalse(pp.read().strip())
def test_write_xml_parameters_amber_write_unused(self): """ Test writing XML parameters loaded from part of the ff14SB forcefield files, using the write_unused argument""" params = openmm.OpenMMParameterSet.from_parameterset( pmd.amber.AmberParameterSet( get_fn("amino12.lib"), os.path.join(get_fn("parm"), "parm10.dat"), os.path.join(get_fn("parm"), "frcmod.ff14SB"), ) ) ffxml = StringIO() params.write(ffxml) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 2178) ffxml = StringIO() params.write(ffxml, write_unused=False) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 1646)
def load(rmol): """ Load a :class:`Mol` object and return a populated :class:`Structure` instance Parameters ---------- rmol: :class:`Mol` RDKit :class:`Mol` object to convert Examples -------- >>> from rdkit import Chem >>> import parmed as pmd >>> mol = Chem.MolFromSmiles('Cc1ccccc1') >>> struct = pmd.load_rdkit(mol) """ from rdkit import Chem fh = StringIO(Chem.MolToPDBBlock(rmol)) return PDBFile.parse(fh)
def parse(filename): """ Parses XML file and returns deserialized object. The return value depends on the serialized object, summarized below - System : returns simtk.openmm.System - State : returns simtk.openmm.State - Integrator : returns simtk.openmm.Integrator subclass - ForceField : returns simtk.openmm.app.ForceField Parameters ---------- filename : str or file-like The file name or file object containing the XML-serialized object Returns ------- obj : System, State, Integrator, or ForceField The deserialized object Notes ----- OpenMM requires the entire contents of this file read into memory. As a result, this function may require a significant amount of memory. """ import simtk.openmm as mm from simtk.openmm import app if isinstance(filename, string_types): with closing(genopen(filename, 'r')) as f: contents = f.read() else: contents = filename.read() # ForceField is not handled by XmlSerializer if '<ForceField' in contents: obj = StringIO() obj.write(contents) obj.seek(0) return app.ForceField(obj) obj = mm.XmlSerializer.deserialize(contents) if isinstance(obj, mm.State): return _OpenMMStateContents(obj) return obj
def test_bad_include(self): """ Tests bad #include syntax in CPreProcessor """ f = StringIO('#include bad syntax gremlin\nline 1') with CPreProcessor(f) as pp: self.assertRaises(PreProcessorError, pp.read)
def test_reporters(self): """ Test NetCDF and ASCII restart and trajectory reporters (no PBC) """ self.assertRaises(ValueError, lambda: NetCDFReporter(get_fn('blah', written=True), 1, crds=False)) self.assertRaises(ValueError, lambda: MdcrdReporter(get_fn('blah', written=True), 1, crds=False)) self.assertRaises(ValueError, lambda: MdcrdReporter(get_fn('blah', written=True), 1, crds=True, vels=True)) system = amber_gas.createSystem() integrator = mm.LangevinIntegrator(300*u.kelvin, 5.0/u.picoseconds, 1.0*u.femtoseconds) sim = app.Simulation(amber_gas.topology, system, integrator, platform=CPU) sim.context.setPositions(amber_gas.positions) sim.reporters.extend([ NetCDFReporter(get_fn('traj1.nc', written=True), 10), NetCDFReporter(get_fn('traj2.nc', written=True), 10, vels=True), NetCDFReporter(get_fn('traj3.nc', written=True), 10, frcs=True), NetCDFReporter(get_fn('traj4.nc', written=True), 10, vels=True, frcs=True), NetCDFReporter(get_fn('traj5.nc', written=True), 10, crds=False, vels=True), NetCDFReporter(get_fn('traj6.nc', written=True), 10, crds=False, frcs=True), NetCDFReporter(get_fn('traj7.nc', written=True), 10, crds=False, vels=True, frcs=True), MdcrdReporter(get_fn('traj1.mdcrd', written=True), 10), MdcrdReporter(get_fn('traj2.mdcrd', written=True), 10, crds=False, vels=True), MdcrdReporter(get_fn('traj3.mdcrd', written=True), 10, crds=False, frcs=True), RestartReporter(get_fn('restart.ncrst', written=True), 10, write_multiple=True, netcdf=True), RestartReporter(get_fn('restart.rst7', written=True), 10) ]) sim.step(500) for reporter in sim.reporters: reporter.finalize() self.assertEqual(len(os.listdir(get_fn('writes'))), 61) ntraj = [NetCDFTraj.open_old(get_fn('traj1.nc', written=True)), NetCDFTraj.open_old(get_fn('traj2.nc', written=True)), NetCDFTraj.open_old(get_fn('traj3.nc', written=True)), NetCDFTraj.open_old(get_fn('traj4.nc', written=True)), NetCDFTraj.open_old(get_fn('traj5.nc', written=True)), NetCDFTraj.open_old(get_fn('traj6.nc', written=True)), NetCDFTraj.open_old(get_fn('traj7.nc', written=True))] atraj = [AmberMdcrd(get_fn('traj1.mdcrd', written=True), amber_gas.ptr('natom'), hasbox=False, mode='r'), AmberMdcrd(get_fn('traj2.mdcrd', written=True), amber_gas.ptr('natom'), hasbox=False, mode='r'), AmberMdcrd(get_fn('traj3.mdcrd', written=True), amber_gas.ptr('natom'), hasbox=False, mode='r')] for traj in ntraj: self.assertEqual(traj.frame, 50) self.assertEqual(traj.Conventions, 'AMBER') self.assertEqual(traj.ConventionVersion, '1.0') self.assertEqual(traj.application, 'AmberTools') self.assertEqual(traj.program, 'ParmEd') self.assertFalse(traj.hasbox) self.assertTrue(ntraj[0].hascrds) self.assertFalse(ntraj[0].hasvels) self.assertFalse(ntraj[0].hasfrcs) self.assertTrue(ntraj[1].hascrds) self.assertTrue(ntraj[1].hasvels) self.assertFalse(ntraj[1].hasfrcs) self.assertTrue(ntraj[2].hascrds) self.assertFalse(ntraj[2].hasvels) self.assertTrue(ntraj[2].hasfrcs) self.assertTrue(ntraj[3].hascrds) self.assertTrue(ntraj[3].hasvels) self.assertTrue(ntraj[3].hasfrcs) self.assertFalse(ntraj[4].hascrds) self.assertTrue(ntraj[4].hasvels) self.assertFalse(ntraj[4].hasfrcs) self.assertFalse(ntraj[5].hascrds) self.assertFalse(ntraj[5].hasvels) self.assertTrue(ntraj[5].hasfrcs) self.assertFalse(ntraj[6].hascrds) self.assertTrue(ntraj[6].hasvels) self.assertTrue(ntraj[6].hasfrcs) for i in (0, 2, 3, 4, 5, 6): ntraj[i].close() # still need the 2nd for traj in atraj: traj.close() # Now test the NetCDF restart files fn = get_fn('restart.ncrst.%d', written=True) for i, j in enumerate(range(10, 501, 10)): ncrst = NetCDFRestart.open_old(fn % j) self.assertEqual(ncrst.coordinates.shape, (1, 25, 3)) self.assertEqual(ncrst.velocities.shape, (1, 25, 3)) np.testing.assert_allclose(ncrst.coordinates[0], ntraj[1].coordinates[i]) np.testing.assert_allclose(ncrst.velocities[0], ntraj[1].velocities[i], rtol=1e-6) # Now test the ASCII restart file f = AmberAsciiRestart(get_fn('restart.rst7', written=True), 'r') # Compare to ncrst and make sure it's the same data np.testing.assert_allclose(ncrst.coordinates, f.coordinates, atol=1e-3) np.testing.assert_allclose(ncrst.velocities, f.velocities, rtol=1e-3) # Make sure the EnergyMinimizerReporter does not fail f = StringIO() rep = EnergyMinimizerReporter(f) rep.report(sim, frame=10) rep.finalize()
def test_nested_defines(self): """ Tests CPreProcessor nested #define token replacement """ f = StringIO("#define MY_VAR replace1\n#define MY_VAR2 MY_VAR\n" "MY_VAR2\n") pp = CPreProcessor(f) self.assertEqual(pp.read().strip(), 'replace1')
def test_warnings(self): """ Test CPreProcessor warnings """ warnings.filterwarnings('error', category=PreProcessorWarning) f = StringIO('#ifndef MYVAR extra tokens\nline\n#endif') with CPreProcessor(f) as f: self.assertRaises(PreProcessorWarning, f.read)
def testWriteCIF(self): """ Test CIF writing capabilities """ cif = read_CIF(self.lzt) written = get_fn('test.cif', written=True) cif.write_cif(written, renumber=False, write_anisou=True) cif2 = read_CIF(written) # cif and cif2 should have equivalent atom properties (basically, # everything should be the same except the metadata) self.assertEqual(len(cif.atoms), len(cif2.atoms)) self.assertEqual(len(cif.residues), len(cif2.residues)) # Check residue properties for res1, res2 in zip(cif.residues, cif2.residues): self.assertEqual(len(res1), len(res2)) self.assertEqual(res1.name, res2.name) self.assertEqual(res1.chain, res2.chain) self.assertEqual(res1.insertion_code, res2.insertion_code) self.assertEqual(res1.number, res2.number) # Check atom properties for a1, a2 in zip(cif.atoms, cif2.atoms): self.assertEqual(a1.name, a2.name) self.assertEqual(a1.number, a2.number) self.assertEqual(a1.element, a2.element) self.assertEqual(a1.altloc, a2.altloc) self.assertEqual(a1.xx, a2.xx) self.assertEqual(a1.xy, a2.xy) self.assertEqual(a1.xz, a2.xz) self.assertEqual(len(a1.anisou), 6) self.assertEqual(len(a2.anisou), 6) for x, y in zip(a1.anisou, a2.anisou): self.assertEqual(x, y) # Check box self.assertEqual(len(cif.box), len(cif2.box)) for x, y in zip(cif.box, cif2.box): self.assertEqual(x, y) # Now check CIF writing without anisotropic B-factors and with # renumbering io = StringIO() cif.write_cif(io) io.seek(0) cif3 = read_CIF(io) # cif and cif3 should have equivalent atom properties (basically, # everything should be the same except the metadata) self.assertEqual(len(cif.atoms), len(cif3.atoms)) self.assertEqual(len(cif.residues), len(cif3.residues)) # Check residue properties i = 1 for res1, res2 in zip(cif.residues, cif3.residues): self.assertEqual(len(res1), len(res2)) self.assertEqual(res1.name, res2.name) self.assertEqual(res1.chain, res2.chain) self.assertEqual(res1.insertion_code, res2.insertion_code) self.assertEqual(res2.number, i) i += 1 # Check atom properties i = 1 for a1, a2 in zip(cif.atoms, cif3.atoms): self.assertEqual(a1.name, a2.name) self.assertEqual(a2.number, i) self.assertEqual(a1.element, a2.element) self.assertEqual(a1.altloc, a2.altloc) self.assertEqual(a1.xx, a2.xx) self.assertEqual(a1.xy, a2.xy) self.assertEqual(a1.xz, a2.xz) self.assertIs(a2.anisou, None) i += 1 + len(a2.other_locations) # Check box self.assertEqual(len(cif.box), len(cif3.box)) for x, y in zip(cif.box, cif3.box): self.assertEqual(x, y)
def test_write_xml_parameters_amber_write_unused(self): """Test the write_unused argument in writing XML files""" params = openmm.OpenMMParameterSet.from_parameterset( pmd.amber.AmberParameterSet( get_fn('amino12.lib'), os.path.join(get_fn('parm'), 'parm10.dat'), os.path.join(get_fn('parm'), 'frcmod.ff14SB'))) ffxml = StringIO() params.write(ffxml) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 2178) ffxml = StringIO() params.write(ffxml, write_unused=False) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 1646) params = openmm.OpenMMParameterSet.from_parameterset( pmd.amber.AmberParameterSet( get_fn('atomic_ions.lib'), os.path.join(get_fn('parm'), 'frcmod.ionsjc_tip3p'))) ffxml = StringIO() warnings.filterwarnings('ignore', category=exceptions.ParameterWarning) params.write(ffxml) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 222) ffxml = StringIO() params.write(ffxml, write_unused=False) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 57)
def test_multiword_define(self): """ Tests CPreProcessor #define with multiple words """ f = StringIO("#define MY_DEFINE Changed to a sentence\nMY_DEFINE") self.assertEqual( CPreProcessor(f).read().strip(), "Changed to a sentence")
def test_write_xml_parameters(self): """ Test writing XML parameters loaded from Amber files """ leaprc = StringIO("""\ logFile leap.log # # ----- leaprc for loading the ff14SB force field # ----- NOTE: this is designed for PDB format 3! # Uses frcmod.ff14SB for proteins; ff99bsc0 for DNA; ff99bsc0_chiOL3 for RNA # # load atom type hybridizations # addAtomTypes { { "H" "H" "sp3" } { "HO" "H" "sp3" } { "HS" "H" "sp3" } { "H1" "H" "sp3" } { "H2" "H" "sp3" } { "H3" "H" "sp3" } { "H4" "H" "sp3" } { "H5" "H" "sp3" } { "HW" "H" "sp3" } { "HC" "H" "sp3" } { "HA" "H" "sp3" } { "HP" "H" "sp3" } { "HZ" "H" "sp3" } { "OH" "O" "sp3" } { "OS" "O" "sp3" } { "O" "O" "sp2" } { "O2" "O" "sp2" } { "OP" "O" "sp2" } { "OW" "O" "sp3" } { "CT" "C" "sp3" } { "CX" "C" "sp3" } { "C8" "C" "sp3" } { "2C" "C" "sp3" } { "3C" "C" "sp3" } { "CH" "C" "sp3" } { "CS" "C" "sp2" } { "C" "C" "sp2" } { "CO" "C" "sp2" } { "C*" "C" "sp2" } { "CA" "C" "sp2" } { "CB" "C" "sp2" } { "CC" "C" "sp2" } { "CN" "C" "sp2" } { "CM" "C" "sp2" } { "CK" "C" "sp2" } { "CQ" "C" "sp2" } { "CD" "C" "sp2" } { "C5" "C" "sp2" } { "C4" "C" "sp2" } { "CP" "C" "sp2" } { "CI" "C" "sp3" } { "CJ" "C" "sp2" } { "CW" "C" "sp2" } { "CV" "C" "sp2" } { "CR" "C" "sp2" } { "CA" "C" "sp2" } { "CY" "C" "sp2" } { "C0" "Ca" "sp3" } { "MG" "Mg" "sp3" } { "N" "N" "sp2" } { "NA" "N" "sp2" } { "N2" "N" "sp2" } { "N*" "N" "sp2" } { "NP" "N" "sp2" } { "NQ" "N" "sp2" } { "NB" "N" "sp2" } { "NC" "N" "sp2" } { "NT" "N" "sp3" } { "NY" "N" "sp2" } { "N3" "N" "sp3" } { "S" "S" "sp3" } { "SH" "S" "sp3" } { "P" "P" "sp3" } { "LP" "" "sp3" } { "EP" "" "sp3" } { "F" "F" "sp3" } { "Cl" "Cl" "sp3" } { "Br" "Br" "sp3" } { "I" "I" "sp3" } { "F-" "F" "sp3" } { "Cl-" "Cl" "sp3" } { "Br-" "Br" "sp3" } { "I-" "I" "sp3" } { "Li+" "Li" "sp3" } { "Na+" "Na" "sp3" } { "K+" "K" "sp3" } { "Rb+" "Rb" "sp3" } { "Cs+" "Cs" "sp3" } { "Mg+" "Mg" "sp3" } # glycam { "OG" "O" "sp3" } { "OL" "O" "sp3" } { "AC" "C" "sp3" } { "EC" "C" "sp3" } } # # Load the main parameter set. # parm10 = loadamberparams parm10.dat frcmod14SB = loadamberparams frcmod.ff14SB # # Load main chain and terminating amino acid libraries, nucleic acids # loadOff amino12.lib loadOff aminoct12.lib loadOff aminont12.lib loadOff nucleic12.lib # # Load water and ions # #loadOff atomic_ions.lib #loadOff solvents.lib #HOH = TP3 #WAT = TP3 # # Define the PDB name map for the amino acids and nucleic acids # addPdbResMap { { 0 "HYP" "NHYP" } { 1 "HYP" "CHYP" } { 0 "ALA" "NALA" } { 1 "ALA" "CALA" } { 0 "ARG" "NARG" } { 1 "ARG" "CARG" } { 0 "ASN" "NASN" } { 1 "ASN" "CASN" } { 0 "ASP" "NASP" } { 1 "ASP" "CASP" } { 0 "CYS" "NCYS" } { 1 "CYS" "CCYS" } { 0 "CYX" "NCYX" } { 1 "CYX" "CCYX" } { 0 "GLN" "NGLN" } { 1 "GLN" "CGLN" } { 0 "GLU" "NGLU" } { 1 "GLU" "CGLU" } { 0 "GLY" "NGLY" } { 1 "GLY" "CGLY" } { 0 "HID" "NHID" } { 1 "HID" "CHID" } { 0 "HIE" "NHIE" } { 1 "HIE" "CHIE" } { 0 "HIP" "NHIP" } { 1 "HIP" "CHIP" } { 0 "ILE" "NILE" } { 1 "ILE" "CILE" } { 0 "LEU" "NLEU" } { 1 "LEU" "CLEU" } { 0 "LYS" "NLYS" } { 1 "LYS" "CLYS" } { 0 "MET" "NMET" } { 1 "MET" "CMET" } { 0 "PHE" "NPHE" } { 1 "PHE" "CPHE" } { 0 "PRO" "NPRO" } { 1 "PRO" "CPRO" } { 0 "SER" "NSER" } { 1 "SER" "CSER" } { 0 "THR" "NTHR" } { 1 "THR" "CTHR" } { 0 "TRP" "NTRP" } { 1 "TRP" "CTRP" } { 0 "TYR" "NTYR" } { 1 "TYR" "CTYR" } { 0 "VAL" "NVAL" } { 1 "VAL" "CVAL" } { 0 "HIS" "NHIS" } { 1 "HIS" "CHIS" } { 0 "G" "G5" } { 1 "G" "G3" } { 0 "A" "A5" } { 1 "A" "A3" } { 0 "C" "C5" } { 1 "C" "C3" } { 0 "U" "U5" } { 1 "U" "U3" } { 0 "DG" "DG5" } { 1 "DG" "DG3" } { 0 "DA" "DA5" } { 1 "DA" "DA3" } { 0 "DC" "DC5" } { 1 "DC" "DC3" } { 0 "DT" "DT5" } { 1 "DT" "DT3" } # some old Amber residue names for RNA: { 0 "RA5" "A5" } { 1 "RA3" "A3"} {"RA" "A" } { 0 "RC5" "C5" } { 1 "RC3" "C3"} {"RC" "C" } { 0 "RG5" "G5" } { 1 "RG3" "G3"} {"RG" "G" } { 0 "RU5" "U5" } { 1 "RU3" "U3"} {"RU" "U" } # some really old Amber residue names, assuming DNA: { 0 "GUA" "DG5" } { 1 "GUA" "DG3" } { "GUA" "DG" } { 0 "ADE" "DA5" } { 1 "ADE" "DA3" } { "ADE" "DA" } { 0 "CYT" "DC5" } { 1 "CYT" "DC3" } { "CYT" "DC" } { 0 "THY" "DT5" } { 1 "THY" "DT3" } { "THY" "DT" } # uncomment out the following if you have this old style RNA files: # { 0 "GUA" "G5" } { 1 "GUA" "G3" } { "GUA" "G" } # { 0 "ADE" "A5" } { 1 "ADE" "A3" } { "ADE" "A" } # { 0 "CYT" "C5" } { 1 "CYT" "C3" } { "CYT" "C" } # { 0 "URA" "R5" } { 1 "URA" "R3" } { "URA" "R" } } # try to be good about reading in really old atom names as well: addPdbAtomMap { { "O5*" "O5'" } { "C5*" "C5'" } { "C4*" "C4'" } { "O4*" "O4'" } { "C3*" "C3'" } { "O3*" "O3'" } { "C2*" "C2'" } { "O2*" "O2'" } { "C1*" "C1'" } { "C5M" "C7" } { "H1*" "H1'" } { "H2*1" "H2'" } { "H2*2" "H2''" } { "H2'1" "H2'" } { "H2'2" "H2''" } { "H3*" "H3'" } { "H4*" "H4'" } { "H5*1" "H5'" } { "H5*2" "H5''" } { "H5'1" "H5'" } { "H5'2" "H5''" } { "HO'2" "HO2'" } { "H5T" "HO5'" } { "H3T" "HO3'" } { "O1'" "O4'" } { "OA" "OP1" } { "OB" "OP2" } { "O1P" "OP1" } { "O2P" "OP2" } } # # assume that most often proteins use HIE # NHIS = NHIE HIS = HIE CHIS = CHIE """) params = openmm.OpenMMParameterSet.from_parameterset( pmd.amber.AmberParameterSet.from_leaprc(leaprc)) params.write(get_fn('amber_conv.xml', written=True), provenance=dict(OriginalFile='leaprc.ff14SB', Reference=[ 'Maier & Simmerling', 'Simmerling & Maier' ], Source=dict(Source='leaprc.ff14SB', sourcePackage='AmberTools', sourcePackageVersion='15')))
def test_write_xml_parameters_amber_write_unused(self): """Test the write_unused argument in writing XML files""" params = openmm.OpenMMParameterSet.from_parameterset( pmd.amber.AmberParameterSet(get_fn('amino12.lib'), os.path.join(get_fn('parm'), 'parm10.dat'), os.path.join(get_fn('parm'), 'frcmod.ff14SB')) ) ffxml = StringIO() params.write(ffxml) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 2178) ffxml = StringIO() params.write(ffxml, write_unused=False) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 1646) params = openmm.OpenMMParameterSet.from_parameterset( pmd.amber.AmberParameterSet(get_fn('atomic_ions.lib'), os.path.join(get_fn('parm'), 'frcmod.ionsjc_tip3p')) ) ffxml = StringIO() warnings.filterwarnings('ignore', category=exceptions.ParameterWarning) params.write(ffxml) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 222) ffxml = StringIO() params.write(ffxml, write_unused=False) ffxml.seek(0) self.assertEqual(len(ffxml.readlines()), 57)