jglaser commited on
Commit
80474da
1 Parent(s): e1c199e

add local frame info for molecules

Browse files
Files changed (4) hide show
  1. data/pdbbind.parquet +2 -2
  2. pdbbind.py +68 -4
  3. pdbbind.slurm +3 -3
  4. pdbbind_complexes.py +1 -1
data/pdbbind.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:3e7a0f58df3e45dec1c90b30f2bd8ab62c601a1073dafa1d426e0f36413ecf30
3
- size 141173725
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7fda9d4f86f91a5469a2bcaa3ecedd009e4e27abf412a1de377a65095033481b
3
+ size 179039843
pdbbind.py CHANGED
@@ -11,6 +11,10 @@ import dask.array as da
11
 
12
  from rdkit import Chem
13
 
 
 
 
 
14
  import os
15
  import re
16
  import sys
@@ -25,6 +29,55 @@ max_seq = 2046 # = 2048 - 2 (accounting for [CLS] and [SEP])
25
  max_smiles = 510 # = 512 - 2
26
  chunk_size = '1G'
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  def parse_complex(fn):
29
  try:
30
  name = os.path.basename(fn)
@@ -59,14 +112,20 @@ def parse_complex(fn):
59
 
60
  k = 0
61
  token_pos = []
 
 
 
 
62
  for i,token in enumerate(masked_tokens):
63
  if token != '':
64
  token_pos.append(tuple(mol.GetConformer().GetAtomPosition(atom_order[k])))
 
65
  k += 1
66
  else:
67
  token_pos.append((np.nan, np.nan, np.nan))
 
68
 
69
- return name, seq, smi, xyz_receptor, token_pos
70
 
71
  except Exception as e:
72
  print(e)
@@ -82,14 +141,19 @@ if __name__ == '__main__':
82
  comm = MPI.COMM_WORLD
83
  with MPICommExecutor(comm, root=0) as executor:
84
  if executor is not None:
85
- result = executor.map(parse_complex, filenames)
86
  result = list(result)
87
  names = [r[0] for r in result if r is not None]
88
  seqs = [r[1] for r in result if r is not None]
89
  all_smiles = [r[2] for r in result if r is not None]
90
  all_xyz_receptor = [r[3] for r in result if r is not None]
91
  all_xyz_ligand = [r[4] for r in result if r is not None]
 
92
 
93
  import pandas as pd
94
- df = pd.DataFrame({'name': names, 'seq': seqs, 'smiles': all_smiles, 'receptor_xyz': all_xyz_receptor, 'ligand_xyz': all_xyz_ligand})
95
- df.to_parquet('data/pdbbind.parquet')
 
 
 
 
 
11
 
12
  from rdkit import Chem
13
 
14
+ from spyrmsd import molecule
15
+ from spyrmsd import graph
16
+ import networkx as nx
17
+
18
  import os
19
  import re
20
  import sys
 
29
  max_smiles = 510 # = 512 - 2
30
  chunk_size = '1G'
31
 
32
+ def rot_from_two_vecs(e0_unnormalized, e1_unnormalized):
33
+ """Create rotation matrices from unnormalized vectors for the x and y-axes.
34
+ This creates a rotation matrix from two vectors using Gram-Schmidt
35
+ orthogonalization.
36
+ Args:
37
+ e0_unnormalized: vectors lying along x-axis of resulting rotation
38
+ e1_unnormalized: vectors lying in xy-plane of resulting rotation
39
+ Returns:
40
+ Rotations resulting from Gram-Schmidt procedure.
41
+ """
42
+ # Normalize the unit vector for the x-axis, e0.
43
+ e0 = e0_unnormalized / np.linalg.norm(e0_unnormalized)
44
+
45
+ # make e1 perpendicular to e0.
46
+ c = np.dot(e1_unnormalized, e0)
47
+ e1 = e1_unnormalized - c * e0
48
+ e1 = e1 / np.linalg.norm(e1)
49
+
50
+ # Compute e2 as cross product of e0 and e1.
51
+ e2 = np.cross(e0, e1)
52
+
53
+ # local to space frame
54
+ return np.stack([e0,e1,e2]).T
55
+
56
+ def get_local_frames(mol):
57
+ # get the two nearest neighbors of every atom on the molecular graph
58
+ # ties are broken using canonical ordering
59
+ g = molecule.Molecule.from_rdkit(mol).to_graph()
60
+
61
+ R = []
62
+ for node in g:
63
+ length = nx.single_source_shortest_path_length(g, node)
64
+
65
+ neighbor_a = [n for n,l in length.items() if l==1][0]
66
+
67
+ try:
68
+ neighbor_b = [n for n,l in length.items() if l==1][1]
69
+ except:
70
+ # get next nearest neighbor
71
+ neighbor_b = [n for n,l in length.items() if l==2][0]
72
+
73
+ xyz = np.array(mol.GetConformer().GetAtomPosition(node))
74
+ xyz_a = np.array(mol.GetConformer().GetAtomPosition(neighbor_a))
75
+ xyz_b = np.array(mol.GetConformer().GetAtomPosition(neighbor_b))
76
+
77
+ R.append(rot_from_two_vecs(xyz_a-xyz, xyz_b-xyz))
78
+
79
+ return R
80
+
81
  def parse_complex(fn):
