pyscf.tools package#
Submodules#
pyscf.tools.c60struct module#
pyscf.tools.chgcar module#
Vasp CHGCAR file format
See also https://cms.mpi.univie.ac.at/vasp/vasp/CHGCAR_file.html
- class pyscf.tools.chgcar.CHGCAR(cell, nx=60, ny=60, nz=60, resolution=None, margin=3.0)[source]#
Bases:
Cube
Read-write of the Vasp CHGCAR files
- pyscf.tools.chgcar.density(cell, outfile, dm, nx=60, ny=60, nz=60, resolution=None)[source]#
Calculates electron density and write out in CHGCAR format.
- Args:
- cellMole or Cell object
Mole or pbc Cell. If Mole object is given, the program will guess a cubic lattice for the molecule.
- outfilestr
Name of Cube file to be written.
- dmndarray
Density matrix of molecule.
- Kwargs:
- nxint
Number of grid point divisions in x direction. Note this is function of the molecule’s size; a larger molecule will have a coarser representation than a smaller one for the same value.
- nyint
Number of grid point divisions in y direction.
- nzint
Number of grid point divisions in z direction.
- Returns:
No return value. This function outputs a VASP chgcarlike file (with phase if desired)…it can be opened in VESTA or VMD or many other softwares
Examples:
>>> # generates the first MO from the list of mo_coefficents >>> from pyscf.pbc import gto, scf >>> from pyscf.tools import chgcar >>> cell = gto.M(atom='H 0 0 0; H 0 0 1', a=numpy.eye(3)*3) >>> mf = scf.RHF(cell).run() >>> chgcar.density(cell, 'h2.CHGCAR', mf.make_rdm1())
- pyscf.tools.chgcar.orbital(cell, outfile, coeff, nx=60, ny=60, nz=60, resolution=None)[source]#
Calculate orbital value on real space grid and write out in CHGCAR format.
- Args:
- cellMole or Cell object
Mole or pbc Cell. If Mole object is given, the program will guess a cubic lattice for the molecule.
- outfilestr
Name of Cube file to be written.
- dmndarray
Density matrix of molecule.
- Kwargs:
- nxint
Number of grid point divisions in x direction. Note this is function of the molecule’s size; a larger molecule will have a coarser representation than a smaller one for the same value.
- nyint
Number of grid point divisions in y direction.
- nzint
Number of grid point divisions in z direction.
- Returns:
No return value. This function outputs a VASP chgcarlike file (with phase if desired)…it can be opened in VESTA or VMD or many other softwares
Examples:
>>> # generates the first MO from the list of mo_coefficents >>> from pyscf.pbc import gto, scf >>> from pyscf.tools import chgcar >>> cell = gto.M(atom='H 0 0 0; H 0 0 1', a=numpy.eye(3)*3) >>> mf = scf.RHF(cell).run() >>> chgcar.orbital(cell, 'h2_mo1.CHGCAR', mf.mo_coeff[:,0])
pyscf.tools.chkfile_util module#
- pyscf.tools.chkfile_util.dump_mo(filename, key='scf')[source]#
Read scf/mcscf information from chkfile, then dump the orbital coefficients.
pyscf.tools.cubegen module#
Gaussian cube file format. Reference: http://paulbourke.net/dataformats/cube/ https://h5cube-spec.readthedocs.io/en/latest/cubeformat.html http://gaussian.com/cubegen/
The output cube file has the following format
Comment line Comment line N_atom Ox Oy Oz # number of atoms, followed by the coordinates of the origin N1 vx1 vy1 vz1 # number of grids along each axis, followed by the step size in x/y/z direction. N2 vx2 vy2 vz2 # … N3 vx3 vy3 vz3 # … Atom1 Z1 x y z # Atomic number, charge, and coordinates of the atom … # … AtomN ZN x y z # … Data on grids # (N1*N2) lines of records, each line has N3 elements
- class pyscf.tools.cubegen.Cube(mol, nx=80, ny=80, nz=80, resolution=None, margin=3.0, origin=None, extent=None)[source]#
Bases:
object
Read-write of the Gaussian CUBE files
- Attributes:
- nxint
Number of grid point divisions in x direction. Note this is function of the molecule’s size; a larger molecule will have a coarser representation than a smaller one for the same value. Conflicts to keyword resolution.
- nyint
Number of grid point divisions in y direction.
- nzint
Number of grid point divisions in z direction.
- resolution: float
Resolution of the mesh grid in the cube box. If resolution is given in the input, the input nx/ny/nz have no effects. The value of nx/ny/nz will be determined by the resolution and the cube box size. The unit is Bohr.
- pyscf.tools.cubegen.density(mol, outfile, dm, nx=80, ny=80, nz=80, resolution=None, margin=3.0)[source]#
Calculates electron density and write out in cube format.
- Args:
- molMole
Molecule to calculate the electron density for.
- outfilestr
Name of Cube file to be written.
- dmndarray
Density matrix of molecule.
- Kwargs:
- nxint
Number of grid point divisions in x direction. Note this is function of the molecule’s size; a larger molecule will have a coarser representation than a smaller one for the same value. Conflicts to keyword resolution.
- nyint
Number of grid point divisions in y direction.
- nzint
Number of grid point divisions in z direction.
- resolution: float
Resolution of the mesh grid in the cube box. If resolution is given in the input, the input nx/ny/nz have no effects. The value of nx/ny/nz will be determined by the resolution and the cube box size.
- pyscf.tools.cubegen.mep(mol, outfile, dm, nx=80, ny=80, nz=80, resolution=None, margin=3.0)[source]#
Calculates the molecular electrostatic potential (MEP) and write out in cube format.
- Args:
- molMole
Molecule to calculate the electron density for.
- outfilestr
Name of Cube file to be written.
- dmndarray
Density matrix of molecule.
- Kwargs:
- nxint
Number of grid point divisions in x direction. Note this is function of the molecule’s size; a larger molecule will have a coarser representation than a smaller one for the same value. Conflicts to keyword resolution.
- nyint
Number of grid point divisions in y direction.
- nzint
Number of grid point divisions in z direction.
- resolution: float
Resolution of the mesh grid in the cube box. If resolution is given in the input, the input nx/ny/nz have no effects. The value of nx/ny/nz will be determined by the resolution and the cube box size.
- pyscf.tools.cubegen.orbital(mol, outfile, coeff, nx=80, ny=80, nz=80, resolution=None, margin=3.0)[source]#
Calculate orbital value on real space grid and write out in cube format.
- Args:
- molMole
Molecule to calculate the electron density for.
- outfilestr
Name of Cube file to be written.
- coeff1D array
coeff coefficient.
- Kwargs:
- nxint
Number of grid point divisions in x direction. Note this is function of the molecule’s size; a larger molecule will have a coarser representation than a smaller one for the same value. Conflicts to keyword resolution.
- nyint
Number of grid point divisions in y direction.
- nzint
Number of grid point divisions in z direction.
- resolution: float
Resolution of the mesh grid in the cube box. If resolution is given in the input, the input nx/ny/nz have no effects. The value of nx/ny/nz will be determined by the resolution and the cube box size.
pyscf.tools.dump_mat module#
- pyscf.tools.dump_mat.dump_mo(mol, c, label=None, ncol=5, digits=5, start=0)[source]#
Format print for orbitals
- Args:
- stdoutfile object
eg sys.stdout, or stdout = open(‘/path/to/file’) or mol.stdout if mol is an object initialized from
gto.Mole
- cnumpy.ndarray
Orbitals, each column is an orbital
- Kwargs:
- labellist of strings
Row labels (default is AO labels)
Examples:
>>> from pyscf import gto >>> mol = gto.M(atom='C 0 0 0') >>> mo = numpy.eye(mol.nao_nr()) >>> dump_mo(mol, mo) #0 #1 #2 #3 #4 #5 #6 #7 #8 0 C 1s 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0 C 2s 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0 C 3s 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0 C 2px 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0 C 2py 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0 C 2pz 0.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0 C 3px 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0 C 3py 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.00 0 C 3pz 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00
- pyscf.tools.dump_mat.dump_rec(stdout, c, label=None, label2=None, ncol=5, digits=5, start=0)[source]#
Print an array in rectangular format
- Args:
- stdoutfile object
eg sys.stdout, or stdout = open(‘/path/to/file’) or mol.stdout if mol is an object initialized from
gto.Mole
- cnumpy.ndarray
coefficients
- Kwargs:
- labellist of strings
Row labels (default is 1,2,3,4,…)
- label2list of strings
Col labels (default is 1,2,3,4,…)
- ncolint
Number of columns in the format output (default 5)
- digitsint
Number of digits of precision for floating point output (default 5)
- startint
The number to start to count the index (default 0)
Examples:
>>> import sys, numpy >>> dm = numpy.eye(3) >>> dump_rec(sys.stdout, dm) #0 #1 #2 0 1.00000 0.00000 0.00000 1 0.00000 1.00000 0.00000 2 0.00000 0.00000 1.00000 >>> from pyscf import gto >>> mol = gto.M(atom='C 0 0 0') >>> dm = numpy.eye(mol.nao_nr()) >>> dump_rec(sys.stdout, dm, label=mol.ao_labels(), ncol=9, digits=2) #0 #1 #2 #3 #4 #5 #6 #7 #8 0 C 1s 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0 C 2s 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0 C 3s 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0 C 2px 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0 C 2py 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0 C 2pz 0.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0 C 3px 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0 C 3py 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.00 0 C 3pz 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00
- pyscf.tools.dump_mat.dump_tri(stdout, c, label=None, ncol=5, digits=5, start=0)[source]#
Format print for the lower triangular part of an array
- Args:
- stdoutfile object
eg sys.stdout, or stdout = open(‘/path/to/file’) or mol.stdout if mol is an object initialized from
gto.Mole
- cnumpy.ndarray
coefficients
- Kwargs:
- labellist of strings
Row labels (default is 1,2,3,4,…)
- ncolint
Number of columns in the format output (default 5)
- digitsint
Number of digits of precision for floating point output (default 5)
- startint
The number to start to count the index (default 0)
Examples:
>>> import sys, numpy >>> dm = numpy.eye(3) >>> dump_tri(sys.stdout, dm) #0 #1 #2 0 1.00000 1 0.00000 1.00000 2 0.00000 0.00000 1.00000 >>> from pyscf import gto >>> mol = gto.M(atom='C 0 0 0') >>> dm = numpy.eye(mol.nao_nr()) >>> dump_tri(sys.stdout, dm, label=mol.ao_labels(), ncol=9, digits=2) #0 #1 #2 #3 #4 #5 #6 #7 #8 0 C 1s 1.00 0 C 2s 0.00 1.00 0 C 3s 0.00 0.00 1.00 0 C 2px 0.00 0.00 0.00 1.00 0 C 2py 0.00 0.00 0.00 0.00 1.00 0 C 2pz 0.00 0.00 0.00 0.00 0.00 1.00 0 C 3px 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0 C 3py 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0 C 3pz 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00
pyscf.tools.fcidump module#
FCIDUMP functions (write, read) for real Hamiltonian
- pyscf.tools.fcidump.from_chkfile(filename, chkfile, tol=1e-15, float_format=' %.16g', molpro_orbsym=False, orbsym=None)[source]#
Read SCF results from PySCF chkfile and transform 1-electron, 2-electron integrals using the SCF orbitals. The transformed integrals is written to FCIDUMP
- Kwargs:
- molpro_orbsym (bool): Whether to dump the orbsym in Molpro orbsym
convention as documented in https://www.molpro.net/info/current/doc/manual/node36.html
- pyscf.tools.fcidump.from_integrals(filename, h1e, h2e, nmo, nelec, nuc=0, ms=0, orbsym=None, tol=1e-15, float_format=' %.16g')[source]#
Convert the given 1-electron and 2-electron integrals to FCIDUMP format
- pyscf.tools.fcidump.from_mcscf(mc, filename, tol=1e-15, float_format=' %.16g', molpro_orbsym=False)[source]#
Use the given MCSCF object to obtain the CAS 1-electron and 2-electron integrals and dump them to FCIDUMP.
- Kwargs:
tol (float): Threshold for writing elements to FCIDUMP float_format (str): Float format for writing elements to FCIDUMP molpro_orbsym (bool): Whether to dump the orbsym in Molpro orbsym
convention as documented in https://www.molpro.net/manual/doku.php?id=general_program_structure#symmetry
- pyscf.tools.fcidump.from_mo(mol, filename, mo_coeff, orbsym=None, tol=1e-15, float_format=' %.16g', molpro_orbsym=False, ms=0)[source]#
Use the given MOs to transform the 1-electron and 2-electron integrals then dump them to FCIDUMP.
- Kwargs:
- molpro_orbsym (bool): Whether to dump the orbsym in Molpro orbsym
convention as documented in https://www.molpro.net/info/current/doc/manual/node36.html
- pyscf.tools.fcidump.from_scf(mf, filename, tol=1e-15, float_format=' %.16g', molpro_orbsym=False)[source]#
Use the given SCF object to transform the 1-electron and 2-electron integrals then dump them to FCIDUMP.
- Kwargs:
- molpro_orbsym (bool): Whether to dump the orbsym in Molpro orbsym
convention as documented in https://www.molpro.net/info/current/doc/manual/node36.html
- pyscf.tools.fcidump.read(filename, molpro_orbsym=False, verbose=True)[source]#
Parse FCIDUMP. Return a dictionary to hold the integrals and parameters with keys: H1, H2, ECORE, NORB, NELEC, MS, ORBSYM, ISYM
- Kwargs:
- molpro_orbsym (bool): Whether the orbsym in the FCIDUMP file is in
Molpro orbsym convention as documented in:
https://www.molpro.net/info/current/doc/manual/node36.html
In return, orbsym is converted to pyscf symmetry convention
verbose (bool): Whether to print debugging information
- pyscf.tools.fcidump.scf_from_fcidump(mf, filename, molpro_orbsym=False)[source]#
Update the SCF object with the quantities defined in FCIDUMP file
pyscf.tools.finite_diff module#
Finite difference driver
- class pyscf.tools.finite_diff.GradScanner(g)[source]#
Bases:
GradScanner
- class pyscf.tools.finite_diff.Gradients(method)[source]#
Bases:
GradientsBase
- as_scanner()[source]#
Generating a nuclear gradients scanner/solver (for geometry optimizer).
The returned solver is a function. This function requires one argument “mol” as input and returns energy and first order nuclear derivatives.
The solver will automatically use the results of last calculation as the initial guess of the new calculation. All parameters assigned in the nuc-grad object and SCF object (DIIS, conv_tol, max_memory etc) are automatically applied in the solver.
Note scanner has side effects. It may change many underlying objects (_scf, with_df, with_x2c, …) during calculation.
Examples:
>>> from pyscf import gto, scf, grad >>> mol = gto.M(atom='H 0 0 0; F 0 0 1') >>> hf_scanner = scf.RHF(mol).apply(grad.RHF).as_scanner() >>> e_tot, grad = hf_scanner(gto.M(atom='H 0 0 0; F 0 0 1.1')) >>> e_tot, grad = hf_scanner(gto.M(atom='H 0 0 0; F 0 0 1.5'))
- displacement = 0.01#
- kernel()[source]#
Kernel function is the main driver of a method. Every method should define the kernel function as the entry of the calculation. Note the return value of kernel function is not strictly defined. It can be anything related to the method (such as the energy, the wave-function, the DFT mesh grids etc.).
- class pyscf.tools.finite_diff.Hessian(method)[source]#
Bases:
HessianBase
- displacement = 0.01#
- kernel()[source]#
Kernel function is the main driver of a method. Every method should define the kernel function as the entry of the calculation. Note the return value of kernel function is not strictly defined. It can be anything related to the method (such as the energy, the wave-function, the DFT mesh grids etc.).
- pyscf.tools.finite_diff.kernel(method, displacement=0.01)[source]#
Evaluate gradients or Hessians for a given method using finite difference approximation.
- Args:
- method (callable):
The function for which the gradient or Hessian is to be computed.
- Kwargs:
- displacement:
The small change for finite difference calculations. Default is 1e-2.
- Returns:
An (n, 3) array for gradients or (n, n, 3, 3) array for hessian, depending on the given method.
pyscf.tools.mo_mapping module#
- pyscf.tools.mo_mapping.mo_1to1map(s)[source]#
Given <i|j>, search for the 1-to-1 mapping between i and j.
- Returns:
a list [j-close-to-i for i in <bra|]
- pyscf.tools.mo_mapping.mo_comps(aolabels_or_baslst, mol, mo_coeff, cart=False, orth_method='meta_lowdin')[source]#
Given AO(s), show how the AO(s) are distributed in MOs.
- Args:
- aolabels_or_baslstfilter function or AO labels or AO index
If it’s a function, the AO indices are the items for which the function return value is true.
- Kwargs:
- cartbool
whether the orbital coefficients are based on cartesian basis.
- orth_methodstr
The localization method to generated orthogonal AO upon which the AO contribution are computed. It can be one of ‘meta_lowdin’, ‘lowdin’ or ‘nao’.
- Returns:
A list of float to indicate the total contributions (normalized to 1) of localized AOs
Examples:
>>> from pyscf import gto, scf >>> from pyscf.tools import mo_mapping >>> mol = gto.M(atom='H 0 0 0; F 0 0 1', basis='6-31g') >>> mf = scf.RHF(mol).run() >>> comp = mo_mapping.mo_comps('F 2s', mol, mf.mo_coeff) >>> print('MO-id F-2s components') >>> for i,c in enumerate(comp): ... print('%-3d %.10f' % (i, c)) MO-id components 0 0.0000066344 1 0.8796915532 2 0.0590259826 3 0.0000000000 4 0.0000000000 5 0.0435028851 6 0.0155889103 7 0.0000000000 8 0.0000000000 9 0.0000822361 10 0.0021017982
pyscf.tools.molden module#
- pyscf.tools.molden.from_mo(mol, filename, mo_coeff, spin='Alpha', symm=None, ene=None, occ=None, ignore_h=True)[source]#
Dump the given MOs in Molden format
- pyscf.tools.molden.from_scf(mf, filename, ignore_h=True)[source]#
Dump the given SCF object in Molden format
- pyscf.tools.molden.orbital_coeff(mol, fout, mo_coeff, spin='Alpha', symm=None, ene=None, occ=None, ignore_h=True)[source]#
- pyscf.tools.molden.parse(moldenfile, verbose=0)#
Extract mol and orbitals from molden file
- pyscf.tools.molden.read(moldenfile, verbose=0)#
Extract mol and orbitals from molden file
- pyscf.tools.molden.remove_high_l(mol, mo_coeff=None)[source]#
Remove high angular momentum (l >= 5) functions before dumping molden file. If molden function raised error message
RuntimeError l=5 is not supported
, you can use this function to format orbitals.Note the formated orbitals may have normalization problem. Some visualization tool will complain about the orbital normalization error.
Examples:
>>> mol1, orb1 = remove_high_l(mol, mf.mo_coeff) >>> molden.from_mo(mol1, outputfile, orb1)
pyscf.tools.qcschema module#
This lib loads results that are in a QCSchema format json. Funcs below can recreate the mol and scf objects from the info in the json.
- pyscf.tools.qcschema.load_qcschema_go_final_json(file_name)[source]#
- Does: loads qcschema format geometry optimization json
and returns only the optimized ‘final’ geometry qcschema info as a dictionary.
- Input:
file_name: qcschema format json file
Returns: dict in qcschema format
- pyscf.tools.qcschema.load_qcschema_hessian(qcschema_dict)[source]#
Does: loads hessian from qcschema format dictionary Input:
qcschema_dict
Returns: hessian with format (N,N,3,3)
- pyscf.tools.qcschema.load_qcschema_json(file_name)[source]#
Does: loads qcschema format json into a dictionary Input:
file_name: qcschema format json file
Returns: dict in qcschema format
- pyscf.tools.qcschema.load_qcschema_molecule(qcschema_dict, to_Angstrom=False, xyz=False, mol_select=1, step=0)[source]#
- Does: Loads molecule from qcschema format dict.
Molecule may be single point molecule or from a geometry optimization/trajectory.
- Input:
syms: atom symbols (qcschema format) coords: x y z coordinates (in qcschema format) mol_select: specifies which molecule to load from qcschema format results.
Default loads ‘molecule’ from qcschema. Geometry optimizations or trajectories have mutliple geometries saved in the schema. mol_select = 1 (default) molecule from standard qcschema format
= 2 initial_molecule in GO or traj qcschema = 3 final_molecule in GO or traj qcschema = 4 a specific step in the GO or traj qcschema, specify with ‘step’ arg.
- step: for geometry optimization or trajectory, which have multiple molecules in a qcschema output.
This specifies which step to load the molecule from.
to_Angstrom (optional): convert coordinates to Angstrom (default is Bohr) xyz (optional): controls output (see below)
- Returns:
xyz=False (default): ‘atom x y z’ format string xyz=True: output a string in xyz file format
i.e. first line is number of atoms.
- pyscf.tools.qcschema.load_qcschema_scf_info(qcschema_dict)[source]#
Does: loads scf info from qcschema format dictionary Input:
qcschema_dict
- Returns:
scf_dict: contains the relevent scf info only
pyscf.tools.ring module#
pyscf.tools.wfn_format module#
GAMESS WFN File format