def test_write_model(): orig_parm = pmd.download_PDB('1l2y') pdb_out = 'out.pdb' # default with tempfolder(): pdb4amber.main(['1l2y', '--pdbid', '-o', pdb_out]) parm = pmd.load_file(pdb_out) assert parm.get_coordinates().shape == (1, 304, 3) # model 1 with tempfolder(): pdb4amber.main(['1l2y', '--pdbid', '-o', pdb_out, '--model', '1']) parm = pmd.load_file(pdb_out) assert parm.get_coordinates().shape == (1, 304, 3) np.testing.assert_almost_equal(parm.coordinates, orig_parm.get_coordinates()[0]) # model 2 model = 2 with tempfolder(): pdb4amber.main(['1l2y', '--pdbid', '-o', pdb_out, '--model', str(model) ]) parm = pmd.load_file(pdb_out) assert parm.get_coordinates().shape == (1, 304, 3) np.testing.assert_almost_equal(parm.coordinates, orig_parm.get_coordinates()[model - 1])
def test_keep_all_model(): orig_parm = pmd.download_PDB('1l2y') pdb_out = 'out.pdb' # default with tempfolder(): pdb4amber.main(['1l2y', '--pdbid', '-o', pdb_out, '--model', '-1']) parm = pmd.load_file(pdb_out) assert parm.get_coordinates().shape == (38, 304, 3)
def testModifiedDNARNA(self): """ Tests that modified DNA/RNA residue names are properly recognized""" def count_nures(parm): nnuc = 0 for res in parm.residues: if RNAResidue.has(res.name) or DNAResidue.has(res.name): nnuc += 1 return nnuc pdb_with_nnures = [('1EHZ', 76), ('3p4a', 48), ('3p4b', 48), ('3p4d', 16)] for pdbid, correct_nres in pdb_with_nnures: pdb = pmd.download_PDB(pdbid) nres = count_nures(pdb) self.assertEqual(correct_nres, nres)
def test_modified_dna_rna(self): """ Tests that modified DNA/RNA residue names are properly recognized""" def count_nures(parm): nnuc = 0 for res in parm.residues: if RNAResidue.has(res.name) or DNAResidue.has(res.name): nnuc += 1 return nnuc pdb_with_nnures = [('1EHZ', 76), ('3p4a', 48), ('3p4b', 48), ('3p4d', 16)] for pdbid, correct_nres in pdb_with_nnures: pdb = pmd.download_PDB(pdbid) nres = count_nures(pdb) self.assertEqual(correct_nres, nres)
def test_structure_box_and_space_group_and_symmetry(self): """ Test correctly copying box, space group and symmetry """ def assert_correctly_copy(parm): sliced_parm = parm['@1-3'] if parm.box is None: self.assertIs(sliced_parm.box, None) else: np.testing.assert_equal(parm.box, sliced_parm.box) if parm.symmetry is None: self.assertIs(sliced_parm.symmetry, None) else: np.testing.assert_equal(parm.symmetry.data, sliced_parm.symmetry.data) self.assertEqual(parm.space_group, sliced_parm.space_group) # pdb parm = pmd.load_file(get_fn('4lzt.pdb')) assert_correctly_copy(parm) # pdb from rcsb parm = pmd.download_PDB('2igd') assert_correctly_copy(parm) # cif parm = pmd.load_file(get_fn('sample.cif')) assert_correctly_copy(parm) # LES parm7, no rst7 parm = pmd.load_file(get_fn('4lzt.les.parm7')) assert_correctly_copy(parm) # LES parm7, with rst7 parm = pmd.load_file(get_fn('4lzt.les.parm7'), xyz=get_fn('4lzt.les.rst7')) assert_correctly_copy(parm) # parm7, no box parm = pmd.load_file(get_fn('ash.parm7')) assert_correctly_copy(parm) # gro parm = pmd.load_file(get_fn('1aki.charmm27.solv.gro')) assert_correctly_copy(parm) # psf parm = pmd.load_file(get_fn('4TVP-dmj_wat-ion.psf')) assert_correctly_copy(parm) # mol2 parm = pmd.load_file(get_fn('m2-c1_f3.mol2'), structure=True) assert_correctly_copy(parm) # pqr parm = pmd.load_file(get_fn('adk_open.pqr')) assert_correctly_copy(parm) # chamber parm parm = pmd.load_file(get_fn('ala_ala_ala.parm7')) assert_correctly_copy(parm)
def main(argv=None): parser = argparse.ArgumentParser() parser.add_argument( "input", nargs='?', help="PDB input file (default: stdin)", ) parser.add_argument("-i", "--in", metavar="FILE", dest="pdbin", help="PDB input file (default: stdin)", default='stdin') parser.add_argument("-o", "--out", metavar="FILE", dest="pdbout", help="PDB output file (default: stdout)", default='stdout') parser.add_argument("-y", "--nohyd", action="store_true", dest="nohyd", help="remove all hydrogen atoms (default: no)") parser.add_argument("-d", "--dry", action="store_true", dest="dry", help="remove all water molecules (default: no)") parser.add_argument("-s", "--strip", dest="strip_atom_mask", default=None, help="Strip given atom mask, (default: no)") parser.add_argument("-m", "--mutate", dest="mutation_string", default=None, help="Mutate residue") parser.add_argument( "-p", "--prot", action="store_true", dest="prot", help="keep only Amber-compatible residues (default: no)") parser.add_argument("--constantph", action="store_true", dest="constantph", help="rename GLU,ASP,HIS for constant pH simulation") parser.add_argument( "--most-populous", action="store_true", dest="mostpop", help="keep most populous alt. conf. (default is to keep 'A')") parser.add_argument("--keep-altlocs", action="store_true", dest="keep_altlocs", help="Keep alternative conformations") parser.add_argument( "--reduce", action="store_true", dest="reduce", help="Run Reduce first to add hydrogens. (default: no)") parser.add_argument( "--no-reduce-db", action="store_true", dest="no_reduce_db", help= "If reduce is on, skip using it for hetatoms. (default: usual reduce behavior for hetatoms)" ) parser.add_argument("--pdbid", action="store_true", dest="pdbid", help="fetch structure with given pdbid, " "should combined with -i option.\n" "Subjected to change") parser.add_argument("--add-missing-atoms", action="store_true", dest="add_missing_atoms", help="Use tleap to add missing atoms") parser.add_argument( "--model", type=int, dest="model", default=1, help= "Model to use from a multi-model pdb file (integer). (default: use 1st model). " "Use a negative number to keep all models") parser.add_argument("-l", "--logfile", metavar="FILE", dest="logfile", help="log filename", default='stderr') parser.add_argument("-v", "--version", action="store_true", dest="version", help="version") parser.add_argument( "--leap-template", action='store_true', dest="leap_template", help="write a leap template for easy adaption\n(EXPERIMENTAL)") parser.add_argument("--no-conect", action='store_true', dest="no_conect", help="Not write S-S conect record") parser.add_argument("--noter", action='store_true', dest="noter", help="Not writing TER") opt = parser.parse_args(argv) # pdbin : {str, file object, parmed.Structure} if opt.version: print(__version__) if opt.input is not None: pdbin = opt.input else: pdbin = opt.pdbin if opt.pdbid: pdbin = parmed.download_PDB(pdbin) if opt.pdbin == 'stdin' and opt.input is None: if os.isatty(sys.stdin.fileno()): parser.print_help() sys.exit(0) if opt.logfile == 'stderr': logfile = sys.stderr elif opt.logfile == 'stdout': logfile = sys.stdout else: logfile = opt.logfile run(arg_pdbout=opt.pdbout, arg_pdbin=pdbin, arg_nohyd=opt.nohyd, arg_dry=opt.dry, arg_strip_atom_mask=opt.strip_atom_mask, arg_mutate_string=opt.mutation_string, arg_prot=opt.prot, arg_constph=opt.constantph, arg_mostpop=opt.mostpop, arg_reduce=opt.reduce, arg_no_reduce_db=opt.no_reduce_db, arg_model=opt.model - 1, arg_keep_altlocs=opt.keep_altlocs, arg_add_missing_atoms=opt.add_missing_atoms, arg_logfile=logfile, arg_leap_template=opt.leap_template, arg_conect=not opt.no_conect, arg_noter=opt.noter)
from parmed.residue import WATER_NAMES import pytest try: from io import StringIO except ImportError: from cStringIO import StringIO from pdb4amber import pdb4amber # local from utils import tempfolder, get_fn, _has_program pdb_fn = get_fn('4lzt/4lzt_h.pdb') try: # check internet pmd.download_PDB('1l2y') internet_ok = True except IOError: internet_ok = False @unittest.skipUnless(internet_ok, 'must have internet connection to rcsb') def test_write_model(): orig_parm = pmd.download_PDB('1l2y') pdb_out = 'out.pdb' # default with tempfolder(): pdb4amber.main(['1l2y', '--pdbid', '-o', pdb_out]) parm = pmd.load_file(pdb_out) assert parm.get_coordinates().shape == (1, 304, 3)
def testDownloadSave(self): """ Tests downloading PDB files and saving a copy """ fname = get_fn('downloaded.pdb', written=True) self._check4lzt(download_PDB('4lzt', saveto=fname)) self._check4lzt(read_PDB(fname))
def testDownload(self): """ Tests downloading PDB files """ self._check4lzt(download_PDB('4lzt'))
def test_space_group(self): parm_from_cif = pmd.download_CIF('2igd') parm_from_pdb = pmd.download_PDB('2igd') self.assertEqual(parm_from_cif.space_group, 'P 21 21 21') self.assertEqual(parm_from_pdb.space_group, 'P 21 21 21')
import parmed as pmd p = pmd.download_PDB('3gx5') p[':SAM'].save('SAM.pdb')