def __init__(self, pdb, working_directory="pdb4amber_reduce"): amberhome = get_amberhome() utils.set_working_directory(working_directory) pdb.to_filename('input.pdb') pdb4amber_command = (amberhome + "/bin/pdb4amber " "-i input.pdb -o pdb4amber.pdb --nohyd --dry") utils.run_in_shell(pdb4amber_command, 'pdb4amber.out') reduce_command = (amberhome + "/bin/reduce " "-build -nuclear pdb4amber.pdb") utils.run_in_shell(reduce_command, 'reduce.pdb') with open('reduce.pdb') as f: self.pdb = pdb_utils.Pdb(f) renamed_histidines = get_renamed_histidines(self.pdb) residues = self.pdb.residues() for res_hash, res_name in renamed_histidines.items(): pdb_utils.modify_atoms(residues.get(res_hash, []), 'resName', res_name) # Remove hydrogens on HETATMs self.pdb.atoms = [ atom for atom in self.pdb.atoms if (atom['record'] != 'HETATM' or 'new' not in atom['extras']) ] # Remove hydrogens added by reduce to non-protein residues with open('pdb4amber_nonprot.pdb') as f: self.nonprotPdb = pdb_utils.Pdb(f) self.nonprot_residues = set(atom['resName'] for atom in self.nonprotPdb.atoms) self.pdb.atoms = [ atom for atom in self.pdb.atoms if (atom['resName'] not in self.nonprot_residues or 'new' not in atom['extras']) ] # store crystalline waters with open('pdb4amber_water.pdb') as f: self.waterPdb = pdb_utils.Pdb(f) os.chdir('..')
def test_get_renamed_histidines(self): renamed_histidines = { 'A_262_HIS': 'HIE', 'A_1_HIS': 'HIE', 'A_71_HIS': 'HIE', 'A_87_HIS': 'HID', 'A_128_HIS': 'HIE', 'A_133_HIS': 'HIE' } with open('tests/test_files/reduce.pdb') as f: reducePdb = pdb_utils.Pdb(f) self.assertEqual(wrappers.get_renamed_histidines(reducePdb), renamed_histidines)
def test_propka_call(self, mock_os, mock_os_path, mock_print, mock_utils): setup_mock(mock_os, mock_os_path) with open('tests/test_files/reduce.pdb') as f: pdb = pdb_utils.Pdb(f) pdb.to_filename = mock.MagicMock() with open('tests/test_files/propka.pka') as f: mock_open = iterable_mock_open(read_data=f.read()) with mock.patch('wrappers.open', mock_open): result = wrappers.PropkaWrapper(pdb) residues = result.pdb.residues() self.assertEqual(len(result.prot_list), 1) self.assertEqual(len(result.deprot_list), 0) self.assertNotIn('A_189_ASP', residues) self.assertIn('A_189_ASH', residues) self.assertEqual(len(residues['A_189_ASH']), 12)
def setUpClass(cls): cls.atom_string = ("ATOM 278 HG2 ARG A 36 " "17.074 -2.417 17.463 1.00 11.39" " H new") cls.parsed_atom = { 'record': "ATOM", 'serial': 278, 'name': "HG2", 'altLoc': "", 'resName': "ARG", 'chainID': "A", 'resSeq': 36, 'iCode': "", 'x': 17.074, 'y': -2.417, 'z': 17.463, 'occupancy': 1.0, 'tempFactor': 11.39, 'element': "H", 'charge': "", 'extras': " new" } with open('tests/test_files/full.pdb') as f: cls.pdb = pdb_utils.Pdb(f)
if args.params is not None: params = utils.merge_dicts_of_dicts(params, json.load(args.params)) args.params.close() print("Starting PREP protocol in {}/".format(pdb_name)) if os.path.exists(pdb_name): print( "It appears you've already (attempted to) run prep.py with {0}. " "Delete folder {0} or rename pdb if you want to run it again.".format( pdb_name)) sys.exit() utils.set_working_directory(pdb_name) pdb = pdb_utils.Pdb(args.pdb) ligands = pdb.get_residues_by_name(ligand_name) if len(ligands) == 0: raise ValueError("No ligands found") ligand_index = params['antechamber']['ligand_index'] if ligand_index > len(ligands): raise ValueError("ligand_index is larger than the number of ligands") ligand_atoms = ligands[ligand_index - 1] if len(ligands) > 1: print("More than one ligand detected. Using coordinates from the ligand" " with chainID={} and resSeq={}".format(ligand_atoms[0]['chainID'], ligand_atoms[0]['resSeq']))