Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/python/structurefinder/lj_potential/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,55 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
import plugandplay as pp
from simde import TotalEnergy

class LJ_potential(pp.ModuleBase):
# Module Construct --------------------------------------------------------
def __init__(self):
"""
This module Evaluates the Lennard-Jones 1D potential function (E), and
calculates minus the gradient (Force) in Cartesian coordinates,
according to the relation
FC = - dE/dx
"""
pp.ModuleBase.__init__(self)
self.description("Lennard-Jones 1D potential function")
self.satisfies_property_type(TotalEnergy())
#--------------------------------------------------------------------------

# Module run_ member function ---------------------------------------------
def run_(self, inputs):
"""
Parameters
----------
inputs : x-coordinate,
TYPE ---> Float
Returns
-------
E: Lennard-Jonnes 1D potential Energy,
TYPE ---> Float
FC: Force in cartesian coordinates evaluated at the given input,
acording to the relation
FC = - dE/dx
TYPE ---> Float
"""
pt = TotalEnergy()
x0 = pt.unwrap_inputs(inputs)
#-------------- LENNARD-JONES FUNCTION --------------------------------
E = lambda x: 4*((1/x**12)-(1/x**6))
#------------- ANALYTIC FORCE -----------------------------------------
DE_x = -24*((2/x0**13)-(1/x0**7))
FC = -DE_x
#----------------------------------------------------------------------
rv = self.results()
return pt.wrap_results(rv, E,FC)
#--------------------------------------------------------------------------

def load_Lenard_Jones_potential(mm):
mm.add_module("Lenard-Jones", LJ_potential())