Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
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
2 changes: 2 additions & 0 deletions src/python/structurefinder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
# limitations under the License.

from .pyberny import load_pyberny_modules
from .lj_potential.lennard_jones_potential_module import load_lenard_jones_potential


def load_modules(mm):
"""
Loads the collection of all modules provided by StructureFinder.
"""
load_pyberny_modules(mm)
load_Lenard_Jones_potential(mm)
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2025 NWChemEx Community
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
"""
@author: Felix Rojas
"""

import numpy as np
import pluginplay as pp
from simde import TotalEnergy


class LennardJonesPotential(pp.ModuleBase):
# Module Construct --------------------------------------------------------
def __init__(self):
"""
This module Evaluates the Lennard-Jones 1D potential function (E)
"""
pp.ModuleBase.__init__(self)
self.description("Lennard-Jones 1D potential function")
self.satisfies_property_type(TotalEnergy())

#--------------------------------------------------------------------------

# Module run_ member function ---------------------------------------------
def run_(self, inputs, submods):
"""
Parameters
----------
inputs : Diatomic distance,
TYPE ---> Float

Returns
-------
E: Lennard-Jonnes 1D potential Energy,
TYPE ---> Float
"""
pt = TotalEnergy()
chem_sys, = pt.unwrap_inputs(inputs)
mol = chem_sys.molecule
coor_0 = np.array([mol.at(0).x, mol.at(0).y, mol.at(0).z])
coor_1 = np.array([mol.at(1).x, mol.at(1).y, mol.at(1).z])
#----------------------------------------------------------------------
assert (mol.size() == 2) #<--- To check molcule size contains 2-atoms
#----------------------------------------------------------------------
r = np.linalg.norm(coor_0 - coor_1)
#-------------- LENNARD-JONES FUNCTION --------------------------------
E = 4 * ((1 / r**12) - (1 / r**6))
#------------- ANALYTIC FORCE -----------------------------------------
DE_x = -24 * ((2 / r**13) - (1 / r**7))
FC = -DE_x
#----------------------------------------------------------------------
rv = self.results()
return pt.wrap_results(rv, E)

#--------------------------------------------------------------------------


def load_lenard_jones_potential(mm):
mm.add_module("Lenard-Jones", LennardJonesPotential())
13 changes: 13 additions & 0 deletions tests/python/unit_tests/test_lennard_jones_potential/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2025 NWChemEx Community
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2024 NWChemEx Community
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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 structurefinder
import nwchemex
import pluginplay as pp
import chemist
import unittest
from simde import TotalEnergy


class TestLennardJonesPotential(unittest.TestCase):

def test_lennard_jones_potential(self):
result = self.mm.run_as(TotalEnergy(), "Lenard-Jones",
chemist.ChemicalSystem(self.mol))
self.assertEqual(result, -1.0)

def setUp(self):
self.mm = pp.ModuleManager()
structurefinder.load_modules(self.mm)
self.mol = chemist.Molecule()
self.mol.push_back(chemist.Atom("H", 1, 1.0079, 0.0, 0.0, 0.0))
self.mol.push_back(chemist.Atom("H", 1, 1.0079, 0.0, 0.0, 2**(1 / 6)))
Loading