示例#1
0
def energy_and_gradient(xyzs, *args):  # argmuent of image
    if len(args) != 0:
        dijk, number = args
        name = os.path.join('./Input_Files', 'ammonia_image_' + str(number))
    else:
        name = os.path.join('./Input_Files', 'ammonia')

    in_file = qc.input_classes.inputfile()
    geo = qc.input_classes.cartesian(atom_list=[[
        "N", str(xyzs[0]), str(xyzs[1]),
        str(xyzs[2])
    ], ["H", str(xyzs[3]), str(xyzs[4]),
        str(xyzs[5])], [
            "H", str(xyzs[6]), str(xyzs[7]),
            str(xyzs[8])
        ], ["H", str(xyzs[9]), str(xyzs[10]),
            str(xyzs[11])]])

    in_file.add(geo)
    in_file.add(rem)

    if os.path.isfile(
            os.path.join(scratch_path, name + '.dir',
                         str(53) + '.' + str(0))):
        rem.add("SCF_GUESS", "READ")

    in_file.run(name=name + '.in')

    try:
        out_file = qc.read(name + ".out", silent=True)
        energy = out_file.general.energy
        if energy == 'undefined' or energy == None:
            print('Error in SCF calculation. Retrying from GWH guess')
            in_file = qc.input_classes.inputfile()
            rem.remove('SCF_GUESS')
            rem.add('SCF_GUESS', 'GHW')
            in_file.add(geo)
            in_file.add(rem)
            in_file.run(name=name + '.in')

            out_file = qc.read(name + ".out", silent=True)
            energy = out_file.general.energy
            if energy == 'undefined' or energy == None:
                out_file.general.info()
                raise ValueError('No SCF convergence achieved')
    except IOError:
        print('energy error occurred')
    if out_file.force.gradient_vector is None:
        gradient = np.array([np.NAN] * 9).reshape(-1, 1)
    else:
        try:
            gradient = out_file.force.gradient_vector.T.flatten()
            gradient = gradient * (
                1 / 0.52917721067
            )  # https://de.wikipedia.org/wiki/Bohrscher_Radius
        except:
            print("gradient error occurred")
    scf_guess = None
    return energy, gradient, scf_guess  # out_file.opt.energies[0], out_file.opt.gradient_vector[0]
示例#2
0
    def test_h2(self):
        """ Hard TestCase as the large numerical values in
        the gradient are more difficult to parse. """

        # Test for QChem version 5.0
        job = qc.read(join(self.path, "force_h2_5.0.out"))
        self.assertEqual(job.force.gradient, self._expected_grad_h2)
        _np.testing.assert_array_equal(job.force.gradient_vector,
                                       self._expected_grad_vec_h2)
示例#3
0
    def test_ethane(self):
        """ Simple TestCase to ensure correct handling of the
        somewhat strange printing format of QChem gradients"""

        # Test for QChem version 5.0
        job = qc.read(join(self.path, "force_c2h6_5.0.out"))
        self.assertEqual(job.force.gradient, self._expected_grad_c2h6)
        _np.testing.assert_array_equal(job.force.gradient_vector,
                                       self._expected_grad_vec_c2h6)
示例#4
0
    def test_h2(self):
        """ Hard TestCase as the large numerical values in
        the gradient are more difficult to parse. """

        # Test for QChem version 5.0
        job = qc.read(join(self.path, "force_h2_5.0.out"))
        self.assertEqual(job.force.gradient,
            self._expected_grad_h2)
        _np.testing.assert_array_equal(job.force.gradient_vector,
            self._expected_grad_vec_h2)
示例#5
0
    def test_ethane(self):
        """ Simple TestCase to ensure correct handling of the
        somewhat strange printing format of QChem gradients"""

        # Test for QChem version 5.0
        job = qc.read(join(self.path, "force_c2h6_5.0.out"))
        self.assertEqual(job.force.gradient,
            self._expected_grad_c2h6)
        _np.testing.assert_array_equal(job.force.gradient_vector,
            self._expected_grad_vec_c2h6)
示例#6
0
def energy_and_gradient(xyzs, *args):  # argmuent of image
    if len(args) != 0:
        dijk, number = args
        name = os.path.join('./Input_Files', 'Ethane_image_' + str(number))
    else:
        name = os.path.join('./Input_Files', 'Ethane')

    in_file = qc.input_classes.inputfile()
    geo = qc.input_classes.cartesian(atom_list=[
        ["H", str(xyzs[0]), str(xyzs[1]),
         str(xyzs[2])], ["H", str(xyzs[3]),
                         str(xyzs[4]),
                         str(xyzs[5])],
        ["H", str(xyzs[6]), str(xyzs[7]),
         str(xyzs[8])], ["C", str(xyzs[9]),
                         str(xyzs[10]),
                         str(xyzs[11])],
        ["C", str(xyzs[12]), str(xyzs[13]),
         str(xyzs[14])], [
             "H", str(xyzs[15]),
             str(xyzs[16]), str(xyzs[17])
         ], ["H", str(xyzs[18]),
             str(xyzs[19]), str(xyzs[20])],
        ["H", str(xyzs[21]), str(xyzs[22]),
         str(xyzs[23])]
    ])

    if os.path.isfile(
            os.path.join(scratch_path, name + '.dir',
                         str(53) + '.' + str(0))):
        rem.add("SCF_GUESS", "READ")

    in_file.add(geo)
    in_file.add(rem)
    in_file.run(name=name + '.in')
    out_file = qc.read(name + ".out", silent=True)
    if out_file.force.gradient_vector is None:
        gradient = np.array([np.NAN] * 24).reshape(-1, 1)
    else:
        try:
            gradient = out_file.force.gradient_vector.T.flatten()
            gradient = gradient * (
                1 / 0.52917721067
            )  # https://de.wikipedia.org/wiki/Bohrscher_Radius
        except:
            print("gradient error occurred")
    if out_file.general.energy is None:
        energy = np.NAN
    else:
        try:
            energy = out_file.general.energy
        except:
            print('energy error occurred')
    scf_guess = None
    return energy, gradient, scf_guess  # out_file.opt.energies[0], out_file.opt.gradient_vector[0]
示例#7
0
#
# This sample file generates center-of-mass displaced water molecules from the standard water dimer
# and loops through different multiplicative displacements
#
# MBG (02/2014)
#
import pyqchem as qc
from pylab import *

# load some sample inputs - here the first and second monomers of the water dimer
a = qc.read("../../databases/s22/Water-dimer_mono1.xyz")
a.name = "water-dimer_mono1"
b = qc.read("../../databases/s22/Water-dimer_mono2.xyz")
b.name = "water-dimer_mono2"

# Save direction and magnitude
d = b.com - a.com

# Translate both to origin
a.move(-a.com)
b.move(-b.com)

# loop over a multiplicative factor for center of mass distance and generate jobs
for i in arange(.9, 2.01, .1):
    # translate to new coordinates
    a.move(-i * d / 2)
    b.move(i * d / 2)

    # form new dimer
    c = a + b
示例#8
0
rem1 = qc.rem_array()
rem1.basis("6-31++G**")
rem1.exchange("hf")
rem1.thresh("14")
rem1.scf_convergence("10")
from copy import deepcopy
rem2 = deepcopy(rem1)
rem2.scf_guess("fragmo")

#make a rem_frgm array
rem_frgm = qc.rem_frgm_array()
rem_frgm.thresh("7")
rem_frgm.scf_convergence("3")

#make objects for holding the molecular geometries
xyz = qc.read("4water.xyz")
frag = qc.fragment(atom_list=xyz.list_of_atoms)

#make molecule array from cartesian object
mol1 = qc.mol_array(xyz)
mol2 = qc.mol_array(frag)

#make input object and write to disk
job1 = qc.inputfile()
job1.add(rem1)
job1.add(mol1)

job2 = qc.inputfile()
job2.add(rem2)
job2.rem.scf_guess("fragmo")
job2.add(rem_frgm)
示例#9
0
文件: queue.py 项目: awhauser/pyQChem
import pyqchem as qc
import os

#make a generic rem array
rem=qc.rem_array()
rem.basis("sto-3g")
rem.exchange("hf")

#make a list of jobs
job_list=[]

