Skip to content

Commit

Permalink
refactor to make code robust
Browse files Browse the repository at this point in the history
  • Loading branch information
CunliangGeng committed Jan 29, 2020
1 parent 2e6b0c1 commit dcfb195
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions iScore/function/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
class iscore(object):

def __init__(self,graphrank_out='GraphRank.dat', energy_out='Energy.dat',
weights = [-0.941,0.041,0.217,0.032],normalize_graph_rank = True):
weights = [-0.941,0.041,0.217,0.032], normalize_graph_rank = True):

self.graphrank_out = graphrank_out
self.energy_out = energy_out
self.weights = weights
self.normalize_graph_rank = normalize_graph_rank

self.features = dict()
# must read graphrank first and then energy
# Read and check, remove problematic molecule
self.read_graphrank()
self.read_energy()
self.check_mol_features()

if self.normalize_graph_rank:
self.normalize_graphrank()
self.score()
self.print()

Expand Down Expand Up @@ -50,20 +53,21 @@ def read_graphrank(self):
self.features[mol] = dict()
self.features[mol]['grank'] = float(l[-1])

if self.normalize_graph_rank:
def normalize_graphrank(self):
"""Normalize graphRank values"""

data = []
mol = self.features.keys()
data = []
mol = self.features.keys()

for m in mol:
data.append(self.features[m]['grank'])
for m in mol:
data.append(self.features[m]['grank'])

data = self._normalize(data)
data = self._normalize(data)

i = 0
for m in mol:
self.features[m]['grank'] = data[i]
i+= 1
i = 0
for m in mol:
self.features[m]['grank'] = data[i]
i+= 1

def check_mol_features(self):
"""Check and remove molecules without enough features"""
Expand Down

0 comments on commit dcfb195

Please sign in to comment.