82
  try:
83
  name = os.path.basename(fn)
 
112
 
113
  k = 0
114
  token_pos = []
115
+ token_rot = []
116
+
117
+ frames = get_local_frames(mol)
118
+
119
  for i,token in enumerate(masked_tokens):
120
  if token != '':
121
  token_pos.append(tuple(mol.GetConformer().GetAtomPosition(atom_order[k])))
122
+ token_rot.append(frames[atom_order[k]].flatten().tolist())
123
  k += 1
124
  else:
125
  token_pos.append((np.nan, np.nan, np.nan))
126
+ token_rot.append(np.eye(3).flatten().tolist())
127
 
128
+ return name, seq, smi, xyz_receptor, token_pos, token_rot
129
 
130
  except Exception as e:
131
  print(e)
 
141
  comm = MPI.COMM_WORLD
142
  with MPICommExecutor(comm, root=0) as executor:
143
  if executor is not None:
144
+ result = executor.map(parse_complex, filenames, chunksize=32)
145
  result = list(result)
146
  names = [r[0] for r in result if r is not None]
147
  seqs = [r[1] for r in result if r is not None]
148
  all_smiles = [r[2] for r in result if r is not None]
149
  all_xyz_receptor = [r[3] for r in result if r is not None]
150
  all_xyz_ligand = [r[4] for r in result if r is not None]
151
+ all_rot_ligand = [r[5] for r in result if r is not None]
152
 
153
  import pandas as pd
154
+ df = pd.DataFrame({'name': names, 'seq': seqs,
155
+ 'smiles': all_smiles,
156
+ 'receptor_xyz': all_xyz_receptor,
157
+ 'ligand_xyz': all_xyz_ligand,
158
+ 'ligand_rot': all_rot_ligand})
159
+ df.to_parquet('data/pdbbind.parquet',index=False)
pdbbind.slurm CHANGED
@@ -1,9 +1,9 @@
1
  #!/bin/bash
2
  #SBATCH -J preprocess_pdbbind
3
- #SBATCH -p gpu
4
  #SBATCH -A STF006
5
  #SBATCH -t 3:00:00
6
- #SBATCH -N 2
7
- #SBATCH --ntasks-per-node=16
8
 
9
  srun python pdbbind.py
 
1
  #!/bin/bash
2
  #SBATCH -J preprocess_pdbbind
3
+ #SBATCH -p batch
4
  #SBATCH -A STF006
5
  #SBATCH -t 3:00:00
6
+ #SBATCH -N 4
7
+ #SBATCH --ntasks-per-node=8
8
 
9
  srun python pdbbind.py
pdbbind_complexes.py CHANGED
@@ -57,7 +57,7 @@ _URLs = {name: _URL+_file_names[name] for name in _file_names}
57
  class PDBBindComplexes(datasets.ArrowBasedBuilder):
58
  """List of protein sequences, ligand SMILES, and complex coordinates."""
59
 
60
- VERSION = datasets.Version("1.1.0")
61
 
62
  def _info(self):
63
  # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
 
57
  class PDBBindComplexes(datasets.ArrowBasedBuilder):
58
  """List of protein sequences, ligand SMILES, and complex coordinates."""
59
 
60
+ VERSION = datasets.Version("1.2.0")
61
 
62
  def _info(self):
63
  # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset