Skip to content

Commit

Permalink
detailed ewald results
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmet kaymak committed May 30, 2024
1 parent 937d972 commit c0f77e0
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions matscipy/calculators/ewald/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ def determine_nk(charge, cell, acc, a, natoms):
[nxmax / cell[0, 0], nymax / cell[1, 1], nzmax / cell[2, 2]]
)
scaled_nbk = np.dot(np.array(np.abs(cell)), vector)
nxmax = max(1, np.int(scaled_nbk[0]))
nymax = max(1, np.int(scaled_nbk[1]))
nzmax = max(1, np.int(scaled_nbk[2]))
nxmax = max(1, np.int32(scaled_nbk[0]))
nymax = max(1, np.int32(scaled_nbk[1]))
nzmax = max(1, np.int32(scaled_nbk[2]))

return kmax, np.array([nxmax, nymax, nzmax])

Expand Down Expand Up @@ -451,7 +451,8 @@ def calculate(self, atoms, properties, system_changes):
self.reset_kspace(atoms)

super().calculate(atoms, properties, system_changes)

self.results["real_ewald_en"] = self.results["energy"]
self.results["real_ewald_f"] = self.results["forces"]
nb_atoms = len(atoms)
charge_n = atoms.get_array("charge")

Expand All @@ -460,23 +461,28 @@ def calculate(self, atoms, properties, system_changes):
alpha = self.alpha

# Energy

e_self = self.self_energy(charge_n, alpha)
e_long = self.kspace_energy(
charge_n, atoms.get_positions(), atoms.get_volume(), I_l, k_lc
)
self.results["self_ewald_en"] = e_self
self.results["kspace_ewald_en"] = e_long

self.results["energy"] += e_self + e_long
self.results["free_energy"] += e_self + e_long

# Forces
self.results["forces"] += self.first_derivative_kspace(
kspace_f = self.first_derivative_kspace(
charge_n,
nb_atoms,
atoms.get_volume(),
atoms.get_positions(),
I_l,
k_lc,
)
# Forces
self.results["forces"] += kspace_f

self.results["kspace_ewald_f"] = kspace_f

# Virial
self.results["stress"] += (
Expand Down

0 comments on commit c0f77e0

Please sign in to comment.