Example #1
0
class EnergyAccumulator:
    """returns energy of each configuration in a dictionary. 
  Keys and their meanings can be found in energy.energy """
    def __init__(self, mol, threshold=10, **kwargs):
        self.mol = mol
        self.threshold = threshold
        if hasattr(mol, "a"):
            print("EnergyAccumulator using Ewald\n", kwargs)
            self.ewald = Ewald(mol, **kwargs)

            def compute_energy(mol, configs, wf, threshold):
                ee, ei, ii = self.ewald.energy(configs)
                ecp_val = energy.get_ecp(mol, configs, wf, threshold)
                ke = energy.kinetic(configs, wf)
                return {
                    "ke": ke,
                    "ee": ee,
                    "ei": ei,
                    "ecp": ecp_val,
                    "total": ke + ee + ei + ecp_val + ii,
                }

            self.compute_energy = compute_energy
        else:
            self.compute_energy = energy.energy

    def __call__(self, configs, wf):
        return self.compute_energy(self.mol, configs, wf, self.threshold)

    def avg(self, configs, wf):
        d = {}
        for k, it in self(configs, wf).items():
            d[k] = np.mean(it, axis=0)
        return d
Example #2
0
 def __init__(self, mol, threshold=10, **kwargs):
     self.mol = mol
     self.threshold = threshold
     if hasattr(mol, "a"):
         ewald = Ewald(mol, **kwargs)
         self.compute_energy = ewald.compute_total_energy
     else:
         self.compute_energy = energy.energy
Example #3
0
    def __init__(self, mol, threshold=10, **kwargs):
        self.mol = mol
        self.threshold = threshold
        if hasattr(mol, "a"):
            self.ewald = Ewald(mol, **kwargs)

            def compute_energy(mol, configs, wf, threshold):
                ee, ei, ii = self.ewald.energy(configs)
                ecp_val = energy.get_ecp(mol, configs, wf, threshold)
                ke = energy.kinetic(configs, wf)
                return {
                    "ke": ke,
                    "ee": ee,
                    "ei": ei,
                    "ecp": ecp_val,
                    "total": ke + ee + ei + ecp_val + ii,
                }

            self.compute_energy = compute_energy
        else:
            self.compute_energy = energy.energy