├── README.md
├── rdsim.py
├── LICENSE
├── rdmin.py
├── applysdfcoordstopdb.py
├── alignmcs.py
├── uffminimize.py
├── flipchiral.py
├── shape.py
├── extractmatch.py
├── extractmatches.py
├── corerxnscaffold.py
├── clustermatches.py
├── rdconf.py
├── rdallconf.py
└── pains.py
/README.md:
--------------------------------------------------------------------------------
1 | # rdkit-scripts
--------------------------------------------------------------------------------
/rdsim.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import sys,string,argparse
4 | from rdkit.Chem import AllChem as Chem
5 | from optparse import OptionParser
6 | import os, gzip
7 | from rdkit import DataStructs
8 |
9 | parser = argparse.ArgumentParser(description='Compute similarity to query ligand')
10 | parser.add_argument('query',metavar='query ligand')
11 | parser.add_argument('test',metavar='test ligands')
12 |
13 | args = parser.parse_args()
14 |
15 | query = open(args.query).readline().split()[0].replace('$','')
16 | qmol = Chem.MolFromSmiles(query)
17 | qfp = Chem.RDKFingerprint(qmol)
18 |
19 | for line in open(args.test):
20 | try:
21 | smi = line.split()[0].replace('$','')
22 | mol = Chem.MolFromSmiles(smi)
23 | fp = Chem.RDKFingerprint(mol)
24 | print smi,DataStructs.FingerprintSimilarity(qfp,fp)
25 | except:
26 | pass #ignore rdkit errors
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 David Koes
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/rdmin.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | from rdkit.Chem import AllChem as Chem
3 | import numpy as np
4 | import sys, gzip, re
5 |
6 | rname = sys.argv[1]
7 | lname = sys.argv[2]
8 | rec = Chem.MolFromPDBFile(rname)
9 |
10 | if lname.endswith('.gz'):
11 | lig = next(Chem.ForwardSDMolSupplier(gzip.open(lname),sanitize=False))
12 | else:
13 | lig = next(Chem.SDMolSupplier(sys.argv[2],sanitize=False))
14 |
15 | complex = Chem.CombineMols(rec,lig)
16 | Chem.SanitizeMol(complex)
17 |
18 | ff = Chem.UFFGetMoleculeForceField(complex,ignoreInterfragInteractions=False)
19 | print("Before:",ff.CalcEnergy())
20 |
21 | for p in range(rec.GetNumAtoms()):
22 | ff.AddFixedPoint(p)
23 |
24 | ff.Minimize()
25 |
26 | print("After:",ff.CalcEnergy())
27 |
28 | cpos = complex.GetConformer().GetPositions()
29 | conf = lig.GetConformer()
30 | for (i,xyz) in enumerate(cpos[-lig.GetNumAtoms():]):
31 | conf.SetAtomPosition(i,xyz)
32 |
33 | m = m = re.search(r'(.*)_(\d+).sdf(.gz)?',lname)
34 | if m:
35 | outname = '%s_rec_uff_%s.sdf.gz'%(m.group(1),m.group(2))
36 | else:
37 | outname = lname.replace('.gz','').replace('.sdf','')+'_rec_uff.sdf.gz'
38 | outfile = gzip.open(outname,'wt')
39 | out = Chem.SDWriter(outfile)
40 | out.write(lig)
41 | out.close()
42 | outfile.close()
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/applysdfcoordstopdb.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | '''Given a pdb file and an sdf file of the same ligand, find the correspondance
4 | between the atoms and output a pdb with the same atom names as the pdb input
5 | but with the coordinates of the sdf file. Atoms missing in the sdf
6 | will not have their coordinates changed, but note that hydrogens are stripped'''
7 |
8 | import sys
9 | from rdkit.Chem import AllChem
10 |
11 | if len(sys.argv) != 3:
12 | print "Need sdf and pdb files"
13 | sys.exit(1)
14 |
15 | sdf = sys.argv[1]
16 | pdb = sys.argv[2]
17 |
18 | #figure out starting atom number
19 | startnum = 1
20 | for line in open(pdb):
21 | if line.startswith('ATOM') or line.startswith('HETATM'):
22 | startnum = int(line[6:11])
23 | break
24 |
25 | pmol = AllChem.MolFromPDBFile(pdb)
26 | smol = AllChem.SDMolSupplier("newsnappy.sdf").next()
27 | pmol = AllChem.AssignBondOrdersFromTemplate(smol,pmol)
28 |
29 | if smol.HasSubstructMatch(pmol):
30 | m = smol.GetSubstructMatch(pmol)
31 | pconf = pmol.GetConformer()
32 | sconf = smol.GetConformer()
33 | for (pi, si) in enumerate(m):
34 | pconf.SetAtomPosition(pi, sconf.GetAtomPosition(si))
35 | pdbout = AllChem.MolToPDBBlock(pmol, flavor=2).split('\n')
36 | num = startnum
37 | for line in pdbout:
38 | if line.startswith('ATOM') or line.startswith('HETATM'):
39 | print '%s%5d%s' % (line[:6],num,line[11:])
40 | num += 1
41 | else:
42 | print "Could not matchup pdb and sdf"
43 | sys.exit(1)
44 |
--------------------------------------------------------------------------------
/alignmcs.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import argparse, sys, rdkit, collections
4 | from rdkit.Chem import AllChem as Chem
5 | from rdkit.Chem import rdMolAlign
6 | from rdkit.Chem.rdMolAlign import AlignMol
7 | from rdkit.Chem import rdMolAlign
8 | from rdkit.Chem import rdFMCS
9 | from rdkit.Chem import rdMolTransforms
10 |
11 | if __name__ == "__main__":
12 | parser = argparse.ArgumentParser(description='Align query molecules to a reference molecule using their maximum common substructure. May produce multiple alignments per an input.')
13 | parser.add_argument('ref',help='Reference SDF file for comparison')
14 | parser.add_argument('query',help="SDF file to compare with")
15 | parser.add_argument('out',help='Output SDF')
16 | parser.add_argument('-s','--strict',action='store_true',help='Use strict atom/bond matching')
17 | args = parser.parse_args()
18 |
19 | #load reference file molecules
20 | refmols = [mol for mol in Chem.SDMolSupplier(args.ref)]
21 |
22 | if len(refmols) > 1:
23 | print("Only using first reference molecule")
24 | refmol = refmols[0]
25 |
26 | out = Chem.SDWriter(args.out)
27 | for mol in Chem.SDMolSupplier(args.query):
28 | if args.strict:
29 | mcs = rdFMCS.FindMCS([refmol,mol])
30 | else:
31 | mcs = rdFMCS.FindMCS([refmol,mol],atomCompare=rdFMCS.AtomCompare.CompareAny,bondCompare=rdFMCS.BondCompare.CompareAny)
32 |
33 | submol = Chem.MolFromSmarts(mcs.smartsString)
34 |
35 | for refmatch in refmol.GetSubstructMatches(submol):
36 | for qmatch in mol.GetSubstructMatches(submol):
37 | AlignMol(mol, refmol, atomMap=list(zip(qmatch,refmatch)))
38 | out.write(mol)
39 |
--------------------------------------------------------------------------------
/uffminimize.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 |
3 | import sys,string
4 | from rdkit.Chem import AllChem as Chem
5 | from optparse import OptionParser
6 |
7 | #minimize sdf structures with the UFF forcefiled and rdkit
8 |
9 | parser = OptionParser(usage="Usage: %prog [options] .sdf