Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
dfc9647
FIRE and NSTOVSUT optimization methods added
fcuantico Apr 17, 2025
50a4e1a
FIRE optimizers added
fcuantico Apr 21, 2025
b09befa
First changes to be2_FIRE.py
fcuantico Apr 21, 2025
26d9a5d
First changes to be2_FIRE.py
fcuantico Apr 21, 2025
5a24d17
getting coordinates of molecule line 37
fcuantico Apr 21, 2025
125c87f
adding fire folder and testing backward_euler.py
fcuantico May 6, 2025
46c5e06
last changes not final June 1st
fcuantico Jun 1, 2025
f66687e
gitignore and change to backward_euler.py
fcuantico Jun 17, 2025
c949302
updates to backward_euler.py and test_backward_eluer.py
fcuantico Jun 17, 2025
b63221c
update of backward_euler.py
fcuantico Jun 17, 2025
7d590c4
getting ready for master merge
fcuantico Jun 18, 2025
82565f1
made changes to make sure that pyberny setup works now
jlheflin Jun 18, 2025
ca17edc
ignored editor files
jlheflin Jun 18, 2025
c444367
removed editor files
jlheflin Jun 18, 2025
20719c0
remove Testing folder and cleaned pyberny test file
fcuantico Jun 18, 2025
ae22916
changed pyberny test
fcuantico Jun 18, 2025
374fc9a
Committing clang-format changes
github-actions[bot] Jun 18, 2025
78ca585
Track VSCode settings to prevent automatic rebuilds
fcuantico Jun 18, 2025
8ced491
backward euler and fire completed
fcuantico Jul 2, 2025
c0a830c
Merge branch 'fcuantico-patch-1' of github.com:NWChemEx/StructureFind…
fcuantico Jul 2, 2025
bba231d
Committing clang-format changes
github-actions[bot] Jul 2, 2025
6479618
Committing clang-format changes
github-actions[bot] Jul 2, 2025
83304ff
SAVED BY JACOB backward_euler.py
fcuantico Jul 2, 2025
dd43daf
Committing clang-format changes
github-actions[bot] Jul 2, 2025
8ea88dc
prints tst.xyz
fcuantico Jul 2, 2025
9ebefd0
clean gitignore
fcuantico Jul 2, 2025
b7805c8
file removal
fcuantico Jul 2, 2025
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@

__pycache__/
build/
venv/
.venv/
install/
toolchain.cmake
.vscode/
StructureFinder.code-workspace

2 changes: 2 additions & 0 deletions src/python/structurefinder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from .pyberny import load_pyberny_modules
from .lj_potential.lennard_jones_potential_module import load_lennard_jones_potential
from .fire.backward_euler.backward_euler import load_backwardeulerfire_modules


