openmm / openmm_workshops

32 stars 10 forks source link

Improve readability of custom force expressions #8

Closed jmichel80 closed 3 months ago

jmichel80 commented 1 year ago

In the US tutorial

code like this

custom_nb_force = mm.CustomNonbondedForce('4*epsilon*((sigma/r)^12-(sigma/r)^6); sigma=0.5*(sigma1+sigma2); epsilon=sqrt(epsilon1*epsilon2)')

would be more readable if the string passed to the constructor is constructed step by step. e.g.

custom_lj = '4*epsilon*((sigma/r)^12-(sigma/r)^6);'
custom_lj += 'sigma=0.5*(sigma1+sigma2);'
custom_lj += 'epsilon=sqrt(epsilon1*epsilon2)'
custom_nb_force = mm.CustomNonbondedForce(custom_lj)