annotate spring_cross.py @ 41:f316caf098a6 draft default tip

"planemo upload commit 685e1236afde7cf6bb0c9236de06998d2c211dd3"
author guerler
date Mon, 01 Mar 2021 15:02:36 +0000
parents 172398348efd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
1 #! /usr/bin/env python3
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
2 import argparse
39
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
3 from os import mkdir
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
4 from os.path import isdir
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
5
39
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
6 from spring_package.DBKit import DBKit
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
7 from spring_package.Molecule import Molecule
39
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
8 from spring_package.Utilities import getName
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
9
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
10
39
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
11 def hasInterface(mol, chainA, chainB, distance=10.0, contacts=5):
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
12 count = 0
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
13 distance = distance ** 2
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
14 for residueA in mol.calpha[chainA]:
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
15 atomA = mol.calpha[chainA][residueA]
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
16 for residueB in mol.calpha[chainB]:
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
17 atomB = mol.calpha[chainB][residueB]
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
18 dist2 = ((atomA["x"] - atomB["x"]) ** 2 +
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
19 (atomA["y"] - atomB["y"]) ** 2 +
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
20 (atomA["z"] - atomB["z"]) ** 2)
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
21 if dist2 < distance:
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
22 count = count + 1
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
23 if count >= contacts:
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
24 return True
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
25 return False
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
26
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
27
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
28 def main(args):
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
29 logFile = open(args.log, "w")
39
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
30 if not isdir("temp"):
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
31 mkdir("temp")
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
32 pdbCount = 0
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
33 partnerList = set()
39
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
34 entries = set()
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
35 with open(args.index) as file:
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
36 for line in file:
39
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
37 entries.add(getName(line))
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
38 logFile.write("Found %s template entries.\n" % len(entries))
39
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
39 pdbDatabase = DBKit(args.index, args.database)
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
40 for pdb in sorted(entries):
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
41 print("Processing %s" % pdb)
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
42 pdbFile = "temp/temp.pdb"
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
43 pdbDatabaseId = "%s.pdb" % pdb
39
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
44 pdbDatabase.createFile(pdbDatabaseId, pdbFile)
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
45 try:
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
46 mol = Molecule(pdbFile)
39
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
47 except Exception as e:
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
48 logFile.write("Warning: Entry '%s' not found. %s.\n" % (pdbDatabaseId, str(e)))
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
49 continue
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
50 pdbCount = pdbCount + 1
39
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
51 for pdbChain in mol.calpha.keys():
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
52 logFile.write("Processing %s, chain %s.\n" % (pdb, pdbChain))
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
53 logFile.write("Found %d biomolecule(s).\n" % len(mol.biomol.keys()))
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
54 for biomolNumber in mol.biomol:
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
55 logFile.write("Processing biomolecule %d.\n" % biomolNumber)
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
56 bioMolecule = mol.createUnit(biomolNumber)
39
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
57 nChains = len(bioMolecule.calpha.keys())
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
58 if nChains > 1 and pdbChain in bioMolecule.calpha:
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
59 for bioChain in bioMolecule.calpha:
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
60 if bioChain == pdbChain:
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
61 continue
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
62 if hasInterface(bioMolecule, pdbChain, bioChain):
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
63 corePdbChain = "%s_%s" % (pdb.upper(), pdbChain[:1])
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
64 partnerPdbChain = "%s_%s" % (pdb.upper(), bioChain[:1])
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
65 partnerList.add("%s\t%s" % (corePdbChain, partnerPdbChain))
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
66 else:
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
67 logFile.write("Skipping: Chains have no interface [%s, %s].\n" % (pdbChain, bioChain))
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
68 else:
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
69 logFile.write("Skipping: Chain not found or single chain [%s].\n" % pdbChain)
172398348efd "planemo upload commit 26b4018c88041ee0ca7c2976e0a012015173d7b6-dirty"
guerler
parents: 38
diff changeset
70 logFile.flush()
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
71 with open(args.output, 'w') as output_file:
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
72 for entry in sorted(partnerList):
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
73 output_file.write("%s\n" % entry)
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
74
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
75
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
76 if __name__ == "__main__":
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
77 parser = argparse.ArgumentParser(description='List filtering.')
38
80a4b98121b6 "planemo upload commit 22cd6b0fa88ce0ddc4052beab306f5ba10754f12"
guerler
parents: 37
diff changeset
78 parser.add_argument('-i', '--index', help='PDB Database Index file (ffindex)', required=True)
80a4b98121b6 "planemo upload commit 22cd6b0fa88ce0ddc4052beab306f5ba10754f12"
guerler
parents: 37
diff changeset
79 parser.add_argument('-d', '--database', help='PDB Database files (ffdata)', required=True)
37
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
80 parser.add_argument('-o', '--output', help='Output file', required=True)
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
81 parser.add_argument('-g', '--log', help='Log File', required=True)
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
82 args = parser.parse_args()
0be0af9e695d "planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
guerler
parents:
diff changeset
83 main(args)