jglaser commited on
Commit
6297930
1 Parent(s): 5ad5b1b

minimum number of ligand atoms is 3

Browse files
Files changed (3) hide show
  1. get_pdb_ids.py +0 -14
  2. parse_complexes.py +5 -1
  3. split_complex.py +0 -123
get_pdb_ids.py DELETED
@@ -1,14 +0,0 @@
1
- from rcsbsearch import Terminal
2
- from rcsbsearch import rcsb_attributes as attrs
3
-
4
- # Create terminals for each query
5
- q1 = attrs.rcsb_entry_info.nonpolymer_entity_count > 0
6
- q2 = attrs.rcsb_entry_info.polymer_entity_count_protein > 0
7
- q3 = Terminal('chem_comp.formula_weight','greater_or_equal',150,service='text_chem')
8
-
9
- # combined using bitwise operators (&, |, ~, etc)
10
- query = q1 & q2 & q3 # AND of all queries
11
-
12
- # Call the query to execute it
13
- for assemblyid in query("entry"):
14
- print(assemblyid)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
parse_complexes.py CHANGED
@@ -26,6 +26,9 @@ import os
26
  # minimum molecular weight to consider sth a ligand
27
  mol_wt_cutoff = 100
28
 
 
 
 
29
  # all punctuation
30
  punctuation_regex = r"""(\(|\)|\.|=|#|-|\+|\\|\/|:|~|@|\?|>>?|\*|\$|\%[0-9]{2}|[0-9])"""
31
 
@@ -148,8 +151,9 @@ def process_entry(df_dict, pdb_fn):
148
  mol, template = process_ligand(ligand, res, df_dict)
149
 
150
  mol_wt = ExactMolWt(template)
 
151
 
152
- if mol_wt >= mol_wt_cutoff:
153
  ligand_mols.append(mol)
154
  ligand_names.append(res)
155
 
 
26
  # minimum molecular weight to consider sth a ligand
27
  mol_wt_cutoff = 100
28
 
29
+ # minimum number of atoms
30
+ min_atoms = 3
31
+
32
  # all punctuation
33
  punctuation_regex = r"""(\(|\)|\.|=|#|-|\+|\\|\/|:|~|@|\?|>>?|\*|\$|\%[0-9]{2}|[0-9])"""
34
 
 
151
  mol, template = process_ligand(ligand, res, df_dict)
152
 
153
  mol_wt = ExactMolWt(template)
154
+ natoms = template.GetNumAtoms()
155
 
156
+ if mol_wt >= mol_wt_cutoff and natoms >= min_atoms:
157
  ligand_mols.append(mol)
158
  ligand_names.append(res)
159
 
split_complex.py DELETED
@@ -1,123 +0,0 @@
1
- #!/usr/bin/env python
2
-
3
- # Split a protein-ligand complex into protein and ligands and assign ligand bond orders using SMILES strings from Ligand Export
4
- # Code requires Python 3.6
5
-
6
- import sys
7
- from prody import *
8
- import pandas as pd
9
- from rdkit import Chem
10
- from rdkit.Chem import AllChem
11
- from io import StringIO
12
- import requests
13
-
14
-
15
- def read_ligand_expo():
16
- """
17
- Read Ligand Expo data, try to find a file called
18
- Components-smiles-stereo-oe.smi in the current directory.
19
- If you can't find the file, grab it from the RCSB
20
- :return: Ligand Expo as a dictionary with ligand id as the key
21
- """
22
- file_name = "Components-smiles-stereo-oe.smi"
23
- try:
24
- df = pd.read_csv(file_name, sep="\t",
25
- header=None,
26
- names=["SMILES", "ID", "Name"])
27
- except FileNotFoundError:
28
- url = f"http://ligand-expo.rcsb.org/dictionaries/{file_name}"
29
- print(url)
30
- r = requests.get(url, allow_redirects=True)
31
- open('Components-smiles-stereo-oe.smi', 'wb').write(r.content)
32
- df = pd.read_csv(file_name, sep="\t",
33
- header=None,
34
- names=["SMILES", "ID", "Name"])
35
- df.set_index("ID", inplace=True)
36
- return df.to_dict()
37
-
38
-
39
- def get_pdb_components(pdb_id):
40
- """
41
- Split a protein-ligand pdb into protein and ligand components
42
- :param pdb_id:
43
- :return:
44
- """
45
- pdb = parsePDB(pdb_id)
46
- protein = pdb.select('protein')
47
- ligand = pdb.select('not protein and not water')
48
- return protein, ligand
49
-
50
-
51
- def process_ligand(ligand, res_name, expo_dict):
52
- """
53
- Add bond orders to a pdb ligand
54
- 1. Select the ligand component with name "res_name"
55
- 2. Get the corresponding SMILES from the Ligand Expo dictionary
56
- 3. Create a template molecule from the SMILES in step 2
57
- 4. Write the PDB file to a stream
58
- 5. Read the stream into an RDKit molecule
59
- 6. Assign the bond orders from the template from step 3
60
- :param ligand: ligand as generated by prody
61
- :param res_name: residue name of ligand to extract
62
- :param expo_dict: dictionary with LigandExpo
63
- :return: molecule with bond orders assigned
64
- """
65
- output = StringIO()
66
- sub_mol = ligand.select(f"resname {res_name}")
67
- sub_smiles = expo_dict['SMILES'][res_name]
68
- template = AllChem.MolFromSmiles(sub_smiles)
69
- writePDBStream(output, sub_mol)
70
- pdb_string = output.getvalue()
71
- rd_mol = AllChem.MolFromPDBBlock(pdb_string)
72
- new_mol = AllChem.AssignBondOrdersFromTemplate(template, rd_mol)
73
- return new_mol
74
-
75
-
76
- def write_pdb(protein, pdb_name):
77
- """
78
- Write a prody protein to a pdb file
79
- :param protein: protein object from prody
80
- :param pdb_name: base name for the pdb file
81
- :return: None
82
- """
83
- output_pdb_name = f"{pdb_name}_protein.pdb"
84
- writePDB(f"{output_pdb_name}", protein)
85
- print(f"wrote {output_pdb_name}")
86
-
87
-
88
- def write_sdf(new_mol, pdb_name, res_name):
89
- """
90
- Write an RDKit molecule to an SD file
91
- :param new_mol:
92
- :param pdb_name:
93
- :param res_name:
94
- :return:
95
- """
96
- outfile_name = f"{pdb_name}_{res_name}_ligand.sdf"
97
- writer = Chem.SDWriter(f"{outfile_name}")
98
- writer.write(new_mol)
99
- print(f"wrote {outfile_name}")
100
-
101
-
102
- def main(pdb_name):
103
- """
104
- Read Ligand Expo data, split pdb into protein and ligands,
105
- write protein pdb, write ligand sdf files
106
- :param pdb_name: id from the pdb, doesn't need to have an extension
107
- :return:
108
- """
109
- df_dict = read_ligand_expo()
110
- protein, ligand = get_pdb_components(pdb_name)
111
- write_pdb(protein, pdb_name)
112
-
113
- res_name_list = list(set(ligand.getResnames()))
114
- for res in res_name_list:
115
- new_mol = process_ligand(ligand, res, df_dict)
116
- write_sdf(new_mol, pdb_name, res)
117
-
118
-
119
- if __name__ == "__main__":
120
- if len(sys.argv) == 2:
121
- main(sys.argv[1])
122
- else:
123
- print("Usage: {sys.argv[1]} pdb_id", file=sys.stderr)