def read_geom(filename: str, verb=0): """Very simple wrapper for iodata load_one. Parameters ---------- filename A string that contains the path to an input file. verb Verbosity level integer flag. Returns ------- mol An IOdata molecule object. Raises ------ readereerror If the file is not found. """ path = os.path.abspath(filename) try: assert os.path.exists(path) assert os.path.isfile(path) except: raise readererror("Could not load the file {0}.".format(path)) mol = load_one(path) if verb > 1: print("File loaded using IOData.") if verb > 2: pp.pprint(mol) return mol
def atom_coordinates_iodata(sdf_name): r"""Load atomic coordinates from a sdf file with iodata. Parameters ---------- sdf_name : string SDF file name. Returns ------- coords : ndarray 3D atomic coordinates. """ mol = load_one(sdf_name) coords = mol.atcoords return coords
def read_one(filename: str, verb=0): """Very simple wrapper for iodata load_one. Parameters ---------- filename A string that contains the path to an input file. verb Verbosity level integer flag. Returns ------- mol An IOdata molecule object. Raises ------ readereerror If the file is not found or is not a file, or does not contain the basis set information needed to calculate the one-particle density matrix etc. """ path = os.path.abspath(filename) try: assert os.path.exists(path) assert os.path.isfile(path) except: raise readererror("Could not load the file {0}.".format(path)) mol = load_one(path) try: mol.mo.coeffsa except: raise readererror( "Basis set coefficients were not understood or are not present.") if verb > 1: print("File loaded using IOData.") if verb > 2: pprint(mol) return mol
def write_orbitals(self, filename='None'): # Assign filename depending if it is given as an input # or if it has to be generated from the elements. if filename == 'None': filename = '../data/molden-fchk_files/' + self.scheme[ 0] + '/' + self.generate_molname() else: filename = '../data/molden-fchk_files/' + filename # Write out the molden file using psi4 psi4.molden(self.model.wavefunction, filename + '.molden') # Using IOData, we load in the molden file. We alter the # values of the coefficients using the localized coefficients. # Finally we write them out to a FCHK file and remove the molden file molecule = load_one(filename + '.molden') molecule_mo = molecule.mo mo_coeffs = molecule_mo.coeffs # replace the occupied orbital coefficients with the localized ones. self.L_occ = np.dot(self.C_occ, self.W) mo_coeffs[:, :self.N_occ] = self.L_occ molecule_mo.coeffs = mo_coeffs dump_one(molecule, filename + '.fchk') os.remove(filename + '.molden')
def test_from_iodata(): """Test gbasis.wrapper.from_iodata.""" pytest.importorskip("iodata") from iodata import load_one mol = load_one(find_datafile("data_iodata_water_sto3g_hf_g03.fchk")) basis, coord_types = from_iodata(mol) assert coord_types == ["cartesian"] * 5 assert all(isinstance(i, GeneralizedContractionShell) for i in basis) assert basis[0].angmom == 0 assert np.allclose(basis[0].coord, mol.atcoords[0]) assert np.allclose(basis[0].exps, np.array([130.7093214, 23.80886605, 6.443608313])) assert np.allclose( basis[0].coeffs, np.array([0.1543289673, 0.5353281423, 0.4446345422]).reshape(-1, 1)) assert np.allclose(basis[0].norm_cont, 1.0) assert basis[1].angmom == 0 assert np.allclose(basis[1].coord, mol.atcoords[0]) assert np.allclose(basis[1].exps, np.array([5.033151319, 1.169596125, 0.3803889600])) assert np.allclose( basis[1].coeffs, np.array([-0.09996722919, 0.3995128261, 0.7001154689]).reshape(-1, 1)) assert np.allclose(basis[1].norm_cont, 1.0) assert basis[2].angmom == 1 assert np.allclose(basis[2].coord, mol.atcoords[0]) assert np.allclose(basis[2].exps, np.array([5.033151319, 1.169596125, 0.3803889600])) assert np.allclose( basis[2].coeffs, np.array([0.1559162750, 0.6076837186, 0.3919573931]).reshape(-1, 1)) assert np.allclose(basis[2].norm_cont, 1.0) assert basis[3].angmom == 0 assert np.allclose(basis[3].coord, mol.atcoords[1]) assert np.allclose(basis[3].exps, np.array([3.425250914, 0.6239137298, 0.1688554040])) assert np.allclose( basis[3].coeffs, np.array([0.1543289673, 0.5353281423, 0.4446345422]).reshape(-1, 1)) assert np.allclose(basis[3].norm_cont, 1.0) assert basis[4].angmom == 0 assert np.allclose(basis[4].coord, mol.atcoords[2]) assert np.allclose(basis[4].exps, np.array([3.425250914, 0.6239137298, 0.1688554040])) assert np.allclose( basis[4].coeffs, np.array([0.1543289673, 0.5353281423, 0.4446345422]).reshape(-1, 1)) assert np.allclose(basis[4].norm_cont, 1.0) # Artificially change angular momentum. # The following few lines are commented out deliberately. The file # "data_iodata_water_sto3g_hf_g03.fchk" does not contain "spherical" # functions for angular momenta 0 and 1, so there is no need to have # conventions for them. (This is a fairly common pattern in most QC codes.) # -- BEGIN COMMENTED ASSERTS # basis[2].angmom = 0 # assert basis[2].angmom_components_sph == (0,) # basis[2].angmom = 1 # assert basis[2].angmom_components_sph == (1, -1, 0) # -- END COMMENTED ASSERTS basis[2].angmom = 2 assert basis[2].angmom_components_sph == ("c0", "c1", "s1", "c2", "s2") basis[2].angmom = 3 assert basis[2].angmom_components_sph == ("c0", "c1", "s1", "c2", "s2", "c3", "s3") # NOTE: you shouldn't actually change the magnetic quantum number that is not compatible with # the angular momentum, but we do so here to check that user input is accepted mol.obasis.conventions[(0, "p")] = ["c1"] basis, coord_types = from_iodata(mol) basis[2].angmom = 0 assert coord_types == ["cartesian"] * 5 assert basis[2].angmom_components_sph == ("c1", ) assert np.allclose(basis[2].norm_cont, 1.0) mol.obasis.conventions[(1, "p")] = ["c1", "c0", "s1"] basis, coord_types = from_iodata(mol) basis[2].angmom = 1 assert coord_types == ["cartesian"] * 5 assert basis[2].angmom_components_sph == ("c1", "c0", "s1") assert np.allclose(basis[2].norm_cont, 1.0) mol.obasis.conventions[(1, "c")] = ["z", "y", "x"] basis, coord_types = from_iodata(mol) basis[2].angmom = 1 assert np.allclose(np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]), basis[2].angmom_components_cart) # Test Cartesian convention generation for missing angmom # Needed for cases when only spherical basis is used in basis set del mol.obasis.conventions[(1, "c")] basis, coord_types = from_iodata(mol) basis[2].angmom = 1 assert np.allclose(np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]), basis[2].angmom_components_cart) with pytest.raises(ValueError): basis[2].angmom = 10 basis[2].angmom_components_sph with pytest.raises(ValueError): mol.obasis = mol.obasis._replace(primitive_normalization="L1") basis, coord_types = from_iodata(mol)
import pytest from gbasis.integrals.point_charge import point_charge_integral from Alchemical_tools import Alchemical_tools import pylibxc from gbasis.evals.density import evaluate_density from gbasis.evals.eval import evaluate_basis from gbasis.integrals.electron_repulsion import electron_repulsion_integral from grid.onedgrid import GaussChebyshev from grid.rtransform import BeckeTF from grid.utils import get_cov_radii from grid.atomic_grid import AtomicGrid from grid.molgrid import MolGrid from iodata import load_one from gbasis.wrappers import from_iodata molecule = load_one("h2o.fchk") basis = from_iodata(molecule) q = np.array([0.1]) R = np.array([[2.574156, -0.181816, -2.453822]]) alc_hf = Alchemical_tools( basis, molecule, point_charge_positions=R, point_charges_values=q, coord_type="cartesian", k="HF", ) r0 = 1e-10 radii = get_cov_radii(molecule.atnums) n_rad_points = 100 deg = 5
def test_from_iodata(): """Test gbasis.wrapper.from_iodata.""" pytest.importorskip("iodata") from iodata import load_one mol = load_one(find_datafile("data_iodata_water_sto3g_hf_g03.fchk")) basis = from_iodata(mol) assert all(isinstance(i, GeneralizedContractionShell) for i in basis) assert basis[0].angmom == 0 assert np.allclose(basis[0].coord, mol.atcoords[0]) assert np.allclose(basis[0].exps, np.array([130.7093214, 23.80886605, 6.443608313])) assert np.allclose( basis[0].coeffs, np.array([0.1543289673, 0.5353281423, 0.4446345422]).reshape(-1, 1)) assert basis[1].angmom == 0 assert np.allclose(basis[1].coord, mol.atcoords[0]) assert np.allclose(basis[1].exps, np.array([5.033151319, 1.169596125, 0.3803889600])) assert np.allclose( basis[1].coeffs, np.array([-0.09996722919, 0.3995128261, 0.7001154689]).reshape(-1, 1)) assert basis[2].angmom == 1 assert np.allclose(basis[2].coord, mol.atcoords[0]) assert np.allclose(basis[2].exps, np.array([5.033151319, 1.169596125, 0.3803889600])) assert np.allclose( basis[2].coeffs, np.array([0.1559162750, 0.6076837186, 0.3919573931]).reshape(-1, 1)) assert basis[3].angmom == 0 assert np.allclose(basis[3].coord, mol.atcoords[1]) assert np.allclose(basis[3].exps, np.array([3.425250914, 0.6239137298, 0.1688554040])) assert np.allclose( basis[3].coeffs, np.array([0.1543289673, 0.5353281423, 0.4446345422]).reshape(-1, 1)) assert basis[4].angmom == 0 assert np.allclose(basis[4].coord, mol.atcoords[2]) assert np.allclose(basis[4].exps, np.array([3.425250914, 0.6239137298, 0.1688554040])) assert np.allclose( basis[4].coeffs, np.array([0.1543289673, 0.5353281423, 0.4446345422]).reshape(-1, 1)) with pytest.raises(ValueError): basis[2].angmom_components_sph # pylint: disable=W0104 # artificially change angular momentum basis[2].angmom = 2 assert basis[2].angmom_components_sph == (0, 1, -1, 2, -2) basis[2].angmom = 3 assert basis[2].angmom_components_sph == (0, 1, -1, 2, -2, 3, -3) with pytest.raises(ValueError): mol.obasis = mol.obasis._replace(primitive_normalization="L1") basis = from_iodata(mol)
def test_from_iodata(): """Test gbasis.wrapper.from_iodata.""" pytest.importorskip("iodata") from iodata import load_one mol = load_one(find_datafile("data_iodata_water_sto3g_hf_g03.fchk")) basis = from_iodata(mol) assert all(isinstance(i, GeneralizedContractionShell) for i in basis) assert basis[0].angmom == 0 assert np.allclose(basis[0].coord, mol.atcoords[0]) assert np.allclose(basis[0].exps, np.array([130.7093214, 23.80886605, 6.443608313])) assert np.allclose( basis[0].coeffs, np.array([0.1543289673, 0.5353281423, 0.4446345422]).reshape(-1, 1)) assert basis[1].angmom == 0 assert np.allclose(basis[1].coord, mol.atcoords[0]) assert np.allclose(basis[1].exps, np.array([5.033151319, 1.169596125, 0.3803889600])) assert np.allclose( basis[1].coeffs, np.array([-0.09996722919, 0.3995128261, 0.7001154689]).reshape(-1, 1)) assert basis[2].angmom == 1 assert np.allclose(basis[2].coord, mol.atcoords[0]) assert np.allclose(basis[2].exps, np.array([5.033151319, 1.169596125, 0.3803889600])) assert np.allclose( basis[2].coeffs, np.array([0.1559162750, 0.6076837186, 0.3919573931]).reshape(-1, 1)) assert basis[3].angmom == 0 assert np.allclose(basis[3].coord, mol.atcoords[1]) assert np.allclose(basis[3].exps, np.array([3.425250914, 0.6239137298, 0.1688554040])) assert np.allclose( basis[3].coeffs, np.array([0.1543289673, 0.5353281423, 0.4446345422]).reshape(-1, 1)) assert basis[4].angmom == 0 assert np.allclose(basis[4].coord, mol.atcoords[2]) assert np.allclose(basis[4].exps, np.array([3.425250914, 0.6239137298, 0.1688554040])) assert np.allclose( basis[4].coeffs, np.array([0.1543289673, 0.5353281423, 0.4446345422]).reshape(-1, 1)) # artificially change angular momentum basis[2].angmom = 0 assert basis[2].angmom_components_sph == (0, ) basis[2].angmom = 1 assert basis[2].angmom_components_sph == (1, -1, 0) basis[2].angmom = 2 assert basis[2].angmom_components_sph == (0, 1, -1, 2, -2) basis[2].angmom = 3 assert basis[2].angmom_components_sph == (0, 1, -1, 2, -2, 3, -3) # NOTE: you shouldn't actually change the magnetic quantum number that is not compatible with # the angular momentum, but we do so here to check that user input is accepted mol.obasis.conventions[(0, "p")] = ["sc1"] basis = from_iodata(mol) basis[2].angmom = 0 assert basis[2].angmom_components_sph == (1, ) mol.obasis.conventions[(1, "p")] = ["pc1", "pc0", "ps1"] basis = from_iodata(mol) basis[2].angmom = 1 assert basis[2].angmom_components_sph == (1, 0, -1) with pytest.raises(ValueError): basis[2].angmom = -1 basis[2].angmom_components_sph with pytest.raises(ValueError): mol.obasis = mol.obasis._replace(primitive_normalization="L1") basis = from_iodata(mol)