Skip to content

Commit

Permalink
Switch to L-BFGS and fixup GFN-FF parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Oct 24, 2023
1 parent 3c58251 commit 857c54e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion avogadro/qtplugins/forcefield/forcefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ void Forcefield::optimize()
bool isInteractive = m_molecule->undoMolecule()->isInteractive();
m_molecule->undoMolecule()->setInteractive(true);

cppoptlib::ConjugatedGradientDescentSolver<EnergyCalculator> solver;
cppoptlib::LbfgsSolver<EnergyCalculator> solver;
// cppoptlib::ConjugatedGradientDescentSolver<EnergyCalculator> solver;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

int n = m_molecule->atomCount();

Expand Down
8 changes: 5 additions & 3 deletions avogadro/qtplugins/forcefield/scriptenergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ Real ScriptEnergy::value(const Eigen::VectorXd& x)
double energy = 0.0;
for (auto line : lines) {
if (line.startsWith("AvogadroEnergy:")) {
QStringList items = line.split(" ");
if (items.size() > 1)
QStringList items = line.split(" ", QString::SkipEmptyParts);
if (items.size() > 1) {
energy = items[1].toDouble();
break;
}
}
}

Expand Down Expand Up @@ -163,7 +165,7 @@ void ScriptEnergy::gradient(const Eigen::VectorXd& x, Eigen::VectorXd& grad)
}

if (readingGrad) {
QStringList items = line.split(" ");
QStringList items = line.split(" ", QString::SkipEmptyParts);
if (items.size() == 3) {
grad[i] = items[0].toDouble();
grad[i + 1] = items[1].toDouble();
Expand Down
2 changes: 1 addition & 1 deletion avogadro/qtplugins/forcefield/scripts/gfn1.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def run(filename):
while(True):
# read new coordinates from stdin
for i in range(len(atoms)):
coordinates[i] = np.fromstring(input(), sep=" ")
coordinates[i] = np.fromstring(input())
# .. convert from Angstrom to Bohr
coordinates /= 0.52917721067

Expand Down
2 changes: 1 addition & 1 deletion avogadro/qtplugins/forcefield/scripts/gfn2.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def run(filename):
while(True):
# read new coordinates from stdin
for i in range(len(atoms)):
coordinates[i] = np.fromstring(input(), sep=" ")
coordinates[i] = np.fromstring(input())
# .. convert from Angstrom to Bohr
coordinates /= 0.52917721067

Expand Down
4 changes: 2 additions & 2 deletions avogadro/qtplugins/forcefield/scripts/gfnff.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def run(filename):
while True:
# read new coordinates from stdin
for i in range(len(atoms)):
coordinates[i] = np.fromstring(input(), sep=" ")
coordinates[i] = np.fromstring(input())
# .. convert from Angstrom to Bohr
coordinates /= 0.52917721067

Expand All @@ -80,7 +80,7 @@ def run(filename):
# now print the gradient
# .. we don't want the "[]" in the output
print("AvogadroGradient:")
grad = res.get_gradient() * 496100.475 # convert units
grad = res.get_gradient() * 4961.475 # convert units
output = np.array2string(grad)
output = output.replace("[", "").replace("]", "")
print(output)
Expand Down

0 comments on commit 857c54e

Please sign in to comment.