def psi4mol_to_cppemol(psi4mol): mol = cppe.Molecule() geom = psi4mol.geometry().np for i, c in enumerate(geom): a = cppe.Atom((int(psi4mol.Z(i))), *c) mol.append(a) return mol
def _create_cppe_state(self, mol): cppe_mol = cppe.Molecule() for z, coord in zip(mol.atom_charges(), mol.atom_coords()): cppe_mol.append(cppe.Atom(z, *coord)) def callback(output): logger.info(self, output) cppe_state = cppe.CppeState(self.options, cppe_mol, callback) cppe_state.calculate_static_energies_and_fields() return cppe_state
def molecule(self): """ The HF data a testcase is based upon """ ret = {} for k in self.testcases: datafile = fullfile(k + ".hdf5") f = h5py.File(datafile, 'r') mol = cppe.Molecule() for z, coord in zip(f['atom_charges'], f['atom_coords']): mol.append(cppe.Atom(z, *coord)) ret[k] = mol return ret
def grad_nuclear_field_fdiff(atoms, coords, potentials, step_au=1e-3): """ Computes the finite difference gradient with a 5-point stencil """ natoms = len(atoms) polsites = cppe.get_polarizable_sites(potentials) grad = np.zeros((natoms, 3, len(polsites), 3)) for i in range(natoms): for c in range(3): print("Computing dE/d{} for atom {}.".format(coords_label[c], i)) for f, p in zip(*stencils["5p"]): coords_p = coords.copy() coords_p[i, c] += f * step_au mol_p = cppe.Molecule() for z, coord in zip(atoms, coords_p): mol_p.append(cppe.Atom(z, *coord)) nf = NuclearFields(mol_p, potentials) en_pert = nf.compute().reshape(len(polsites), 3) grad[i, c] += p * en_pert / step_au return grad
def grad_nuclear_interaction_energy_fdiff(atoms, coords, potentials, step_au=1e-3): """ Computes the finite difference gradient with a 5-point stencil """ natoms = len(atoms) grad = np.zeros((natoms, 3)) for i in range(natoms): for c in range(3): print("Computing dE/d{} for atom {}.".format(coords_label[c], i)) for f, p in zip(*stencils["5p"]): coords_p = coords.copy() coords_p[i, c] += f * step_au mol_p = cppe.Molecule() for z, coord in zip(atoms, coords_p): mol_p.append(cppe.Atom(z, *coord)) mexp = MultipoleExpansion(mol_p, potentials) en_pert = mexp.interaction_energy() grad[i, c] += p * en_pert / step_au return grad