4
$\begingroup$

I have a big number of .xyz files which I plan to run using Q-Chem, and I was wondering if there were any options for automatically generating Q-Chem input files from these .xyz files. I know that IQmol can generate an input file from an .xyz, but from what I know this can only be done one at a time. I was looking at packages like PyQchem, but this seems to require manually entering the coordinates, charge, and multiplicity.

Is there any sort of software or package which can automatically generate such input files from .xyz files?

Thanks!

$\endgroup$
1
  • $\begingroup$ Does this answer work for you? This would read a gaussian log file and generate new gaussian input files. You should be able to modify the script to do what you need. If you can provide a template .xyz file and Q-Chem input file, I can post the answer with the new script. $\endgroup$ Apr 8 at 17:48

2 Answers 2

2
$\begingroup$

You don't need to write a script to generate a bunch of Q-chem input files. Alternatively, Q-chem has an option READ to read external .xyz file in the $molecule code deck:

$molecule
   READ filename
$end

Ref: https://manual.q-chem.com/4.3/sect-molinput.html

$\endgroup$
2
  • $\begingroup$ But this will read only one file, so, at the end, you need a script to run over the whole set of XYZ files. $\endgroup$
    – Camps
    Apr 10 at 14:22
  • 1
    $\begingroup$ @Camps Hi, sorry for the unclear explanation. I meant that the OP does not need to write a script to generate input files, but rather one script that loops over input files and submits calculation jobs all at once. $\endgroup$ Apr 10 at 14:37
2
$\begingroup$

Thanks for everyone's help! I ended up just writing my own script to iterate through each .xyz and write a Q-Chem .inp. The main issue with just reading in directly from the file name was that I am trying to do BSSE calculations, and the $molecule section needed to be split up into different fragments. Here is the python code, for those who may stumble upon this later:

'''SCRIPT FOR GENERATING Q-CHEM INPUTS FOR BSSE CALCULATIONS WITH TWO FRAGMENTS'''

# Number of atoms in each adsorbate
ads = [1, 2, 3, 4, 5]

# Spin states for each adsorbate
spins = [3, 2, 3, 2, 1]

# Charge of each slab
charge = 0
k = 0

# Number of atoms in first fragment (slab)
frag1 = 30

# Number of input files:
inp = 75

for i in range(0, inp):
    with open(f'file_{i}.xyz', 'r') as f:
        raw = f.readlines()
    
    with open(f'input_{i}.inp', 'w') as g:
        g.write('$molecule\n')
        g.write(f'{charge} {spins[k]}\n')

        # Write first fragment
        g.write(
            '--\n'
            '0 1\n'
        )
        for j in range(2, frag1+2): # Skip first 2 lines of .xyz
            g.write(raw[j])

        # Write second fragment
        g.write(
            '--\n'
            f'0 {spins[k]}\n'
        )
        for j in range(frag1+2, frag1+2+ads[k]):
            g.write(raw[j])
        g.write('$end\n')
        g.write('\n')

        # Write settings:
        g.write(
            '$rem\n'
            
            '''
            PUT SETTINGS HERE
            '''
            
        g.write('$end\n')

    # With more adsorbates/spin states, must change k!
    k += 1
    if k > 4:
        k = 0

Of course this was made to satisfy a rather specific situation, but it can be easily adapted for other inputs. Thanks again.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .