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
29 changes: 15 additions & 14 deletions src/relentless/optimize/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,21 +585,22 @@ def _calc_ensemble_average_dvar_gradient(self, trajectory, variables):
filter_j_gt_i = neighbors[:, 1] > neighbors[:, 0]
neighbors.filter(filter_j_gt_i)
# pair contributions to the gradient
for i in self.potentials.pair.types:
for j in self.potentials.pair.types:
filter_ij = numpy.logical_and(
type_masks[i][neighbors[:, 0]],
type_masks[j][neighbors[:, 1]],
)
for var in variables:
gradient[var] += numpy.sum(
self.potentials.pair.derivative(
(i, j), var, x=neighbors.distances[filter_ij]
)
if self.potentials.pair is not None:
for i in self.potentials.pair.types:
for j in self.potentials.pair.types:
filter_ij = numpy.logical_and(
type_masks[i][neighbors[:, 0]],
type_masks[j][neighbors[:, 1]],
)
for var in variables:
gradient[var] += numpy.sum(
self.potentials.pair.derivative(
(i, j), var, x=neighbors.distances[filter_ij]
)
)

# bond contributions to the gradient
if snap.bonds.N != 0:
if self.potentials.bond is not None:
bond_type_map = {
type: i for i, type in enumerate(self.potentials.bond.types)
}
Expand All @@ -624,7 +625,7 @@ def _calc_ensemble_average_dvar_gradient(self, trajectory, variables):
)

# angle contributions to the gradient
if snap.angles.N != 0:
if self.potentials.angle is not None:
angle_type_map = {
type: i for i, type in enumerate(self.potentials.angle.types)
}
Expand Down Expand Up @@ -657,7 +658,7 @@ def _calc_ensemble_average_dvar_gradient(self, trajectory, variables):
)

# dihedral contributions to the gradient
if snap.dihedrals.N != 0:
if self.potentials.dihedral is not None:
dihedral_type_map = {
type: i for i, type in enumerate(self.potentials.dihedral.types)
}
Expand Down