Open ahy3nz opened 5 years ago
I wonder if we can get sympy
to intelligently compare functions that are similar but not quite exact, like the case of harmonic bond potentials sometimes having a 1/2 coefficient and sometimes having it wrapped into the force constant.
>>> func1 = sympy.sympify('0.5 * k * (r-r0)**2')
>>> func2 = sympy.sympify('k * (r-r0)**2')
>>> func1
0.5*k*(r - r0)**2
>>> func2
k*(r - r0)**2
>>> small_k = 500
>>> big_k = 1000
>>> func1.subs({'k': small_k})
250.0*(r - r0)**2
>>> func1.subs({'k': small_k})
250.0*(r - r0)**2
>>> func1.subs({'k': big_k})
500.0*(r - r0)**2
>>> func2.subs({'k': small_k})
500*(r - r0)**2
>>> subs_1 = func1.subs({'k': big_k})
>>> subs_2 = func2.subs({'k': small_k})
>>> subs_1
500.0*(r - r0)**2
>>> subs_2
500*(r - r0)**2
>>> subs_1 == subs_2
True
>>> func1 == func2
False
It looks like if you substitute 'k' into the sympy.functions, it looks like equality can be compared. but if you compare the non-substituted sympy.functions, you won't get equality
Different engine formats and external packages have slightly different functions, which will affect the resultant parameters for I/O:
Bond potentials
BondType
Angle potentials
AngleType
Dihedral potentials
Potential Templates