def load_modules(mm):
Expand All @@ -22,3 +23,4 @@ def load_modules(mm):
"""
load_pyberny_modules(mm)
load_lennard_jones_potential(mm)
load_backwardeulerfire_modules(mm)
13 changes: 13 additions & 0 deletions src/python/structurefinder/fire/__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.
89 changes: 89 additions & 0 deletions src/python/structurefinder/fire/backward_euler/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright 2023 NWChemEx-Project
#
# 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 pluginplay as pp
from simde import EnergyNuclearGradientStdVectorD, TotalEnergy, MoleculeFromString
from berny import Berny, geomlib
import chemist
import numpy as np
import tensorwrapper as tw


class GeomoptViaPyberny(pp.ModuleBase):

def __init__(self):
pp.ModuleBase.__init__(self)
self.satisfies_property_type(TotalEnergy())
self.description("Performs PyBerny optimization")
self.add_submodule(TotalEnergy(), "Energy")
self.add_submodule(EnergyNuclearGradientStdVectorD(), "Gradient")
self.add_submodule(MoleculeFromString(), "StringConv")

def run_(self, inputs, submods):
pt = TotalEnergy()
mol, = pt.unwrap_inputs(inputs)
molecule = mol.molecule

# Convert Chemist Chemical System to XYZ
xyz = ""
xyz += (str(molecule.size()) + "\n\n")
for i in range(molecule.size()):
xyz += (molecule.at(i).name + " " + str(molecule.at(i).x) + " " +
str(molecule.at(i).y) + " " + str(molecule.at(i).z) + "\n")

# Loads the geometry string into the Berny optimizer
# object.
optimizer = Berny(geomlib.loads(xyz, fmt='xyz'))

for geom in optimizer:

# Converts the "Berny" geometry object to Chemical System
geom2xyz = geom.dumps('xyz')
print('Berny Geom to XYZ value: \n' + geom2xyz + '\n')
lines = geom2xyz.split('\n')
print('Lines of geom2xyz: \n' + str(lines) + '\n')
mol_string = '\n'.join(lines[2:])
print('Lines to string: \n' + mol_string + '\n')
xyz2chem_mol = submods["StringConv"].run_as(
MoleculeFromString(), mol_string)
print('String conversion from xyz to chem sys: \n' +
str(xyz2chem_mol.nuclei) + '\n')
geom = chemist.ChemicalSystem(xyz2chem_mol)
print('Chemical system of xyz2chem_mol: \n' +
str(geom.molecule.nuclei) + '\n')
geom_nuclei = geom.molecule.nuclei.as_nuclei()
geom_points = geom_nuclei.charges.point_set

# Main optimizer operation
energy = submods["Energy"].run_as(TotalEnergy(), geom)
print('Interim energy: \n' + str(energy) + '\n')
gradients = submods["Gradient"].run_as(
EnergyNuclearGradientStdVectorD(), geom,
geom_points.as_point_set())
print('Interim gradient: \n' + str(gradients) + '\n')
optimizer.send((energy, gradients))

opt_geom = geom.molecule.nuclei
print(
'Resulting relaxed geometry (assigned to variable opt_geom): \n' +
str(opt_geom))
# Optimized energy is of type "float"
e = tw.Tensor(energy)
print(e)
rv = self.results()
return pt.wrap_results(rv, e)


def load_pyberny_modules(mm):
mm.add_module("PyBerny", GeomoptViaPyberny())
Comment on lines +15 to +89
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import pluginplay as pp
from simde import EnergyNuclearGradientStdVectorD, TotalEnergy, MoleculeFromString
from berny import Berny, geomlib
import chemist
import numpy as np
import tensorwrapper as tw
class GeomoptViaPyberny(pp.ModuleBase):
def __init__(self):
pp.ModuleBase.__init__(self)
self.satisfies_property_type(TotalEnergy())
self.description("Performs PyBerny optimization")
self.add_submodule(TotalEnergy(), "Energy")
self.add_submodule(EnergyNuclearGradientStdVectorD(), "Gradient")
self.add_submodule(MoleculeFromString(), "StringConv")
def run_(self, inputs, submods):
pt = TotalEnergy()
mol, = pt.unwrap_inputs(inputs)
molecule = mol.molecule
# Convert Chemist Chemical System to XYZ
xyz = ""
xyz += (str(molecule.size()) + "\n\n")
for i in range(molecule.size()):
xyz += (molecule.at(i).name + " " + str(molecule.at(i).x) + " " +
str(molecule.at(i).y) + " " + str(molecule.at(i).z) + "\n")
# Loads the geometry string into the Berny optimizer
# object.
optimizer = Berny(geomlib.loads(xyz, fmt='xyz'))
for geom in optimizer:
# Converts the "Berny" geometry object to Chemical System
geom2xyz = geom.dumps('xyz')
print('Berny Geom to XYZ value: \n' + geom2xyz + '\n')
lines = geom2xyz.split('\n')
print('Lines of geom2xyz: \n' + str(lines) + '\n')
mol_string = '\n'.join(lines[2:])
print('Lines to string: \n' + mol_string + '\n')
xyz2chem_mol = submods["StringConv"].run_as(
MoleculeFromString(), mol_string)
print('String conversion from xyz to chem sys: \n' +
str(xyz2chem_mol.nuclei) + '\n')
geom = chemist.ChemicalSystem(xyz2chem_mol)
print('Chemical system of xyz2chem_mol: \n' +
str(geom.molecule.nuclei) + '\n')
geom_nuclei = geom.molecule.nuclei.as_nuclei()
geom_points = geom_nuclei.charges.point_set
# Main optimizer operation
energy = submods["Energy"].run_as(TotalEnergy(), geom)
print('Interim energy: \n' + str(energy) + '\n')
gradients = submods["Gradient"].run_as(
EnergyNuclearGradientStdVectorD(), geom,
geom_points.as_point_set())
print('Interim gradient: \n' + str(gradients) + '\n')
optimizer.send((energy, gradients))
opt_geom = geom.molecule.nuclei
print(
'Resulting relaxed geometry (assigned to variable opt_geom): \n' +
str(opt_geom))
# Optimized energy is of type "float"
e = tw.Tensor(energy)
print(e)
rv = self.results()
return pt.wrap_results(rv, e)
def load_pyberny_modules(mm):
mm.add_module("PyBerny", GeomoptViaPyberny())

The contents in this file are just copy/paste from elsewhere. Everything but the license header can be deleted.

Loading
Loading