Skip to content

Commit 37ea75c

Browse files
committed
Select the rate rules to average based on the norm distance
Previously, we were using a distance algorithm that choose the manhattan distance. Now we move to use the Euclidian norm distance instead in hopes of decreasing the usage of very general nodes
1 parent 36008b1 commit 37ea75c

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

rmgpy/data/kinetics/rules.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,25 @@ def __getAverageKinetics(self, kineticsList):
550550
E0 = (E0*0.001,"kJ/mol"),
551551
)
552552
return averagedKinetics
553+
554+
def calculateNormDistance(self, template, otherTemplate):
555+
"""
556+
Calculate the norm distance squared between two rate rules with
557+
`template` and `otherTemplate`. The norm distance is
558+
a^2 + b^2 + c^2 .... when a is the distance between the nodes in the
559+
first tree, b is the distance between the nodes in the second tree, etc.
560+
"""
561+
562+
# Do it the stupid way first and calculate distances from the top
563+
# rather than from each other for now... it's dumb but need to see results first
564+
import numpy
565+
depth = numpy.array([len(self.ancestors(node)) for node in template])
566+
otherDepth = numpy.array([len(self.ancestors(otherNode)) for otherNode in otherTemplate])
553567

568+
distance = numpy.array(depth-otherDepth)
569+
norm = numpy.dot(distance,distance)
570+
return norm
571+
554572
def estimateKinetics(self, template, degeneracy=1):
555573
"""
556574
Determine the appropriate kinetics for a reaction with the given
@@ -573,7 +591,18 @@ def getTemplateLabel(template):
573591
kineticsList.append([kinetics, t])
574592

575593
if len(kineticsList) > 0:
576-
594+
595+
if len(kineticsList) > 1:
596+
# First, let's cull any pairs that have a longer norm distance than the other
597+
norms = [self.calculateNormDistance(template, t) for kinetics,t in kineticsList]
598+
#for kinetics, t in kineticsList:
599+
# norm = self.calculateNormDistance(template, t)
600+
# norms.append(norm)
601+
minNorm = min(norms)
602+
603+
604+
kineticsList = [pair for pair, norm in zip(kineticsList,norms) if norm == min(norms)]
605+
577606
if len(kineticsList) == 1:
578607
kinetics, t = kineticsList[0]
579608
# Check whether the exact rate rule for the original template (most specific

0 commit comments

Comments
 (0)