예제 #1
0
def fastcontact(pdb_f, fastcontact_exe):

    felecv = .0
    fdesolv = .0
    freee = .0

    prot_dic = PDB.load_structure(pdb_f)

    for segid_x, segid_y in itertools.combinations(prot_dic, 2):

        prot_x = '{}.pdb'.format(segid_x)
        prot_x_str = ''.join(prot_dic[segid_x])
        with open(prot_x, 'w') as fh_prot_x:
            fh_prot_x.write(prot_x_str)
        fh_prot_x.close()

        prot_y = '{}.pdb'.format(segid_y)
        prot_y_str = ''.join(prot_dic[segid_y])
        with open(prot_y, 'w') as fh_prot_y:
            fh_prot_y.write(prot_y_str)
        fh_prot_y.close()

        p = subprocess.Popen([fastcontact_exe, prot_x, prot_y],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        out = p.communicate()

        returncode = p.wait()

        if returncode != 0:
            print('+ ERROR: Something wrong with fastcontact')
            exit()

        i, j, k = map(float, str(out[0]).split('\\n')[1].split())
        felecv += i
        fdesolv += j
        freee += k

        os.remove(prot_x)
        os.remove(prot_y)

    return felecv, fdesolv
예제 #2
0
파일: dfire.py 프로젝트: SSchott/haddock3
def dfire(pdb_f, dcomplex_exe):

    fixed_pdb = PDB.fix_id(pdb_f)
    prot_dic = PDB.load_structure(fixed_pdb)

    dfire_regex = r'-?\d*?\.\d\d*'

    dfire_dic = {'binding': [], 'score': []}
    for segid_x, segid_y in itertools.combinations(prot_dic, 2):

        input_str = str.encode(f'{fixed_pdb}\n1\n{segid_x}\n1\n{segid_y}')

        p = subprocess.run(dcomplex_exe,
                           input=input_str,
                           stdout=subprocess.PIPE)

        try:
            result = p.stdout.decode('utf-8')
            score, binding = re.findall(dfire_regex, result)

            score = float(score)
            binding = float(binding)

        except ValueError:

            binding = .0
            score = .0

        dfire_dic['binding'].append(binding)
        dfire_dic['score'].append(score)

    binding_l = [float(e) for e in dfire_dic['binding']]
    score_l = [float(e) for e in dfire_dic['score']]

    mean_binding = sum(binding_l) / len(binding_l)
    mean_score = sum(score_l) / len(score_l)

    return mean_binding, mean_score
예제 #3
0
class TestPDB(unittest.TestCase):

	def setUp(self):
		self.PDB = PDB()

	def test_treat_ensemble(self):
		copyfile(f'{data_path}/mini_ens.pdb', f'{data_path}/temp_ens.pdb')
		input_pdb_dic = {'mol1': f'{data_path}/temp_ens.pdb'}

		treated_dic = self.PDB.treat_ensemble(input_pdb_dic)
		expected_treated_dic = {'mol1': [f'{data_path}/temp_1.pdb', f'{data_path}/temp_2.pdb']}

		self.assertEqual(treated_dic, expected_treated_dic)
		self.assertTrue(filecmp.cmp(f'{data_path}/temp_1.pdb', f'{data_path}/mini_ens1.pdb'))
		self.assertTrue(filecmp.cmp(f'{data_path}/temp_2.pdb', f'{data_path}/mini_ens2.pdb'))

		os.remove(f'{data_path}/temp_1.pdb')
		os.remove(f'{data_path}/temp_2.pdb')
		os.remove(f'{data_path}/temp_ens.pdb')

	def test_load_structure(self):
		pdb_f = f'{data_path}/miniA.pdb'
		pdb_dic = self.PDB.load_structure(pdb_f)
		expected_pdb_dic = {'A': ['ATOM      2  CA  MET A   1      16.967  12.784   4.338  1.00 10.80      A    C  \n',
							  'ATOM      9  CA  ARG A   2      13.856  11.469   6.066  1.00  8.31      A    C  \n',
							  'ATOM     16  CA  CYS A   3      13.660  10.707   9.787  1.00  5.39      A    C  \n']}
		self.assertEqual(pdb_dic, expected_pdb_dic)

	def test_identify_chains(self):
		pdb_f = f'{data_path}/mini.pdb'
		chain_l = self.PDB.identify_chains(pdb_f)
		expected_chain_l = ['A', 'B','C']
		self.assertEqual(chain_l, expected_chain_l)

	def test_identify_segids(self):
		pdb_f = f'{data_path}/miniA.pdb'
		segid_l = self.PDB.identify_segids(pdb_f)
		expected_segid_l = ['A']
		self.assertEqual(segid_l, expected_segid_l)

	def test_split_models(self):
		ensamble_f = f'{data_path}/mini_ens.pdb'
		model_list = self.PDB.split_models(ensamble_f)
		expected_list = [f'{data_path}/mini_1.pdb', f'{data_path}/mini_2.pdb']

		self.assertEqual(model_list, expected_list, 'Name of list elements differ')
		self.assertTrue(filecmp.cmp(f'{data_path}/mini_1.pdb', f'{data_path}/mini_1.gold'))
		self.assertTrue(filecmp.cmp(f'{data_path}/mini_2.pdb', f'{data_path}/mini_2.gold'))

		for f in model_list:
			os.remove(f)

	def test_fix_id(self):
		nosegid_pdb_f = f'{data_path}/mini.pdb'
		nochain_pdb_f = f'{data_path}/mini_nochain.pdb'

		segid_pdb = self.PDB.fix_id(nosegid_pdb_f, priority='chain', overwrite=False)
		chain_pdb = self.PDB.fix_id(nochain_pdb_f, priority='seg', overwrite=False)

		self.assertTrue(filecmp.cmp(segid_pdb, f'{data_path}/mini_segid.pdb'))
		self.assertTrue(filecmp.cmp(chain_pdb, f'{data_path}/mini_segid.pdb'))

		os.remove(f'{data_path}/mini.pdb_')
		os.remove(f'{data_path}/mini_nochain.pdb_')

	def test_add_chainseg(self):

		copyfile(f'{data_path}/mini.pdb', f'{data_path}/temp.pdb')

		check = self.PDB.add_chainseg(f'{data_path}/temp.pdb', 'A')

		self.assertTrue(check)
		self.assertTrue(filecmp.cmp(f'{data_path}/temp.pdb', f'{data_path}/miniA.pdb'))

		os.remove(f'{data_path}/temp.pdb')

	def test_identify_chainseg(self):

		pdbf = f'{data_path}/miniA.pdb'

		chainseg = self.PDB.identify_chainseg(pdbf)

		self.assertEqual(chainseg, ['A'])

	def test_fix_chainseg(self):
		copyfile(f'{data_path}/mini_1.gold', f'{data_path}/mol1.pdb')
		copyfile(f'{data_path}/mini_2.gold', f'{data_path}/mol2.pdb')

		input_pdb_dic = {'mol1': f'{data_path}/mol1.pdb', 'segid1': 'X', 'mol2': f'{data_path}/mol2.pdb'}

		return_pdb_dic = self.PDB.fix_chainseg(input_pdb_dic)
		expected_return_dic = {'mol1': f'{data_path}/mol1.pdb', 'mol2': f'{data_path}/mol2.pdb'}

		self.assertEqual(return_pdb_dic, expected_return_dic)
		self.assertTrue(filecmp.cmp(f'{data_path}/mol1.pdb', f'{data_path}/miniX.pdb'))

		os.remove(f'{data_path}/mol1.pdb')
		os.remove(f'{data_path}/mol2.pdb')

	def test_sanitize(self):
		copyfile(f'{data_path}/mini.dirty.pdb', f'{data_path}/temp.pdb')

		input_pdb_dic = {'mol1': [f'{data_path}/temp.pdb']}

		model_list = self.PDB.sanitize(input_pdb_dic)

		expected_model_list = [f'{data_path}/temp.pdb']

		self.assertEqual(model_list, expected_model_list)
		self.assertTrue(filecmp.cmp(f'{data_path}/temp.pdb', f'{data_path}/mini.clean.pdb'))

		os.remove(f'{data_path}/temp.pdb')

	def test_count_atoms(self):
		pdb_f = f'{data_path}/mini.pdb'
		atom_count = self.PDB.count_atoms(pdb_f)
		self.assertEqual(atom_count, 3)

	def test_organize_chains(self):
		pass

	def test_replace_chain(self):
		pdb_f = f'{data_path}/mini.pdb'
		newchain_pdb = self.PDB.replace_chain(pdb_f, 'A', 'X', overwrite=False)
		self.assertTrue(filecmp.cmp(newchain_pdb, f'{data_path}/mini_A-X.pdb'))
		os.remove(f'{data_path}/mini.pdb_')

	def test_renumber(self):
		pass

	def test_load_seq(self):
		pass

	def tearDown(self):
		pass