def __update_many_mol2(inp, suffix, wfn_suffix, g09_suffix, input_type, charges): """ updates many mol2 files at the same time """ from a2mdio.qm import WaveFunction, GaussianLog from a2mdio.molecules import UNITS_TABLE if input_type == 'json': with open(inp) as f: input_contents = json.load(f) elif input_type == 'csv': with open(inp) as f: input_contents = [i.strip() for i in f.readlines()] else: print("unknown format. use either csv or json") sys.exit() for name in input_contents: mm = Mol2(name + '.mol2') wfn = name + wfn_suffix gaussian_log = name + g09_suffix wfn_instance = WaveFunction(file=wfn, prefetch_dm=False, verbose=False) glog = GaussianLog(file=gaussian_log, method='', charges=charges, verbose=False) gdict = glog.read() mm.coordinates = wfn_instance.get_coordinates() * UNITS_TABLE['au']['angstrom'] mm.charges = np.array(gdict['charges'], dtype='float64') mm.write(name + suffix)
def __getitem__(self, item): wfn = WaveFunction(file=self.idx[item], verbose=False) centers = wfn.cent.tolist() sym = wfn.sym.tolist() exp = wfn.exp.tolist() r = torch.tensor(wfn.get_coordinates(), dtype=torch.float) dm = torch.tensor(wfn.density_matrix, dtype=torch.float) return r, centers, exp, sym, dm
def admin_sources(mm, reference, reference_type): if reference_type == 'wfn': reference_d = WaveFunction(verbose=False, file=reference, batch_size=10000) elif reference_type == 'a2md': reference_d = a2md_from_mol(mm) with open(reference) as f: reference_d.read(json.load(f)) else: logger.error("use either wfn or a2md as reference format") sys.exit() return reference_d
def __update_mol2(name, wfn, gaussian_log, output, charges): """ updates a mol2 file using npa charges from gaussian output and coordinates of a wfn """ from a2mdio.qm import WaveFunction, GaussianLog from a2mdio.molecules import UNITS_TABLE mm = Mol2(name) wfn_instance = WaveFunction(file=wfn, prefetch_dm=False, verbose=False) glog = GaussianLog(file=gaussian_log, method='', charges=charges, verbose=False) gdict = glog.read() mm.coordinates = wfn_instance.get_coordinates() * UNITS_TABLE['au']['angstrom'] mm.charges = np.array(gdict['charges'], dtype='float64') mm.write(output)
def dx_add_wfn_charge(name, dx, charge, output): wfn = WaveFunction(file=name, verbose=False, batch_size=1000000) convert2au = lambda x: x*UNITS_TABLE['angstrom']['au'] r3 = UNITS_TABLE['angstrom']['au'] ** 3 fun = lambda x : -wfn.eval(convert2au(x))*r3 dx1 = Volume(filename=dx) dx1.read() dx1.eval(fun) dx2 = Volume(filename=dx) dx2.read() q = dx2._Volume__dx.sum() + charge qt = dx1._Volume__dx.sum() * (dx1.get_basis()[0, 0] ** 3) dx1._Volume__dx = dx1._Volume__dx * (q/ qt) dx1._Volume__dx = -dx1._Volume__dx + dx2._Volume__dx dx1.write(output) return
from a2md.integrate import integrate_density_functional_gradient, dkl_gradient_functional, kullback_leibler_functional from a2md.integrate import integrate_density_functional from a2md.models import a2md_from_mol from a2md.utils import RBFSymmetryCluster from a2mdio.molecules import Mol2 from a2mdio.qm import WaveFunction from a2mdtest.a2mdtests import water from a2md.utils import project from scipy.optimize import minimize if __name__ == '__main__': water_mol2 = Mol2(water.mol2) water_a2md = a2md_from_mol(water_mol2) water_wfn = WaveFunction(file=water.wfn) water_density_sample = np.loadtxt(water.surfaces[1], skiprows=1, delimiter=',') cm = RBFSymmetryCluster(verbose=False) water_a2md.parametrize() water_a2md.clustering(cm.cluster) water_a2md.optimize( training_coordinates=water_density_sample[:, :3], training_density=water_density_sample[:, 3], optimization_mode='restricted' ) n = water_a2md.get_number_optimizable_functions() x = water_a2md.get_unfrozen_integrals() q = np.array(water_a2md.atom_charges).sum() - water_a2md.get_frozen_integrals().sum()
for fx in split_space(water_molecule, fun): integral += pi_lebedev( fun=fx, r_max=15.0, radial_res=100, grid='tight' ) print(integral) print("done") print("TE = {:8.4f}".format(time.time() - START)) START = time.time() water_molecule = Mol2(water.mol2) water_wfn = WaveFunction(file=water.path / "gdb_000003_sto3g.wfn", batch_size=20000) fun = lambda x: water_wfn.eval(x) integral = 0 for fx in split_space(water_molecule, fun): integral += pi_lebedev( fun=fx, r_max=15.0, radial_res=100, grid='medium' ) print(integral) print("done") print("TE = {:8.4f}".format(time.time() - START))