I'm trying to create a script to generate partial charges for a given .dat file.

As an example of my process, I'm currently using gromacs to run minimization on a box of propane. It outputs a min.gro file, which i wrote a script to convert to min.dat so I can use Psi4. Here is the script:

def gro_to_dat(input_file, output_file):
    with open(input_file, 'r') as gro, open(output_file, 'w') as dat:
        # Skip the title and total atoms lines in the .gro file
        num_atoms = int(gro.readline().strip())

        # Write the initial lines to the .dat file
        dat.write("molecule mol {\n")
        dat.write("   0 1\n")

        # Process each line in the .gro file
        for _ in range(num_atoms):
            line = gro.readline()
            atom_symbol = line[12:15].strip()[0]  # Extract the first character of atom name
            x, y, z = line[20:28].strip(), line[28:36].strip(), line[36:44].strip()
            dat.write(f"   {atom_symbol}   {x}   {y}   {z}\n")


gro_to_dat("min.gro", "min.dat")

And it creates a .dat file, which looks like this:

molecule mol {
   0 1
   C   3.384   2.059   2.720
   C   3.419   2.209   2.725
   C   3.308   2.297   2.664
   H   3.465   2.000   2.761
   H   3.368   2.026   2.617
   H   3.294   2.038   2.777

Finally, my partial charge generation script:

import psi4

# Set Psi4 memory and number of threads
psi4.set_memory('8 GB')

# Read the min.dat file for molecular geometry
with open("min.dat", 'r') as f:
    lines = f.readlines()
    molecule_data = "".join(lines[1:-1])  # skip the first and last lines

# Create the molecule object using the data from the file
molecule = psi4.geometry(molecule_data)

# Set computation options 
    'basis': 'STO-3G',
    'scf_type': 'df',
    'e_convergence': 1e-6,

# Perform a single-point energy computation to obtain wavefunction
energy, wfn = psi4.energy("SCF", return_wfn=True, molecule=molecule)

# Compute the ESP charges
esp_charges = psi4.core.MoleculeESP.compute_esp_charges(wfn.molecule())

# Write the ESP charges to a file
with open("esp_charges.txt", 'w') as f:
    for charge in esp_charges:

print("ESP charges written to esp_charges.txt")

I actually want to use 6-31G*, but even using STO-3G, the computation does not finish.

My output is very long, but it basically is this:

 ==> Geometry <==

    Molecular point group: c1
    Full point group: C1

    Geometry (in Angstrom), charge = 0, multiplicity = 1:

       Center              X                  Y                   Z               Mass
    ------------   -----------------  -----------------  -----------------  -----------------
         C            0.901238549949    -0.441467579029     0.193243059784    12.000000000000
         C            0.936238549949    -0.291467579029     0.198243059784    12.000000000000
         C            0.825238549949    -0.203467579029     0.137243059784    12.000000000000
         H            0.982238549949    -0.500467579029     0.234243059784     1.007825032230
Running in c1 symmetry.

  Rotational constants: A =      0.00022  B =      0.00020  C =      0.00020 [cm^-1]
  Rotational constants: A =      6.53586  B =      6.11387  C =      6.09670 [MHz]
  Nuclear repulsion = 18130296.238725978881121

  Charge       = 0
  Multiplicity = 1
  Electrons    = 13000
  Nalpha       = 6500
  Nbeta        = 6500

  ==> Algorithm <==

  SCF Algorithm Type is DF.
  DIIS enabled.
  MOM disabled.
  Fractional occupation disabled.
  Guess Type is SAD.
  Energy threshold   = 1.00e-06
  Density threshold  = 1.00e-06
  Integral threshold = 1.00e-12

  ==> Primary Basis <==

  Basis Set: STO-3G
    Blend: STO-3G
    Number of shells: 8500
    Number of basis functions: 11500
    Number of Cartesian functions: 11500
    Spherical Harmonics?: true
    Max angular momentum: 1

I've tried increasing memory, and have already downgraded my basis set, but nothing seems to be working.

  • 1
    $\begingroup$ Are you running this on some sort of computing cluster or just your laptop/desktop? Your output shows that even with STO-3G you have over 10,000 basis functions, which going to require quite a large amount of memory. The "Killed" in the output suggests Psi4 isn't running out memory, but that your machine's OS has decided the process is using too much memory. On a Linux machine, it can be a little difficult to control this OS memory limit unless you have admin access. $\endgroup$
    – Tyberius
    Commented Oct 7, 2023 at 18:54
  • $\begingroup$ Just on my laptop, while running windows 11. I'm confused as to why I need so much memory as when I run this operation with Gaussian it isn't intensive at all. @Tyberius $\endgroup$
    – asquith
    Commented Oct 9, 2023 at 10:26
  • 1
    $\begingroup$ @asquith How large was the swap space size when successfully running the computation in Gaussian? One can adjust it while submitting a job, see here. Is it possible to declare a swap file of similar volume ahead of your computation now engaging Psi4 (for a test, an initially smaller, less resource demanding computation may be suitable)? $\endgroup$
    – Buttonwood
    Commented Oct 9, 2023 at 18:05


You must log in to answer this question.