-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauxclass.py
49 lines (36 loc) · 1.28 KB
/
auxclass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 10/03/2022 7:51PM
# MolGraph, Query
# graph class from https://medium.com/geekculture/how-to-represent-a-graph-data-structure-in-python-9f0df57e33a2
# undirected, weighted graph
class MolGraph:
def __init__(self, mol2mol):
self.graph = dict()
for atom in mol2mol.atoms:
self.graph[atom.AtInd] = []
for bond in mol2mol.bonds:
self.graph[bond.BdAt1].append((bond.BdAt2, bond.BdType))
self.graph[bond.BdAt2].append((bond.BdAt1, bond.BdType))
def isbonded(self,a1,a2):
return a2.AtInd in [x[0] for x in self.graph[a1.AtInd]]
def isbondedby(self,a1,a2,btype):
return (a2.AtInd,btype) in self.graph[a1.AtInd]
def countbond(self,a,btype):
return len([x for x in self.graph[a.AtInd] if x[1]==btype])
def returnbonds(self,a):
return self.graph[a.AtInd]
# expected query
# ATOM C.2
# CONN H 1
# CONN C.3 1
# CONN O.2 2
class Query:
def __init__(self, specs):
self.atype = ''
self.bonded = []
for line in specs:
if len(line.split()) > 0:
items = line.split()
if items[0] == 'ATOM':
self.atype = items[1]
if items[0] == 'CONN':
self.bonded.append((items[1],items[2]))