#for all xyzs in a database, create and append the job to the list
for i in os.popen("ls ../../databases/a24/*.xyz").read().splitlines():

    #make the jobs
    job=qc.inputfile()

    #give job a name
    job.runinfo.name=i.split('/')[-1].replace(".xyz","")

    #read the xyz
    xyz=qc.read(i)
   
    #append the molecule and rem array
    job.add(qc.mol_array(xyz))
    job.add(rem)
    job_list.append(job)

# run all jobs in list using 12 workers
qc.queue(job_list,num_workers=12)
示例#10
0
文件: adc.py 项目: wuyulele/pyQChem
rem = qc.rem_array()
rem.basis("6-31g")
rem.jobtype("sp")
rem.method("adc(2)")
rem.ee_singlets("[2,0,0,0,0,2,0,0]")
xyz = qc.cartesian()
xyz.add_atom()
xyz.add_atom("H", "0", "0", ".74")
molec = qc.mol_array(xyz)
job = qc.inputfile()
job.add(rem)
job.add(molec)

#run job with name "h2" making h2.in h2.sh, and h2.out
job.run(name="h2")

#read in output
out = qc.read("h2.out")
out.adc.info()

#let's compute the excitation energies between the excited states
print("\nExcitation energies between excited states:")
for i in range(0, len(out.adc.list_of_excited_states) - 1):
    es1 = out.adc.list_of_excited_states[i]
    for j in range(i + 1, len(out.adc.list_of_excited_states)):
        es2 = out.adc.list_of_excited_states[j]
        print(
            ("{0:10s} -> {1:10s}: {2:12.6f}".format(es1.term_symbol,
                                                    es2.term_symbol,
                                                    es2.energy - es1.energy)))
示例#11
0
rem1=qc.rem_array()
rem1.basis("6-31++G**")
rem1.exchange("hf")
rem1.thresh("14")
rem1.scf_convergence("10")
from copy import deepcopy
rem2=deepcopy(rem1)
rem2.scf_guess("fragmo")

#make a rem_frgm array
rem_frgm=qc.rem_frgm_array()
rem_frgm.thresh("7")
rem_frgm.scf_convergence("3")

#make objects for holding the molecular geometries
xyz=qc.read("4water.xyz")
frag=qc.fragment(atom_list=xyz.list_of_atoms)

#make molecule array from cartesian object
mol1=qc.mol_array(xyz)
mol2=qc.mol_array(frag)

#make input object and write to disk
job1=qc.inputfile()
job1.add(rem1)
job1.add(mol1)

job2=qc.inputfile()
job2.add(rem2)
job2.rem.scf_guess("fragmo")
job2.add(rem_frgm)
示例#12
0
rem=qc.rem_array()
rem.basis("sto-3g")
rem.jobtype("opt")
xyz=qc.cartesian()
xyz.add_atom()
xyz.add_atom("H","0","0",".74")
molec=qc.mol_array(xyz)
job=qc.inputfile()
job.add(rem)
job.add(molec)

#run job with name "h2" making h2.in h2.sh, and h2.out
job.run(name="h2")

#read in output
out=qc.read("h2.out")
out.opt.info()

#let's approximate how much this has changed

#grab first geometry
start=out.opt.geometries[0]

#grab last geometry
end=out.opt.geometries[-1]

#Print statistics for geometric distortions
print("\n\nApproximate change between starting and ending geometries by two metrics:\n")
print(qc.utilities.rmsd(start.xyzs,end.xyzs)," or ", qc.utilities.kabsch(start.xyzs,end.xyzs),"\n")

#Check for reordering (not necessary in this case) and print out sequential RMSDs
示例#13
0
import pyqchem as qc
import os

#make a generic rem array
rem = qc.rem_array()
rem.basis("sto-3g")
rem.exchange("hf")

#make a list of jobs
job_list = []

#for all xyzs in a database, create and append the job to the list
for i in os.popen("ls ../../databases/a24/*.xyz").read().splitlines():

    #make the jobs
    job = qc.inputfile()

    #give job a name
    job.runinfo.name = i.split('/')[-1].replace(".xyz", "")

    #read the xyz
    xyz = qc.read(i)

    #append the molecule and rem array
    job.add(qc.mol_array(xyz))
    job.add(rem)
    job_list.append(job)

# run all jobs in list using 12 workers
qc.queue(job_list, num_workers=12)