### Configure C/C++ Compilation in setup.py Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/contributing.rst Example of how to configure the `setup.py` file to include C/C++ source files for compilation within a PySCF extension. ```python SO_EXTENSIONS = { 'pyscf.new_feature.new_feature': ['pyscf/new_feature/new_feature.cc'] } ``` -------------------------------- ### Run PySCF Docker Container with IPython Shell Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md Starts a Docker container with a PySCF environment and launches an IPython shell. This allows for command-line interaction with PySCF within a pre-configured environment. ```bash docker run -it pyscf/pyscf:latest start.sh ipython ``` -------------------------------- ### Compile and Install External Libraries for Offline PySCF Installation Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md This section provides the bash commands to compile and install the downloaded external libraries (libcint, Libxc, XCFun) into a specified directory (e.g., /opt). It involves creating build directories, configuring with CMake, and running make for compilation and installation. ```bash tar xvzf libcint.tar.gz cd libcint mkdir build && cd build cmake -DWITH_F12=1 -DWITH_RANGE_COULOMB=1 -DWITH_COULOMB_ERF=1 \ -DCMAKE_INSTALL_PREFIX:PATH=/opt -DCMAKE_INSTALL_LIBDIR:PATH=lib .. make && make install tar xvzf libxc-6.0.0.tar.gz cd libxc-6.0.0 mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=1 \ -DENABLE_FORTRAN=0 -DDISABLE_KXC=0 -DDISABLE_LXC=1 \ -DCMAKE_INSTALL_PREFIX:PATH=/opt -DCMAKE_INSTALL_LIBDIR:PATH=lib .. make && make install tar xvzf xcfun.tar.gz cd xcfun-cmake-3.5 mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=1 -DXCFUN_MAX_ORDER=3 -DXCFUN_ENABLE_TESTS=0 \ -DCMAKE_INSTALL_PREFIX:PATH=/opt -DCMAKE_INSTALL_LIBDIR:PATH=lib .. make && make install ``` -------------------------------- ### Example: Gamma Point Post-HF Calculation in PBC Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/pbc/mix_mol.rst This example demonstrates how to perform a post-Hartree-Fock calculation on a gamma-point system within the PySCF framework, leveraging its PBC capabilities. It shows the setup for a calculation that requires specific integral handling. ```python from pyscf.pbc import gto, dft from pyscf.pbc.df import DF from pyscf.pyscf_utils import * # noqa cell = gto.Cell() cell.atom = ''' O 0. 0. 0. H 0. 74. 0. 47 H 0. -0.74. 0. 47 ''' cell.basis = 'sto-3g' cell.a = ''' 10. 0. 0. 0. 10. 0. 0. 0. 10. ''' cell.build() mf = dft.RKS(cell) mf.xc = 'lda,vwn' mf.kernel() # Example of using a post-HF method (e.g., MP2) # from pyscf.pbc.mp import MP2 # mp = MP2(mf) # mp.kernel() print('Calculation finished.') ``` -------------------------------- ### 1D System PBC DFT with Semi-local XC Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/pbc/dft-settings.md Configures a 1D (wire) Periodic Boundary Condition (PBC) DFT calculation using a pseudopotential and a semi-local XC functional. This example simulates a 1D system by using a 2D setup with large vacuum dimensions along the non-periodic axes and recommends MultiGridNumInt. ```python import pyscf import numpy as np cell = pyscf.M(dimension=2, a=np.diag([3.6, 15, 15]), pseudo='gth-pbe', basis='gth-dzvp') kmesh = [2, 1, 1] # Example k-point mesh mf = cell.KRKS(xc='pbe', kpts=cell.make_kpts(kmesh)) mf = mf.multigrid_numint() # Recommended for efficiency mf.run() ``` -------------------------------- ### Install PySCF with binary preference Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md This command installs PySCF using a binary wheel, which can help avoid build errors related to missing dependencies like `cmake`. This is recommended when encountering issues during source compilation. ```bash pip install --prefer-binary pyscf ``` -------------------------------- ### Install pytblis for optimized einsum backend Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md This code installs the `pytblis` package, which provides an optimized backend for `numpy.einsum` operations. TBLIS can significantly improve tensor contraction performance compared to the default NumPy implementation. PySCF automatically detects and utilizes `pytblis` once installed. ```bash pip install pytblis ``` -------------------------------- ### Download External Libraries for Offline PySCF Installation Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md This section details how to download necessary external libraries (libcint, Libxc, XCFun) for an offline installation of PySCF. These commands assume a Linux/macOS environment and use git and wget for downloading. ```bash git clone https://github.com/sunqm/libcint.git tar czf libcint.tar.gz libcint wget https://gitlab.com/libxc/libxc/-/archive/6.0.0/libxc-6.0.0.tar.gz wget -O xcfun.tar.gz https://github.com/fishjojo/xcfun/archive/refs/tags/cmake-3.5.tar.gz ``` -------------------------------- ### Example: k-point sampling for KRHF/KRKS and Newton Solver (Python) Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/modules/pbc/scf.rst This code snippet is intended to demonstrate the usage of k-points for KRHF and KRKS calculations, along with the Newton (second-order SCF) solver within the PySCF library for periodic systems. The specific implementation details are found in the referenced example file. ```python import numpy from pyscf.pbc import gto, scf # Placeholder for the actual code from the example file # The following lines are illustrative and not the complete code. # cell = gto.M(atom='H 0 0 0; H 0 0 1', basis='sto3g', # h=numpy.eye(3)*3, gs=[10]*3, kpts=[[0,0,0],[0.5,0,0]]) # mf = scf.KRHF(cell).run() ``` -------------------------------- ### Initialize Git Repository for Extension Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/contributing.rst Commands to initialize a new Git repository for an extension project, add all files, and make an initial commit. ```bash git init git add . git commit -m "An example of new extension package" ``` -------------------------------- ### Build PySCF from source manually Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md Manually installs PySCF by cloning the repository and building the C extensions using CMake and make. This method requires specific build prerequisites and manual configuration of the PYTHONPATH. ```bash git clone https://github.com/pyscf/pyscf.git cd pyscf cd pyscf/lib mkdir build cd build cmake .. make ``` ```bash export PYTHONPATH=/opt/pyscf:$PYTHONPATH ``` ```bash python -c "import pyscf; print(pyscf.__version__)" ``` -------------------------------- ### Install PySCF Documentation Dependencies Source: https://github.com/pyscf/pyscf.github.io/blob/master/README.md Installs the required Python packages for building the PySCF documentation. These packages include PySCF itself, Sphinx for documentation generation, and various Sphinx extensions for themes, parsing, and notebooks. ```bash pip install pyscf sphinx sphinxcontrib-bibtex nbsphinx pydata-sphinx-theme myst-parser sphinx_design ``` -------------------------------- ### Initialize and Run FCI Solver in PySCF Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Demonstrates initializing a direct spin-1 FCI solver and running the kernel function with different electron and orbital configurations. The FCI solver can handle various numbers of electrons and spin states. ```python from pyscf import fci fs = fci.direct_spin1.FCI() # direct_spin0 instead for singlet system ground states e, fcivec = fs.kernel(h1e, h2e, N, 8) # 8 electrons in N orbitals e, fcivec = fs.kernel(h1e, h2e, N, (5,4)) # (5 alpha, 4 beta) electrons e, fcivec = fs.kernel(h1e, h2e, N, (3,1)) # (3 alpha, 1 beta) electrons ``` -------------------------------- ### Generate Density and Transition Density Matrices with FCI Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Shows how to generate 1-electron density matrices (spin-traced and spin-resolved) and 1-electron transition density matrices using an FCI solver. These functions require the FCI coefficients, number of orbitals, and electron configuration. ```python from pyscf import fci # Assuming fs is an initialized FCI solver and fcivec, fcivec0, fcivec1 are FCI coefficients # N is the number of orbitals rdm1 = fs.make_rdm1(fcivec, N, (5, 4)) # spin-traced 1-electron density matrix rdm1a, rdm1b = fs.make_rdm1s(fcivec, norb, (5, 4)) # alpha and beta 1-electron density matrices t_rdm1 = fs.trans_rdm1(fcivec0, fcivec1, N, (5, 4)) # spin-traced 1-electron transition density matrix ``` -------------------------------- ### Initialize and Run CASCI and CASSCF in PySCF Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Demonstrates the initialization and execution of Complete Active Space Configuration Interaction (CASCI) and Complete Active Space Self-Consistent Field (CASSCF) methods. These methods require a mean-field object (like RHF) and the number of active electrons and orbitals. ```python from pyscf import mcscf # Assuming rhf_h2o is a pre-computed RHF object casci_h2o = mcscf.CASCI(rhf_h2o, 6, 8) e_casci = casci_h2o.kernel()[0] casscf_h2o = mcscf.CASSCF(rhf_h2o, 6, 8) e_casscf = casscf_h2o.kernel()[0] ``` -------------------------------- ### CASSCF Calculation Example in Python Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/mcscf.rst This Python code illustrates a CASSCF calculation. It shows how to initialize and run a CASSCF calculation starting from Hartree-Fock orbitals. Dependencies include the PySCF library. ```python import pyscf mol = pyscf.M( atom = 'O 0 0 0; O 0 0 1.2', basis = 'ccpvdz', spin = 2) myhf = mol.RHF().run() ncas, nelecas = (6,(5,3)) # We can also run CAS calculations starting from the Hartree-Fock orbitals. mycas = myhf.CASSCF(ncas, nelecas).run() ``` -------------------------------- ### Set up Crystal Cell with Pseudopotentials (Python) Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Demonstrates how to initialize a crystal cell object in PySCF for periodic boundary condition calculations. It includes setting lattice vectors, basis sets, and pseudopotentials. All-electron calculations can be performed by omitting the pseudopotential. ```python from pyscf.pbc import gto import numpy as np cell_diamond = gto.Cell() cell_diamond.atom = ''' C 2.6751 .8917 2.6751 C 0. 1.7834 1.7834 C .8917 2.6751 2.6751 ''' cell_diamond.basis = 'gth-szv' cell_diamond.pseudo = 'gth-pade' cell_diamond.a = np.eye(3) * 3.5668 cell_diamond.build() ``` -------------------------------- ### Hardcode BLAS Libraries in CMakeLists.txt Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md This example shows how to directly modify the CMakeLists.txt file to hardcode the paths to specific BLAS libraries, such as multiple MKL libraries. This provides explicit control over the linking process. ```bash set(BLAS_LIBRARIES "${BLAS_LIBRARIES};/path/to/mkl/lib/intel64/libmkl_intel_lp64.so") set(BLAS_LIBRARIES "${BLAS_LIBRARIES};/path/to/mkl/lib/intel64/libmkl_sequential.so") set(BLAS_LIBRARIES "${BLAS_LIBRARIES};/path/to/mkl/lib/intel64/libmkl_core.so") set(BLAS_LIBRARIES "${BLAS_LIBRARIES};/path/to/mkl/lib/intel64/libmkl_avx.so") ``` -------------------------------- ### Serve PySCF Website Locally Source: https://github.com/pyscf/pyscf.github.io/blob/master/README.md Starts a local HTTP server to view the generated PySCF website. The server serves files from the 'build/html' directory, allowing you to preview the documentation locally. ```bash python -m http.server --directory build/html ``` -------------------------------- ### CASSCF with Density Fitting and Frozen Core Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Illustrates how to perform CASSCF calculations using density fitting for 2-electron integrals and applying a frozen core approximation. This involves using the DFCASSCF class and setting the 'frozen' attribute. ```python from pyscf import mcscf # Assuming rhf_h2o is a pre-computed RHF object casscf_h2o_df = mcscf.DFCASSCF(rhf_h2o, 6, 8, auxbasis='ccpvtzfit') casscf_h2o_df.frozen = 1 # frozen core e_casscf_df = casscf_h2o_df.kernel()[0] ``` -------------------------------- ### Evaluate Wave Function Symmetry with PySCF FCI Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/ci.rst This example demonstrates how to evaluate the symmetry of a wave function using the FCI module in PySCF. It requires the PySCF library to be installed. ```python from pyscf import gto, scf, ao2mo, fci mol = gto.M(atom='H 0 0 0; F 0 0 1.1', basis='sto-3g') mf = scf.RHF(mol).run() # FCI calculation cisolver = fci.FCI(mf) cisolver.kernel() # Evaluate wave function symmetry # The output will indicate the symmetry of the calculated wave function. ``` -------------------------------- ### Initialize SCF with Density Matrix from Checkpoint (Python) Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/scf.rst Shows how to read a density matrix directly from a checkpoint file and pass it as an initial guess to the SCF solver. This method achieves the same result as setting `init_guess = 'chkfile'` but offers more direct control. ```python from pyscf import scf mf = scf.RHF(mol) dm = scf.hf.from_chk(mol, '/path/to/chkfile') mf.kernel(dm) ``` -------------------------------- ### Run PySCF Docker Container with Jupyter Notebook Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md Starts a Docker container with a PySCF environment and a Jupyter notebook server listening on port 8888. Access the notebook via https://localhost:8888. This is useful for interactive development and experimentation. ```bash docker run -it -p 8888:8888 pyscf/pyscf:latest ``` -------------------------------- ### Run Restricted and Unrestricted FCI Calculation (Python) Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/ci.rst Provides a basic example of performing restricted (RFCI) and unrestricted (UFCI) Full Configuration Interaction calculations using PySCF. It shows the setup for both types of calculations. ```Python from pyscf import gto, scf, fci mol = gto.M(atom='H 0 0 0; F 0 0 1.1', basis='sto-3g') mf = scf.RHF(mol).run() myfci = fci.FCI(mf).run() print('E(RFCI) = %s' % myfci.e_tot) mf = scf.UHF(mol).run() myfci = fci.FCI(mf).run() print('E(UFCI) = %s' % myfci.e_tot) ``` -------------------------------- ### Molecular Orbital Localization Schemes in Python Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Shows how to localize molecular orbitals (MOs) using different schemes like Foster-Boys and Pipek-Mezey in PySCF. It also demonstrates the computation of Knizia's intrinsic bond orbitals. ```python from pyscf import lo # Assuming mol_h2o and rhf_h2o are pre-defined # Occupied orbitals occ_orbs = rhf_h2o.mo_coeff[:, rhf_h2o.mo_occ > 0.] # Foster-Boys localization fb_h2o = lo.Boys(mol_h2o, occ_orbs) loc_occ_orbs = fb_h2o.kernel() # Pipek-Mezey localization for virtual orbitals virt_orbs = rhf_h2o.mo_coeff[:, rhf_h2o.mo_occ == 0.] pm_h2o = lo.PM(mol_h2o, virt_orbs) loc_virt_orbs = pm_h2o.kernel() # Knizia's intrinsic bond orbitals iao = lo.iao.iao(mol_h2o, occ_orbs) ciao = lo.vec_lowdin(iao, rhf_h2o.get_ovlp()) ibos = lo.ibo.ibo(mol_h2o, occ_orbs, iaos=iao) ``` -------------------------------- ### Calculate Polarizability with ASE and Siesta (Python) Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/interface/nao/examples/ase.rst Performs a simple polarizability calculation for a system using PYSCF-NAO, ASE, and Siesta. Requires installation of Siesta, ASE, and the interface between them. The input is typically a molecular structure, and the output is the polarizability tensor. ```python from pyscf.nao import nao from ase.calculators.siesta import Siesta from ase.optimize import BFGS from ase.io import read, write # Load a molecule using ASE # Example: C60 molecule # You can replace this with your own molecule file molecule = read('C60.xyz') # Initialize PYSCF-NAO calculator n = nao.XCFun( роород='LDA', xc_code='LDA') # Set up Siesta calculator calc_siesta = Siesta( label='siesta_calc', basis='DZP', mesh_cutoff=200.0, pseudo=' latach-PBE', # Add other Siesta specific parameters as needed ) # Set the calculator for the molecule molecule.calc = calc_siesta # Perform a calculation to get polarizability # This is a simplified example; actual polarizability calculation might require specific flags or methods # For detailed polarizability calculation, refer to PYSCF-NAO and ASE documentation # Example: Get total energy (as a placeholder for a calculation step) total_energy = molecule.get_potential_energy() print(f"Total Energy: {total_energy}") # To get polarizability, you would typically use PYSCF-NAO's specific functions # For example: # polarizability = n.polarization(molecule_ase=molecule, xc_code='LDA') # print(f"Polarizability: {polarizability}") # Note: The exact method to obtain polarizability might vary based on the PYSCF-NAO version and desired calculation type. # Consult the PYSCF-NAO documentation for precise polarizability calculation procedures. ``` -------------------------------- ### Configure CMake for PySCF Build Options Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md Sets specific CMake build options within a configuration file to disable certain libraries or features. This example shows how to disable XCFun and F12 integrals, which can be useful for reducing build time or avoiding compilation issues. ```bash set(ENABLE_XCFUN Off) set(WITH_F12 Off) ``` -------------------------------- ### State-Averaged CASSCF with Multiple Solvers Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Shows how to set up and run state-averaged CASSCF calculations, allowing for multiple electronic states to be considered simultaneously. This involves defining different FCI solvers for different spin states and using the `state_average_mix_` function. ```python from pyscf import mcscf, fci import numpy as np # Assuming rhf_c2 is a pre-computed RHF object for molecule c2 casscf_c2 = mcscf.CASSCF(rhf_c2, 8, 8) solver_t = fci.direct_spin1_symm.FCI(mol_c2) # Example for triplet states solver_t.spin = 2 solver_t.nroots = 1 solver_t = fci.addons.fix_spin(solver_t, shift=.2, ss=2) # Adjust spin solver_s = fci.direct_spin0_symm.FCI(mol_c2) # Example for singlet states solver_s.spin = 0 solver_s.nroots = 2 mcscf.state_average_mix_(casscf_c2, [solver_t, solver_s], np.ones(3) / 3.) casscf_c2.kernel() ``` -------------------------------- ### Density Fitting Techniques in PySCF Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Illustrates two methods for invoking density fitting of 2-electron integrals in PySCF. Density fitting approximates the electron repulsion integrals, reducing computational cost. It can be applied by decorating an existing SCF object or by passing the density_fit function during SCF object initialization. ```python from pyscf import scf, df # Assuming mol_c2 is a defined molecule object # Option 1: Decorate an existing SCF object # rhf_c2_df = rhf_c2.density_fit(auxbasis='def2-universal-jfit') # Option 2: Initialize SCF with density_fit # rhf_c2_df = df.density_fit(scf.RHF(mol_c2), auxbasis='def2-universal-jfit') ``` -------------------------------- ### Perform Gamma-point RHF and CCSD Calculation (Python) Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Illustrates how to perform a Restricted Hartree-Fock (RHF) calculation at the Gamma-point for a crystal structure, followed by a Coupled Cluster Singles and Doubles (CCSD) calculation. Density fitting is used for efficiency. This example assumes the crystal cell is already set up. ```python from pyscf.pbc import scf as pbcscf from pyscf.pbc import cc # Assuming cell_diamond is already defined and built rhf_diamond = pbcscf.RHF(cell_diamond).density_fit() rhf_diamond.kernel() ccsd_diamond = cc.CCSD(rhf_diamond) ccsd_diamond.kernel() ``` -------------------------------- ### Display Make Help for PySCF Docs Source: https://github.com/pyscf/pyscf.github.io/blob/master/README.md Displays all available options and commands for the 'make' utility within the PySCF documentation project. This is useful for discovering various build and utility targets. ```bash make help ``` -------------------------------- ### EOM-CCSD Calculations (IP, EA, EE) in PySCF Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Shows how to perform Equation-Of-Motion Coupled Cluster Singles and Doubles (EOM-CCSD) calculations in PySCF for ionization potential (IP), electron affinity (EA), and electron-electron double ionization (EE) channels. These calculations start from a ground-state CCSD result. ```python from pyscf import cc, scf # Assuming ccsd_h2o is a pre-defined CCSD object from a ground-state calculation # e_ip_ccsd = ccsd_h2o.ipccsd(nroots=1)[0] # Ionization Potential EOM-CCSD # e_ea_ccsd = ccsd_h2o.eaccsd(nroots=1)[0] # Electron Affinity EOM-CCSD # e_ee_ccsd = ccsd_h2o.eeccsd(nroots=1)[0] # Electron-Electron Double Ionization EOM-CCSD ``` -------------------------------- ### Install PySCF-forge with pip Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md Installs the pyscf-forge package, which contains newly introduced features. This package can be installed using pip. ```bash pip install pyscf-forge ``` -------------------------------- ### 1- and 2-Electron Integral Transformations in Python Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Shows how to obtain 1- and 2-electron integrals in a molecular orbital (MO) basis using PySCF. It covers calculating core Hamiltonian and electron repulsion integrals, and transforming them to the MO basis. It also demonstrates saving and reading integrals from HDF5 files. ```python import numpy as np from pyscf import ao2mo import tempfile import h5py # Assuming mol_h2o and rhf_h2o are pre-defined # 1-electron integrals (core Hamiltonian) hcore_ao = mol_h2o.intor_symmetric('int1e_kin') + mol_h2o.intor_symmetric('int1e_nuc') hcore_mo = np.einsum('pi,pq,qj->ij', rhf_h2o.mo_coeff, hcore_ao, rhf_h2o.mo_coeff) # 2-electron integrals (4-fold symmetry in AO basis) eri_4fold_ao = mol_h2o.intor('int2e_sph', aosym=4) # Transform 2-electron integrals to MO basis (in-core) eri_4fold_mo = ao2mo.incore.full(eri_4fold_ao, rhf_h2o.mo_coeff) # Transform and save 2-electron integrals to HDF5 (out-of-core) with tempfile.NamedTemporaryFile() as ftmp: ao2mo.kernel(mol_h2o, rhf_h2o.mo_coeff, ftmp.name) with h5py.File(ftmp.name) as f: eri_4fold_from_file = f['eri_mo'] ``` -------------------------------- ### Initialize and Run DMRGSCF with PySCF Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Shows the initialization and execution of Density Matrix Renormalization Group Self-Consistent Field (DMRGSCF) calculations. This includes setting up state-averaged calculations and configuring the FCI solver's memory and thread usage. ```python from pyscf import dmrgscf # Assuming rhf_c2 is a pre-computed RHF object dmrgscf_c2 = dmrgscf.DMRGSCF(rhf_c2, 8, 8) dmrgscf_c2.state_average_([.5] * 2) dmrgscf_c2.fcisolver.memory = 4 # in GB dmrgscf_c2.fcisolver.num_thrds = 8 # number of threads to spawn on each MPI process e_dmrgscf = dmrgscf_c2.kernel() ``` -------------------------------- ### Compute IP and EA for open-shell molecules with ADC(3) Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/modules/adc.rst This example demonstrates the computation of IP and EA for open-shell molecules using the ADC(3) method, starting from a UHF reference. It shows how to set up the molecule with charge and spin, run the UHF calculation, and then perform the ADC calculations. ```python from pyscf import gto, scf, adc mol = gto.M(atom='H 0 0 0; F 0 0 1', basis='ccpvdz', charge = 1, spin = 1) mf = scf.UHF(mol).run() myadc = adc.ADC(mf) myadc.method = "adc(3)" myadc.kernel() e_ip,v_ip,p_ip = myadc.ip_adc(nroots=1) e_ea,v_ea,p_ea = myadc.ea_adc(nroots=1) ``` -------------------------------- ### Symmetry Handling in SCF Calculations in Python Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Demonstrates how to control wave function symmetry in SCF calculations using PySCF. This includes specifying orbital occupancy based on symmetry irreps and deducing orbital symmetries from MO coefficients. ```python from pyscf import scf, symm # Assuming mol_c2 and rhf_c2 are pre-defined # Specify orbital occupancy by symmetry irrep rhf_c2 = scf.RHF(mol_c2) rhf_c2.irrep_nelec = {'Ag': 4, 'B1u': 4, 'B2u': 2, 'B3u': 2} e_c2 = rhf_c2.kernel() # Deduce orbital symmetries from MO coefficients orbsym = symm.label_orb_symm(mol_c2, mol_c2.irrep_id, mol_c2.symm_orb, rhf_c2.mo_coeff) ``` -------------------------------- ### Install PySCF on Fedora Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md Installs PySCF as a distribution package on Fedora Linux using the dnf package manager. On x86-64 platforms, this typically installs the optimized 'qcint' library. ```bash dnf install python3-pyscf ``` -------------------------------- ### QM/MM Calculations with PySCF Source: https://context7.com/pyscf/pyscf.github.io/llms.txt Provides an example of setting up and running a QM/MM calculation in PySCF. This involves defining a quantum mechanical region and adding external molecular mechanics point charges to the calculation. ```python import numpy from pyscf import gto, scf, qmmm mol = gto.M(atom=''' C 1.1879 -0.3829 0.0000 C 0.0000 0.5526 0.0000 O -1.1867 -0.2472 0.0000 H -1.9237 0.3850 0.0000 H 2.0985 0.2306 0.0000 H 1.1184 -1.0093 0.8869 H 1.1184 -1.0093 -0.8869 H -0.0227 1.1812 0.8852 H -0.0227 1.1812 -0.8852 ''', basis='3-21g', verbose=4) # Define MM point charges numpy.random.seed(1) coords = numpy.random.random((5, 3)) * 10 # MM charge positions charges = (numpy.arange(5) + 1.) * -0.1 # MM charges # Add MM charges to HF calculation mf = scf.UHF(mol) mf = qmmm.mm_charge(mf, coords, charges) mf.run() ``` -------------------------------- ### Install PySCF with pip Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md Installs the precompiled PySCF package using pip. This is the recommended method for most users and works on Linux, macOS, and WSL. It also includes commands for upgrading an existing installation. ```bash pip install --prefer-binary pyscf ``` ```bash pip install --upgrade pyscf ``` -------------------------------- ### Periodic Boundary Conditions (PBC) Initialization in PySCF Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Initializes unit cells for crystalline materials calculations using the PBC modules. The API for initializing unit cells is similar to that for finite-size molecules. Requires importing pbc.gto and defining the unit cell structure. This is a foundational step for PBC calculations. ```python from pyscf.pbc import gto as pbcgto cell_diamond = pbcgto.M(atom = '''C 0. 0. 0. C .8917 .8917 .8917 C 1.7834 1.7834 0. C 2.6751 2.6751 .8917 C 1.7834 0. 1.7834 ''') ``` -------------------------------- ### ADC Calculations (ADC(2), ADC(2)-X, ADC(3)) in PySCF Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Demonstrates the use of Algebraic Diagrammatic Construction (ADC) methods in PySCF, including ADC(2), ADC(2)-X, and ADC(3) schemes. These methods can be applied for ionization potential (IP) and electron affinity (EA) calculations, and support specifying the number of roots and method type. ```python from pyscf import adc, scf # Assuming rhf_h2o is a pre-defined RHF object # adc_h2o = adc.ADC(rhf_h2o) # e_ip_adc2 = adc_h2o.kernel()[0] # IP-ADC(2) for 1 root # adc_h2o.method = "adc(2)-x" # adc_h2o.method_type = "ea" # e_ea_adc2x = adc_h2o.kernel()[0] # EA-ADC(2)-x for 1 root # adc_h2o.method = "adc(3)" # adc_h2o.method_type = "ea" # e_ea_adc3 = adc_h2o.kernel(nroots = 3)[0] # EA-ADC(3) for 3 roots ``` -------------------------------- ### Install PySCF with Conda Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/install.md Installs PySCF using conda from the conda-forge channel, recommended for creating dedicated environments. It also provides an alternative installation from the 'pyscf' channel for x86 CPUs preferring MKL. ```bash conda install -c conda-forge pyscf ``` ```bash conda create -n pyscf-env -c conda-forge python=3.12 pyscf conda activate pyscf-env ``` ```bash conda install -c pyscf pyscf ``` -------------------------------- ### Apply Scalar Relativistic Effects with x2c in PySCF Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/modules/x2c.rst This code snippet demonstrates how to apply scalar relativistic effects using the x2c module in PySCF. It initializes a molecule, performs a restricted Hartree-Fock calculation with x2c, modifies molecular properties, and then performs an unrestricted Hartree-Fock calculation using x2c1e. The example covers basic setup and execution of relativistic calculations. ```python from pyscf import gto from pyscf import scf mol = gto.M( verbose = 0, atom = '''8 0 0. 0 1 0 -0.757 0.587 1 0 0.757 0.587''', basis = 'ccpvdz', ) mf = scf.RHF(mol).x2c().run() mol.spin = 1 mol.charge = 1 mol.build(0, 0) mf = scf.UKS(mol).x2c1e() energy = mf.kernel() ``` -------------------------------- ### Install PySCF Extension with Pip (Bash) Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/extensions.md Shows how to install specific PySCF extensions or all available extensions using pip's extra dependency mechanism. This is the recommended method for installing extensions. ```bash pip install pyscf[semiempirical] ``` ```bash pip install pyscf[all] ``` -------------------------------- ### Full Configuration Interaction (FCI) in PySCF Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/quickstart.rst Shows how to perform a Full Configuration Interaction (FCI) calculation in PySCF, which provides an exact diagonalization of the Hamiltonian for correlated electrons. The syntax is similar to other correlation methods, and it supports user-defined Hamiltonians. ```python from pyscf import fci, scf # Assuming rhf_h2o is a pre-defined RHF object # fci_h2o = fci.FCI(rhf_h2o) # e_fci = fci_h2o.kernel()[0] # For user-defined Hamiltonians (h1e, h2e): # fci_solver = fci.direct_spin1.FCI() # e_fci_custom = fci_solver.kernel(h1e, h2e)[0] ``` -------------------------------- ### Install PySCF Extension from GitHub (Bash) Source: https://github.com/pyscf/pyscf.github.io/blob/master/source/user/extensions.md Illustrates how to install PySCF extensions directly from their GitHub repositories using pip. This method is useful for installing the latest development versions or extensions not yet published on PyPI. ```bash pip install git+https://github.com/pyscf/semiempirical ``` ```bash pip install https://github.com/pyscf/semiempirical/archive/v0.1.0.tar.gz ```