Example #1
0
    def structure(self):
        totalRMSD=0
        for filer in self.prodOuts:
            # Extract the coordinates from a geometry optimization
            p = ccopen(filer)
            data = p.parse()

            # Use the bridge to create two lists of Biopython atoms
            from cclib.bridge import makebiopython
            initial = makebiopython(data.atomcoords[0] , data.atomnos)
            final =   makebiopython(data.atomcoords[-1], data.atomnos)

            # Use Biopython to superimpose the two geometries and calculate the RMS
            from Bio.PDB.Superimposer import Superimposer
            superimposer = Superimposer()
            superimposer.set_atoms(initial, final)
            totalRMSD+= superimposer.rms
            print ('RMSD'+str(superimposer.rms))
        for filer in self.reacOuts:
            # Extract the coordinates from a geometry optimization
            p = ccopen(filer)
            data = p.parse()

            # Use the bridge to create two lists of Biopython atoms
            from cclib.bridge import makebiopython
            initial = makebiopython(data.atomcoords[0] , data.atomnos)
            final =   makebiopython(data.atomcoords[-1], data.atomnos)

            # Use Biopython to superimpose the two geometries and calculate the RMS
            from Bio.PDB.Superimposer import Superimposer
            superimposer = Superimposer()
            superimposer.set_atoms(initial, final)
            totalRMSD+= superimposer.rms
            print ('RMSD'+str(superimposer.rms))
        return (totalRMSD)
Example #2
0
def main():
    """Goal: Identify first atom in product.out based on connectivity"""

    # Parse product output and generate z-matrix
    product = ccopen('product.out').parse()
    ccproduct = ccData_xyz(product.getattributes())
    ccproduct.build_zmatrix()
    shift = 2.0
    ccproduct.distances[1] += shift
    ccproduct.build_xyz()
    #ccproduct.print_xyz()

    reactant = ccopen('r1.out').parse()
    ccreactant = ccData_xyz(reactant.getattributes())

    # Shitty design here, but not sure what else to do yet...
    P2Ridx = [None]*len(ccreactant.atomnos)
    matched = []

    for i in range(len(ccproduct.atomnos)):
        match = indexmatch(ccproduct, i, ccreactant, ignores=[1], matched=matched)
        if match is not None:
            P2Ridx[match] = i
            matched.append(match)


    reactantinproduct(ccreactant, ccproduct, P2Ridx)
Example #3
0
def get_geometries(outputfilenames):

    snapnums = []
    CO2_geometries = []

    for outputfilename in outputfilenames:
        print("Parsing CO2 geometry from {}".format(outputfilename))

        job = ccopen(outputfilename)
        try:
            data = job.parse()
        except:
            # Is this the right control flow statement?
            continue
        # take the first one on the off chance that we've done a
        # numerical frequency run, which looks a lot like a geometry
        # optimization
        geometry_whole = data.atomcoords[0]
        start_index = len(data.atomnos) - 3
        geometry_CO2 = geometry_whole[start_index:]
        CO2_geometries.append(geometry_CO2)
        snapnum = int(re.search(r'drop_(\d+)', outputfilename).groups()[0])
        snapnums.append(snapnum)

    return CO2_geometries, snapnums
Example #4
0
def figs(opts):
    """
    Determine type of output from opts or file
    Call appropriate function
    """

    if type(opts.fname) == str:
        # Assuming ccinput is a filename
        data = parser.ccopen(opts.fname).parse()
    else:
        data = opts.fname
        assert type(data) == parser.data.ccData_optdone_bool \
            or type(data) == parser.data.ccData

    # TODO: determine what kind of job (opt, sp, freq)
        # auto = automatically determine
        # or get from opts.job
    if opts.job == 'auto':
        #print opts.job, "not yet implemented"
        _opt(data)
    elif opts.job == 'opt':
        _opt(data)
    elif opts.job == 'sp':
        _sp(data)
    elif opts.job == 'vib':
        print(opts.job, "not yet implemented")
    else:
        print(opts.job, "not yet implemented")
Example #5
0
 def extracter(self, trait):
     self.ccfile = ccopen(self.outFile)  #opens the out file in cclib
     self.ccfile.logger.setLevel(
         logging.ERROR
     )  # avoid printing to the screen all the data cclib wants to print
     data = self.ccfile.parse(
     )  # data contain anything cclib knows to extract
     return getattr(data, trait)
Example #6
0
def get_xyz_block_from_log(logfile_path):
    myfile = ccopen(logfile_path,loglevel=logging.WARN)
    data   = myfile.parse()
    lines = get_last_coord_block_str(logfile_path, data = data).split('\n')
    scfener = data.scfenergies[-1]
    result = '{0: >5d}\n'.format(len(lines))
    result +=  'scf done:{0: >13.6f}\n'.format(scfener)
    for l in lines:
        result += ' ' + l + '\n'
    return result
Example #7
0
    def run_calculations(self, fname):
        niedoida = "./niedoida"

        inp_fname = fname + ".inp"
        log_fname = fname + ".log"

        subprocess.check_call([niedoida, inp_fname])
        log = ccopen(log_fname)
        log.logger.setLevel(logging.WARNING)
        return log.parse()
Example #8
0
def CalcJ(namejob):
    molA_parser = ccopen("part1/" + namejob + "part1.log")
    molB_parser = ccopen("part2/" + namejob + "part2.log")
    molAB_parser = ccopen("dim/" + namejob + "dim.log")

    molA = molA_parser.parse()
    molB = molB_parser.parse()
    molAB = molAB_parser.parse()
    print("Parsed...")

    nbs = molAB.nbasis
    if molA.nbasis != molB.nbasis:
        print("Count of basis functions doesn't match. Failing.")
        return False

    for mole in molA, molB, molAB:
        if len(mole.atomcoords) != 1:
            print(mole +
                  " calculation appears to be an optimisation! Failing.")

#Take mocoeffs[0] - the alpha electrons to get matrix in correct order
    MolAB_Pro = np.transpose(np.dot(molAB.mocoeffs[0], molAB.aooverlaps))
    #    print "DimPro via JKP:", DimPro, "DimPro2 via JMF", DimPro2

    #    print "Psi1DimBS via JKP: ", Psi1DimBS
    PsiA_DimBS = np.dot(molA.mocoeffs[0], MolAB_Pro)
    PsiB_DimBS = np.dot(molB.mocoeffs[0], MolAB_Pro)
    #    print "Dim Mocoeffs: ", molAB.moenergies[0]/27.211

    #Note: moenergies in eV, so converted to Hartree for checking with JKP code
    JAB = np.dot(np.dot(np.diagflat(molAB.moenergies[0] / 27.211), PsiA_DimBS),
                 np.transpose(PsiB_DimBS))
    JAA = np.dot(np.dot(np.diagflat(molAB.moenergies[0] / 27.211), PsiA_DimBS),
                 np.transpose(PsiA_DimBS))
    JBB = np.dot(np.dot(np.diagflat(molAB.moenergies[0] / 27.211), PsiB_DimBS),
                 np.transpose(PsiB_DimBS))

    print "JAB", JAB
    print "JAA", JAA
    print "JBB", JBB

    return [JAB, JAA, JBB]
Example #9
0
def get_point_charges_qmout(pc_file_path, pc_type):
    """Use cclib to parse a QM output file for point charges (Mulliken,
    Lowdin, CHELPG, ...).
    """

    from cclib.parser import ccopen

    job = ccopen(pc_file_path)
    data = job.parse()

    return data.atomcharges[pc_type]
Example #10
0
    def extractcalcdata(self):
        if len(self.gjfs) > 0:
            self.log("\tExtracting data from log files")
            tostore = []
            for j, pname in enumerate(self.gjforder):
                mylogfile = os.path.join("gaussian", "%d.out.gz" % j)
                if not os.path.isfile(mylogfile):
                    continue
                text = gzip.open(mylogfile, "r").read()
                if text.find(
                        "Excitation energies and oscillator strength") < 0:
                    continue
                lines = iter(text.split("\n"))
                for line in lines:
                    if line.startswith(" #T PM6 OPT"):
                        line = lines.next()
                        line = lines.next()
                        line = lines.next()
                        break
                for line in lines:
                    if line.startswith(" Initial command"): break
                zindofile = list(lines)
                if len(zindofile) == 0:
                    # All the PM6 data is missing
                    continue
                with open("tmp.out", "w") as f:
                    f.write("\n".join(zindofile))
                logfile = ccopen("tmp.out")
                logfile.logger.setLevel(logging.ERROR)
                try:
                    data = logfile.parse()
                except AssertionError:
                    continue
                try:
                    lumo = data.moenergies[0][data.homos[0] + 1]
                    h**o = data.moenergies[0][data.homos[0]]
                    etens = [x * convert
                             for x in data.etenergies]  # cm-1 to eV
                    etoscs = data.etoscs
                except:
                    continue
                if max(etens) <= 0:
                    continue


##                myjson = json.dumps([h**o, lumo, etens, etoscs])
                myjson = json.dumps([
                    h**o, lumo, etens, etoscs, data.moenergies[0],
                    data.homos[0]
                ])
                tostore.append((pname, myjson))

            for pname, myjson in tostore:
                self.admin.storedata(pname, self.gen, myjson)
Example #11
0
    def generate_data(self,
                      request,
                      experiment_output,
                      experiment,
                      output_file=None,
                      **kwargs):

        # Parse output_file
        output_text = io.TextIOWrapper(output_file)
        gaussian = ccopen(output_text)
        data = gaussian.parse()
        data.listify()
        homo_eigenvalues = None
        lumo_eigenvalues = None
        if hasattr(data, 'homos') and hasattr(data, 'moenergies'):
            homos = data.homos[0] + 1
            moenergies = data.moenergies[0]
            if homos > 9 and len(moenergies) >= homos:
                homo_eigenvalues = [
                    data.moenergies[0][homos - 1 - i] for i in range(1, 10)
                ]
            if homos + 9 <= len(moenergies):
                lumo_eigenvalues = [
                    data.moenergies[0][homos + i] for i in range(1, 10)
                ]

        # Create plot
        fig = Figure()
        if homo_eigenvalues and lumo_eigenvalues:
            fig.suptitle("Eigenvalues")
            ax = fig.subplots(2, 1)
            ax[0].plot(range(1, 10), homo_eigenvalues, label='H**o')
            ax[0].set_ylabel('eV')
            ax[0].legend()
            ax[1].plot(range(1, 10), lumo_eigenvalues, label='Lumo')
            ax[1].set_ylabel('eV')
            ax[1].legend()
        else:
            ax = fig.subplots()
            ax.text(0.5,
                    0.5,
                    "No applicable data",
                    horizontalalignment='center',
                    verticalalignment='center',
                    transform=ax.transAxes)

        # Export plot as image buffer
        buffer = io.BytesIO()
        fig.savefig(buffer, format='png')
        image_bytes = buffer.getvalue()
        buffer.close()

        # return dictionary with image data
        return {'image': image_bytes, 'mime-type': 'image/png'}
Example #12
0
def main():
    """Goal: Identify first atom in product.out based on connectivity"""
    ccproduct = ccopen('product.out').parse()
    product = ccData_xyz(ccproduct.getattributes(), ccdataconvert=True)
    product.build_zmatrix()

    elements = set(product.elements)

    atom0 = NodeAtom(product, index=0)
    #atom0.children.pop(0)

    atom1 = NodeAtom(product, index=1)
    for child in [x for x in atom0.children if x.index == 0]:
        atom0.children.remove(child)

    #D0 = build_distancematrix(atom0, elements, 3, ignore=[1])
    D1 = build_distancematrix(atom1, elements, 3, ignore=[0])

    ccr2 = ccopen('r2.out').parse()
    r2 = ccData_xyz(ccr2.getattributes(), ccdataconvert=True)
    r2.build_zmatrix()

    print(r2.connectivity)
    print(product.connectivity)
    atom1.nodeprint()

    for i in range(len(r2.atomnos)):
        atomtree = NodeAtom(r2, index=i)
        distancematrix = build_distancematrix(atomtree, elements, 3)

        if dstmat_equal(distancematrix, D1):
            print('Atom 1 found')
            break

    print('Atom 1 in reactant:')
    for dst in distancematrix:
        print(dst)

    print('Atom 1 in product:')
    for dst in D1:
        print(dst)
Example #13
0
def main():
    """Goal: Identify first atom in product.out based on connectivity"""
    ccproduct = ccopen('product.out').parse()
    product = ccData_xyz(ccproduct.getattributes(), ccdataconvert=True)
    product.build_zmatrix()

    elements = set(product.elements)

    atom0 = NodeAtom(product, index=0)
    #atom0.children.pop(0)

    atom1 = NodeAtom(product, index=1)
    for child in [x for x in atom0.children if x.index == 0]:
        atom0.children.remove(child)

    #D0 = build_distancematrix(atom0, elements, 3, ignore=[1])
    D1 = build_distancematrix(atom1, elements, 3, ignore=[0])

    ccr2 = ccopen('r2.out').parse()
    r2 = ccData_xyz(ccr2.getattributes(), ccdataconvert=True)
    r2.build_zmatrix()

    print(r2.connectivity)
    print(product.connectivity)
    atom1.nodeprint()

    for i in range(len(r2.atomnos)):
        atomtree = NodeAtom(r2, index=i)
        distancematrix = build_distancematrix(atomtree, elements, 3)

        if dstmat_equal(distancematrix, D1):
            print('Atom 1 found')
            break

    print('Atom 1 in reactant:')
    for dst in distancematrix:
        print(dst)

    print('Atom 1 in product:')
    for dst in D1:
        print(dst)
Example #14
0
def main():

    stretch('product.out')

    rfiles = ['r1.out', 'r2.out']
    reactants = []
    for rfile in rfiles:
        tmp = ccopen(rfile).parse()
        reactants.append(ccData_xyz(tmp.getattributes(), ccdataconvert=True))

    for reactant in reactants:
        reactant.build_zmatrix()
        reactant.print_gzmat()
def CalcJ(namejob):
    molA_parser=ccopen("part1/"+namejob+"part1.log")
    molB_parser=ccopen("part2/"+namejob+"part2.log")
    molAB_parser=ccopen("dim/"+namejob+"dim.log")

    molA=molA_parser.parse()
    molB=molB_parser.parse()
    molAB=molAB_parser.parse()
    print ("Parsed...")

    nbs=molAB.nbasis
    if molA.nbasis!=molB.nbasis:
	print("Count of basis functions doesn't match. Failing.")
	return False

    for mole in molA,molB,molAB:
        if len(mole.atomcoords)!=1:
	    print(mole+" calculation appears to be an optimisation! Failing.")

#Take mocoeffs[0] - the alpha electrons to get matrix in correct order
    MolAB_Pro = np.transpose(np.dot(molAB.mocoeffs[0],molAB.aooverlaps))
#    print "DimPro via JKP:", DimPro, "DimPro2 via JMF", DimPro2

#    print "Psi1DimBS via JKP: ", Psi1DimBS
    PsiA_DimBS = np.dot(molA.mocoeffs[0], MolAB_Pro)
    PsiB_DimBS = np.dot(molB.mocoeffs[0], MolAB_Pro)
#    print "Dim Mocoeffs: ", molAB.moenergies[0]/27.211


#Note: moenergies in eV, so converted to Hartree for checking with JKP code
    JAB=np.dot(np.dot(np.diagflat(molAB.moenergies[0]/27.211),PsiA_DimBS), np.transpose(PsiB_DimBS) )
    JAA=np.dot(np.dot(np.diagflat(molAB.moenergies[0]/27.211),PsiA_DimBS), np.transpose(PsiA_DimBS) )
    JBB=np.dot(np.dot(np.diagflat(molAB.moenergies[0]/27.211),PsiB_DimBS), np.transpose(PsiB_DimBS) )

    print "JAB", JAB
    print "JAA", JAA
    print "JBB", JBB

    return [JAB, JAA, JBB]
Example #16
0
def main():

    stretch('product.out')

    rfiles = ['r1.out', 'r2.out']
    reactants = []
    for rfile in rfiles:
        tmp = ccopen(rfile).parse()
        reactants.append(ccData_xyz(tmp.getattributes(), ccdataconvert=True))

    for reactant in reactants:
        reactant.build_zmatrix()
        reactant.print_gzmat()
Example #17
0
    def extractcalcdata(self):
        if len(self.gjfs) > 0:
            self.log("\tExtracting data from log files")
            tostore = []
            for j, pname in enumerate(self.gjforder):

                print 'on pname=%s, j=%s' % (pname, j)

                mylogfile = os.path.join("gaussian", "%d.out.gz" % j)
                if not os.path.isfile(mylogfile):
                    continue
                #logfile = ccopen("tmp.out")
                logfile = ccopen(mylogfile)
                logfile.logger.setLevel(logging.ERROR)
                try:
                    data = logfile.parse()
                except AssertionError:
                    continue
                try:
                    lumo = data.moenergies[0][data.homos[0] + 1]
                    h**o = data.moenergies[0][data.homos[0]]
                    etens = [x * convert
                             for x in data.etenergies]  # cm-1 to eV
                    etoscs = data.etoscs
                except:
                    continue
                if max(etens) <= 0:
                    continue

                #myjson = json.dumps([h**o, lumo, etens, etoscs.tolist()])
                # adds JSON with H**O, LUMO, electronic transition energies, et oscillator strengths
                # and then all the MO energies

                myjson = json.dumps([
                    float(h**o),
                    float(lumo), etens,
                    list(etoscs),
                    list(data.moenergies[0]),
                    int(data.homos[0])
                ])
                tostore.append((pname, myjson))

            for pname, myjson in tostore:
                # get the sequence
                output = get_comb(pname, self.length)
                seq = output[0]
                # chain the .replace(old, new) function to replace id with A, di with B, uq with D, qu with E
                seqSym = seq.replace("(qu)", "A").replace("(uq)", "B").replace(
                    "(di)", "D").replace("(id)", "E")
                self.admin.storedata(pname, self.gen, seqSym, myjson)
Example #18
0
 def parse(self):
     """Parse the logfile and assign the discrete spectrum values."""
     try:
         if os.path.exists(self.name):
             logfile = ccopen(self.name)
             logfile.logger.setLevel(logging.ERROR)
             data = logfile.parse()
             setattr(self, 'excited_state_energy', data.etenergies)
             setattr(self, 'oscillator_strength', data.etoscs)
         else:
             error('The logfile `%s` could not be found' % self.name)
     except TypeError:
         error('The `parse()` method requires the `filename` argument '
               'in `Logfile`')
Example #19
0
    def parser(self):
        progresser = progress.TextProgress()  #text nprogress stores logs
        filer = Gauparse.ccopen(self.filename, progresser, logging.ERROR)
        attrs = filer.parse()
        entries = []

        for attr in attrs.__dict__:
            if re.match("_(.*)", attr):
                pass
            else:
                entries.append((attr, attrs.__dict__[attr]))
            for entry in entries:
                print str(entry)
                print '\n\n\n'
Example #20
0
 def parse(self):
     """Parse the logfile and assign the discrete spectrum values."""
     try:
         if os.path.exists(self.name):
             logfile = ccopen(self.name)
             logfile.logger.setLevel(logging.ERROR)
             data = logfile.parse()
             setattr(self, 'excited_state_energy', data.etenergies)
             setattr(self, 'oscillator_strength', data.etoscs)
         else:
             error('The logfile `%s` could not be found' % self.name)
     except TypeError:
         error('The `parse()` method requires the `filename` argument '
               'in `Logfile`')
Example #21
0
def add_geomtotxt(egeom,geomfile):
    #print(geomfile.get())
    #f=open(geomfile.get())
    #print(f.read())
    from cclib.parser import ccopen
    if geomfile.get() == '':
        print("No log file!")
        filetypes=(("Gaussian Output","*.log"),("all files","*.*"))
        logfile = askopenfilename(filetypes = filetypes)
    else:
        logfile = ccopen(geomfile.get())
    data = logfile.parse()
    for i in range(len(data.atomnos)):

        egeom.insert(END,pertable[data.atomnos[i]]+" "+str(data.atomcoords[-1,i,0])+" "+str(data.atomcoords[-1,i,1])+" "+str(data.atomcoords[-1,i,2])+"\n")
    egeom.setvar()
Example #22
0
def get_CO2_frequencies_4fs(outputfilenames):
    """The same as above, but for the snapshots separated by 4fs."""

    snapnums = []
    CO2_frequencies = []
    CO2_intensities = []

    for outputfilename in outputfilenames:
        print("Parsing frequencies from {}".format(outputfilename))

        job = ccopen(outputfilename)
        try:
            data = job.parse()
        except:
            # Is this the right control flow statement?
            continue
        # geometry = data.atomcoords[-1]
        # atoms = data.atomnos
        # start_indices = find_CO2_atom_indices(atoms, geometry)
        # assert isinstance(start_indices, list)
        try:
            vibfreqs = data.vibfreqs
            vibdisps = data.vibdisps
            vibirs = data.vibirs
        except AttributeError:
            # Is this the correct control flow statement?
            continue
        # Assumption!
        # start_index = start_indices[0]
        # Assumption?
        start_index = 0
        mode_indices = find_CO2_mode_indices(start_index, vibdisps, thresh=0.50)
        # mode_indices = [2]
        # freqs = [vibfreqs[modeidx] for modeidx in mode_indices]
        # freqs = filter(lambda x: x > 0.0, freqs)
        # print(freqs)
        # Let's only take the last one...
        # print(outputfilename)
        CO2_frequencies.append(vibfreqs[mode_indices[-1]])
        CO2_intensities.append(vibirs[mode_indices[-1]])
        snapnum = int(re.search(r'drop_(\d+)', outputfilename).groups()[0])
        snapnums.append(snapnum)

    return CO2_frequencies, CO2_intensities, snapnums
Example #23
0
    def extractcalcdata(self):
        if len(self.gjfs) > 0:
            self.log("\tExtracting data from log files")
            tostore = []
            for j, pname in enumerate(self.gjforder):

                print 'on pname=%s, j=%s' % (pname, j)

                mylogfile = os.path.join("gaussian", "%d.log.gz" % j)
                if not os.path.isfile(mylogfile):
                    continue
                # logfile = ccopen("tmp.out")
                logfile = ccopen(mylogfile)
                logfile.logger.setLevel(logging.ERROR)
                try:
                    data = logfile.parse()
                except AssertionError:
                    continue
                try:
                    # Values rounded to reduce size of output file
                    lumo = round(data.moenergies[0][data.homos[0] + 1], 3)
                    h**o = round(data.moenergies[0][data.homos[0]], 3)
                    etens = [round(x*convert, 3) for x in data.etenergies] # cm-1 to eV
                    etoscs = [round(x, 3) for x in data.etoscs]
                except:
                    continue
                if max(etens) <= 0:
                    continue

                # File stores too much info for large data set, so use other function (below) which saves fewer energies
                #myjson = json.dumps([float(h**o), float(lumo), etens, list(etoscs), list(data.moenergies[0]), int(data.homos[0])])
                #tostore.append((pname, myjson))

                myjson = json.dumps([float(h**o), float(lumo), etens, list(etoscs)])
                tostore.append((pname, myjson))

            for pname, myjson in tostore:
                # get the sequence
                output = get_comb(pname, self.length)
                seq = output[0]
                # chain the .replace(old, new) function to replace id with A, di with B, uq with D, qu with E to make
                # sequences easier to read
                seqSym = seq.replace("(qu)", "A").replace("(uq)", "B").replace("(di)", "D").replace("(id)", "E")
                self.admin.storedata(pname, self.gen, seqSym, myjson)
Example #24
0
def get_CO2_frequencies(outputfilenames):

    snapnums = []
    CO2_frequencies = []
    CO2_intensities = []

    for outputfilename in outputfilenames:
        print("Parsing frequencies from {}".format(outputfilename))

        job = ccopen(outputfilename)
        try:
            data = job.parse()
        except:
            # Is this the right control flow statement?
            continue
        # geometry = data.atomcoords[-1]
        # atoms = data.atomnos
        # start_indices = find_CO2_atom_indices(atoms, geometry)
        # assert isinstance(start_indices, list)
        try:
            vibfreqs = data.vibfreqs
            vibirs = data.vibirs
        except AttributeError:
            # Is this the correct control flow statement?
            continue
        # Assumption!
        # start_index = start_indices[0]
        # Assumption?
        start_index = len(data.atomnos) - 3
        # mode_indices = find_CO2_mode_indices(start_index, vibdisps, thresh=0.50)
        mode_indices = [2]
        # freqs = [vibfreqs[modeidx] for modeidx in mode_indices]
        # freqs = filter(lambda x: x > 0.0, freqs)
        # print(freqs)
        # Let's only take the last one...
        # print(outputfilename)
        CO2_frequencies.append(vibfreqs[mode_indices[-1]])
        CO2_intensities.append(vibirs[mode_indices[-1]])
        snapnum = int(re.search('drop_(\d+)_', outputfilename).groups()[0])
        snapnums.append(snapnum)

    return CO2_frequencies, CO2_intensities, snapnums
Example #25
0
def get_last_coord_block_str(log,step=None, data = None):
    """
    Open gaussian log file and prints last coordinates of atoms
    as a block for creating new input file.
    """
    if data == None:
        myfile = ccopen(log,loglevel=logging.WARN)
        data   = myfile.parse()

    if not step:
        coords = data.atomcoords[-1]
    else:
        coords = data.atomcoords[step]
    rows = []
    t = PeriodicTable()
    for i in range(len(coords)):
        strrow_l        = [t.element[data.atomnos[i]]]
        strrow_l.extend(['{0: >12.6f}'.format(x) for x in coords[i]])
        rows.append(''.join(strrow_l))
    coord_block = '\n'.join(rows + [''])
    return coord_block
Example #26
0
    def fileopen(self):
        if self.inputfilename != None:
            mydir = os.path.dirname(self.inputfilename)
        else:
            mydir = "."

        inputfilename = tkinter.filedialog.askopenfilename(filetypes=[
            ("All files", ".*"), ("Output Files", ".out"),
            ("Log Files", ".log"), ("ADF output", ".adfout")
        ],
                                                           initialdir=mydir)

        if inputfilename != "":
            self.inputfilename = os.path.basename(inputfilename)
            os.chdir(os.path.dirname(inputfilename))
            # Create an instance of the parser
            if hasattr(self, "logfile") and self.logfile != None:
                self.logfile.logger.removeHandler(
                    self.logfile.logger.handlers[0])
            self.logfile = ccopen(self.inputfilename)
            self.fileopenednow()
Example #27
0
def add_calcul2list(file,molid,t):
    t.destroy()
    print('Opening file')
    log = open(file).read()
    # print("Test reading")
    # print(log)
    basis,funct = scanbasis(file)
    #scanfreq(file)
    from cclib.parser import ccopen
    logfile = ccopen(file)
    data = logfile.parse()
    freqanharm = np.zeros(len(data.vibfreqs))
    intensanharmtmp = np.zeros(len(data.vibfreqs))
    intensanharm = np.zeros(len(data.vibfreqs))
    freqanharmscan(file,freqanharm,intensanharmtmp,len(data.vibfreqs))
    print(freqanharm)
    sort = np.argsort(freqanharm)
    freqanharm=np.sort(freqanharm)
    for k in range(len(intensanharmtmp)):
        intensanharm[k]=intensanharmtmp[sort[k]]
    db.insertcalc(molid,data,freqanharm,intensanharm,"B3LYP",basis,log)
def main(args):

    hessian = read_scratch_hessian(os.path.join(args.scratchdir, 'HESS'))
    atomsyms = read_scratch_molecule(os.path.join(args.scratchdir, 'molecule'))
    atommasses = atomsyms2atommasses(atomsyms)
    hessian_mw = hessian_mass_weight_4(hessian, atommasses)
    eigvals, eigvecs = np.linalg.eigh(hessian_mw)
    frequencies = np.lib.scimath.sqrt(eigvals)[6:] * vib_constant
    print(complex_as_negative(frequencies))

    if args.outputfile:
        from cclib.parser import ccopen
        job = ccopen(args.outputfile)
        data = job.parse()
        hessian_outputfile = data.hessian
        hessian_outputfile_mw = hessian_mass_weight_4(hessian_outputfile, atommasses)
        eigvals_outputfile, eigvecs_outputfiles = np.linalg.eigh(hessian_outputfile_mw)
        frequencies_outputfile_hess = np.lib.scimath.sqrt(eigvals_outputfile)[6:] * vib_constant
        frequencies_outputfile  = data.vibfreqs
        print(complex_as_negative(frequencies_outputfile_hess))
        print(frequencies_outputfile)

if __name__ == '__main__':

    import cclib
    from cclib.parser import ccopen
    from cclib.parser.utils import convertor

    args = getargs()

    for qmoutputfile in args.qmoutputfile:

        qmoutputfile = os.path.abspath(qmoutputfile)
        print(qmoutputfile)

        job = ccopen(qmoutputfile)

        if job:
            data = job.parse()

            idx_homo = data.homos[-1]
            idx_lumo = idx_homo + 1

            steps = len(data.scfenergies)
            total_e = convertor(data.scfenergies[-1], 'eV', 'hartree')
            h**o = convertor(data.moenergies[-1][idx_homo], 'eV', 'hartree')
            lumo = convertor(data.moenergies[-1][idx_lumo], 'eV', 'hartree')

            job_type = determine_job_type(job)
            total_time = extract_total_time(qmoutputfile, job_type)
            time_per_step = total_time / steps
Example #30
0
def parse(file_name, output_file_name):
    result = OrderedDict()
    identifiers = OrderedDict()
    calculation = OrderedDict()
    molecule = OrderedDict()
    calculated_properties = OrderedDict()
    execution_environment = OrderedDict()
    molecule_structural_formats = OrderedDict()

    # extracting fields from open-babel
    mol = pybel.readfile('mpo', file_name).next()
    identifiers['InChI'] = mol.write('inchi').strip()
    identifiers['InChIKey'] = mol.write('inchikey').strip()
    identifiers['SMILES'] = mol.write('smiles').split('\t')[0]
    identifiers['CanonicalSMILES'] = mol.write('can').split('\t')[0]
    molecule_structural_formats['PDB'] = mol.write('pdb').split('\t')[0]
    molecule_structural_formats['SDF'] = mol.write('sdf').split('\t')[0]

    # extracting fields from ccdbt
    parser_pyramid = ParserPyramid()
    meta_f = metafile(file_name)
    if meta_f.parse(parser_pyramid):
        if 'CodeVersion' in meta_f.record:
            calculation['Package'] = meta_f.record['CodeVersion']
        if 'Methods' in meta_f.record:
            calculation['Methods'] = meta_f.record['Methods']
        if 'Keywords' in meta_f.record:
            calculation['Keywords'] = meta_f.record['Keywords']
        if 'Basis' in meta_f.record:
            calculation['Basis'] = meta_f.record['Basis']
        if 'CalcType' in meta_f.record:
            calculation['CalcType'] = meta_f.record['CalcType']
        if 'JobStatus' in meta_f.record:
            calculation['JobStatus'] = meta_f.record['JobStatus']

        if 'Formula' in meta_f.record:
            molecule['Formula'] = meta_f.record['Formula']
        if 'OrbSym' in meta_f.record:
            molecule['OrbSym'] = meta_f.record['OrbSym']
        if 'Multiplicity' in meta_f.record:
            molecule['Multiplicity'] = meta_f.record['Multiplicity']
        if 'Charge' in meta_f.record:
            molecule['Charge'] = meta_f.record['Charge']
        if 'ElecSym' in meta_f.record:
            molecule['ElecSym'] = meta_f.record['ElecSym']

        if 'Energy' in meta_f.record:
            calculated_properties['Energy'] = meta_f.record['Energy']
        if 'Dipole' in meta_f.record:
            calculated_properties['Dipole'] = meta_f.record['Dipole']
        if 'HF' in meta_f.record:
            calculated_properties['HF'] = meta_f.record['HF']

        if 'CalcMachine' in meta_f.record:
            execution_environment['CalcMachine'] = meta_f.record['CalcMachine']
        if 'FinTime' in meta_f.record:
            execution_environment['FinTime'] = meta_f.record['FinTime']
            fin_date = datetime.strptime(execution_environment['FinTime'], '%d %b %y')
            execution_environment['FinTimeStamp'] = datetime.utcfromtimestamp(calendar.timegm(fin_date.timetuple()))
        if 'CalcBy' in meta_f.record:
            execution_environment['CalcBy'] = meta_f.record['CalcBy']

        # Rest of the key value pairs are not updated by the seagrid-data
        if 'ParsedBy' in meta_f.record:
            result['ParsedBy'] = meta_f.record['ParsedBy']
        if 'NumBasis' in meta_f.record:
            result['NumBasis'] = meta_f.record['NumBasis']
        if 'NumFC' in meta_f.record:
            result['NumFC'] = meta_f.record['NumFC']
        if 'NumVirt' in meta_f.record:
            result['NumVirt'] = meta_f.record['NumVirt']
        if 'InitGeom' in meta_f.record:
            result['InitGeom'] = meta_f.record['InitGeom']
        if 'FinalGeom' in meta_f.record:
            result['FinalGeom'] = meta_f.record['FinalGeom']
        if 'PG' in meta_f.record:
            result['PG'] = meta_f.record['PG']
        if 'NImag' in meta_f.record:
            result['NImag'] = meta_f.record['NImag']
        if 'EnergyKcal' in meta_f.record:
            result['EnergyKcal'] = meta_f.record['EnergyKcal']
        if 'ZPE' in meta_f.record:
            result['ZPE'] = meta_f.record['ZPE']
        if 'ZPEKcal' in meta_f.record:
            result['ZPEKcal'] = meta_f.record['ZPEKcal']
        if 'HFKcal' in meta_f.record:
            result['HFKcal'] = meta_f.record['HFKcal']
        if 'Thermal' in meta_f.record:
            result['Thermal'] = meta_f.record['Thermal']
        if 'ThermalKcal' in meta_f.record:
            result['ThermalKcal'] = meta_f.record['ThermalKcal']
        if 'Enthalpy' in meta_f.record:
            result['Enthalpy'] = meta_f.record['Enthalpy']
        if 'EnthalpyKcal' in meta_f.record:
            result['EnthalpyKcal'] = meta_f.record['EnthalpyKcal']
        if 'Entropy' in meta_f.record:
            result['Entropy'] = meta_f.record['Entropy']
        if 'EntropyKcal' in meta_f.record:
            result['EntropyKcal'] = meta_f.record['EntropyKcal']
        if 'Gibbs' in meta_f.record:
            result['Gibbs'] = meta_f.record['Gibbs']
        if 'GibbsKcal' in meta_f.record:
            result['GibbsKcal'] = meta_f.record['GibbsKcal']
        if 'Freq' in meta_f.record:
            result['Freq'] = meta_f.record['Freq']
        if 'AtomWeigh' in meta_f.record:
            result['AtomWeigh'] = meta_f.record['AtomWeigh']
        if 'Conditions' in meta_f.record:
            result['Conditions'] = meta_f.record['Conditions']
        if 'ReacGeom' in meta_f.record:
            result['ReacGeom'] = meta_f.record['ReacGeom']
        if 'ProdGeom' in meta_f.record:
            result['ProdGeom'] = meta_f.record['ProdGeom']
        if 'MulCharge' in meta_f.record:
            result['MulCharge'] = meta_f.record['MulCharge']
        if 'NatCharge' in meta_f.record:
            result['NatCharge'] = meta_f.record['NatCharge']
        if 'S2' in meta_f.record:
            result['S2'] = meta_f.record['S2']
        if 'MemCost' in meta_f.record:
            result['MemCost'] = meta_f.record['MemCost']
        if 'TimeCost' in meta_f.record:
            result['TimeCost'] = meta_f.record['TimeCost']
        if 'CPUTime' in meta_f.record:
            result['CPUTime'] = meta_f.record['CPUTime']
        if 'Convergence' in meta_f.record:
            result['Convergenece'] = meta_f.record['Convergence']
        if 'FullPath' in meta_f.record:
            result['FullPath'] = meta_f.record['FullPath']
        if 'InputButGeom' in meta_f.record:
            result['InputButGeom'] = meta_f.record['InputButGeom']
        if 'Otherinfo' in meta_f.record:
            result['Otherinfo'] = meta_f.record['Otherinfo']
        if 'Comments' in meta_f.record:
            result['Comments'] = meta_f.record['Comments']
        # End of not updated key-value pairs

    # extracting fields from cclib
    myfile = ccopen(file_name)
    try:
        data = myfile.parse()
        data.listify()
        if hasattr(data, 'natom'):
            molecule['NAtom'] = data.natom
        if hasattr(data, 'homos'):
            calculated_properties['Homos'] = data.homos
        if hasattr(data, 'scfenergies'):
            result['ScfEnergies'] = data.scfenergies        # Not updated by the seagrid-data
        if hasattr(data, 'coreelectrons'):
            result['CoreElectrons'] = data.coreelectrons    # Not updated by the seagrid-data
        if hasattr(data, 'moenergies'):
            result['MoEnergies'] = data.moenergies          # Not updated by the seagrid-data
        if hasattr(data, 'atomcoords'):
            result['AtomCoords'] = data.atomcoords          # Not updated by the seagrid-data
        if hasattr(data, 'scftargets'):
            result['ScfTargets'] = data.scftargets          # Not updated by the seagrid-data
        if hasattr(data, 'nmo'):
            molecule['Nmo'] = data.nmo
        if hasattr(data, 'nbasis'):
            calculation['NBasis'] = data.nbasis
        if hasattr(data, 'atomnos'):
            result['AtomNos'] = data.atomnos                # Not updated by the seagrid-data
    except:
        sys.stderr.write('cclib parsing failed!')

    # Drawing the molecule
    # mol.draw(show=False, filename=molecule_image_file)

    result['Identifiers'] = identifiers
    result['Calculation'] = calculation
    result['Molecule'] = molecule
    result['CalculatedProperties'] = calculated_properties
    result['ExecutionEnvironment'] = execution_environment
    result['FinalMoleculeStructuralFormats'] = molecule_structural_formats

    result = json.dumps(result, separators=(',', ':'), sort_keys=False, indent=4)
    json.dump()
    output_file = open(output_file_name, 'w')
    for row in result:
        output_file.write(row)
    output_file.close()
Example #31
0
def CalcJ():
    #
    #molA_parser=ccopen("part1/"+namejob+"part1.log")
    #molB_parser=ccopen("part2/"+namejob+"part2.log")
    #molAB_parser=ccopen("dim/"+namejob+"dim.log")

    MOLA_CP=sys.argv[1]
    MOLB_CP=sys.argv[2]
    MOLAB_CP=sys.argv[3]
# Open the Gaussian 'log' files with CCLIB
    molA_parser=ccopen("%s"%(MOLA_CP))
    molB_parser=ccopen("%s"%(MOLB_CP))
    molAB_parser=ccopen("%s"%(MOLAB_CP))

# Parse the logfiles into mol{A,B,AB} objects
    molA=molA_parser.parse()
    molB=molB_parser.parse()
    molAB=molAB_parser.parse()
    print("Gaussian logfiles Loaded and Parsed...")

    nbs=molAB.nbasis
    if molA.nbasis!=molB.nbasis:
        print("Number of basis functions in molA and molB. Failing.")
        return False

    for mole in molA,molB,molAB:
        if len(mole.atomcoords)!=1:
            print(mole," calculation appears to be an optimisation (multiple steps)! Warning!")

    nhomoA=molA.homos
    nhomoB=molB.homos
    nhomoAB=molAB.homos

    print("Energy splitting in dimer")
    print('ESID H**O-H**O coupling: ',(molAB.moenergies[0][nhomoAB]-molAB.moenergies[0][nhomoAB-1])/2.0," eV")
    print('ESID LUMO-LUMO coupling: ',(molAB.moenergies[0][nhomoAB+2]-molAB.moenergies[0][nhomoAB+1])/2.0," eV")

#Take mocoeffs[0] - the alpha electrons, to get matrix in correct order
    MolAB_Pro = np.transpose(np.dot(molAB.mocoeffs[0],molAB.aooverlaps))
   
    PsiA_DimBS = np.dot(molA.mocoeffs[0], MolAB_Pro)
    PsiB_DimBS = np.dot(molB.mocoeffs[0], MolAB_Pro)
#    print "Dim Mocoeffs: ", molAB.moenergies[0]/27.211

# JMF 2009-08 CCLIB code to reproduce JKP's original values for Ethene. BELIEVED INCORRECT.
    print("Original James KP method; matrix multiplication believed out of order.")
    JAB=np.dot(np.dot(np.diagflat(molAB.moenergies[0]),PsiA_DimBS), np.transpose(PsiB_DimBS) )
    JAA=np.dot(np.dot(np.diagflat(molAB.moenergies[0]),PsiA_DimBS), np.transpose(PsiA_DimBS) )
    JBB=np.dot(np.dot(np.diagflat(molAB.moenergies[0]),PsiB_DimBS), np.transpose(PsiB_DimBS) )

    print("JKP H**O-H**O coupling: ", JAB[nhomoA,nhomoB], " eV")
    print("JKP LUMO-LUMO coupling: ", JAB[nhomoA+1,nhomoB+1], " eV")
#Note: CCLIB values in eV, so converted to Hartree for checking with JKP original code
    print("JKP H**O-H**O coupling: ", JAB[nhomoA,nhomoB]/27.211, " Ha")
    print("JKP LUMO-LUMO coupling: ", JAB[nhomoA+1,nhomoB+1]/27.211, " Ha")

# JKP - 2009-09-10 update (script pasted into email)
    print("James KP 2009-09-10 re-order matrix multiplication...")
# this is the bit I changed: note the different order of multiplication
# I suspect that most mistakes will tend to be of that kind... x.y != y.x alas...

    JAB = np.dot(np.dot( PsiB_DimBS, np.diagflat(molAB.moenergies[0])) , np.transpose(PsiA_DimBS) )
    JAA = np.dot(np.dot( PsiA_DimBS, np.diagflat(molAB.moenergies[0])) , np.transpose(PsiA_DimBS) )
    JBB = np.dot(np.dot( PsiB_DimBS, np.diagflat(molAB.moenergies[0])) , np.transpose(PsiB_DimBS) )

    #print "JAB", JAB
    #print "JAA", JAA
    #print "JBB", JBB

# I think these are hardwired by James to look at ethene molecular orbital overlaps
    # print "PSI1 in dimer", PsiA_DimBS[3][0], PsiA_DimBS[3][1], PsiA_DimBS[3][2], PsiA_DimBS[3][3] , PsiA_DimBS[3][4], PsiA_DimBS[3][5], PsiA_DimBS[3][6], PsiA_DimBS[3][7]
    # print "PSI1 in dimer", PsiB_DimBS[3][0], PsiB_DimBS[3][1], PsiB_DimBS[3][2], PsiB_DimBS[3][3] , PsiB_DimBS[3][4], PsiB_DimBS[3][5], PsiB_DimBS[3][6], PsiB_DimBS[3][7]

    print("JKP2 H**O-H**O coupling: ", JAB[nhomoA,nhomoB], " eV")
    print("JKP2 LUMO-LUMO coupling: ", JAB[nhomoA+1,nhomoB+1], " eV")
#Note: CCLIB values in eV, so converted to Hartree for checking with JKP original code
    print("JKP2 H**O-H**O coupling: ", JAB[nhomoA,nhomoB]/27.211, " Ha")
    print("JKP2 LUMO-LUMO coupling: ", JAB[nhomoA+1,nhomoB+1]/27.211, " Ha")

# JMF 2016-10-04: These additions are I think due to Bjorn Baumeier 2009-09-17
# Determine overlap analogous to JAB
    SAB = np.dot(PsiB_DimBS , np.transpose(PsiA_DimBS) )
    # Calculate JAB_eff according to Eq.10 in JACS 128, 9884 (2006)
    # !only for the desired orbitals!

    print("Bjorn Baumeier JAB_eff (Eq.10 in JACS 128, 9884 (2006)) ")
    orbA=nhomoA
    orbB=nhomoB
    JAB_eff = (JAB[orbA,orbB] - 0.5*(JAA[orbA,orbA]+JBB[orbB,orbB])*SAB[orbA,orbB])/(1.0 - SAB[orbA,orbB]*SAB[orbA,orbB])
    print("Jeff H**O-H**O Jeff-coupling", JAB_eff," eV")

    orbA=nhomoA+1
    orbB=nhomoB+1
    JAB_eff = (JAB[orbA,orbB] - 0.5*(JAA[orbA,orbA]+JBB[orbB,orbB])*SAB[orbA,orbB])/(1.0 - SAB[orbA,orbB]*SAB[orbA,orbB])
    print("Jeff LUMO-LUMO Jeff-coupling", JAB_eff, " eV")

    return [JAB, JAA, JBB]
Example #32
0
        result['TimeCost'] = meta_f.record['TimeCost']
    if 'CPUTime' in meta_f.record:
        result['CPUTime'] = meta_f.record['CPUTime']
    if 'Convergence' in meta_f.record:
        result['Convergenece'] = meta_f.record['Convergence']
    if 'FullPath' in meta_f.record:
        result['FullPath'] = meta_f.record['FullPath']
    if 'InputButGeom' in meta_f.record:
        result['InputButGeom'] = meta_f.record['InputButGeom']
    if 'Otherinfo' in meta_f.record:
        result['Otherinfo'] = meta_f.record['Otherinfo']
    if 'Comments' in meta_f.record:
        result['Comments'] = meta_f.record['Comments']

#extracting fields from cclib
myfile = ccopen(file_name)
try:
    data = myfile.parse()
    data.listify()
    if hasattr(data, 'natom'):
        result['NAtom'] = data.natom
    if hasattr(data, 'homos'):
        result['Homos'] = data.homos
    if hasattr(data, 'scfenergies'):
        result['ScfEnergies'] = data.scfenergies
    if hasattr(data, 'coreelectrons'):
        result['CoreElectrons'] = data.coreelectrons
    if hasattr(data, 'moenergies'):
        result['MoEnergies'] = data.moenergies
    if hasattr(data, 'atomcoords'):
        result['AtomCoords'] = data.atomcoords
def CountPJ():
# Read in molecule log files for counterpoise method. Requires IOp(6/7=3) in Gaussian header + ghost atoms to make up basis sets in individual com files  
	MOLA_CP=sys.argv[1]
	MOLB_CP=sys.argv[2]
	MOLAB_CP=sys.argv[3]

# Open the log files
	molA_parser=ccopen("%s"%(MOLA_CP))
	molB_parser=ccopen("%s"%(MOLB_CP))
	molAB_parser=ccopen("%s"%(MOLAB_CP))

# Parse the relevant data
	molA=molA_parser.parse()
	molB=molB_parser.parse()
	molAB=molAB_parser.parse()

	print ("Parsed...")

# Size of basis sets
	Nbasis=molAB.nbasis

# H**O index
	nhomoA=molA.homos
	nhomoB=molB.homos
	nhomoAB=molAB.homos

	print "H**O A: ", nhomoA
	print "H**O B: ", nhomoB
	print "H**O AB: ", nhomoAB

# Every basis set should have the same size (the size of the pair) 
	if molA.nbasis!=molB.nbasis:
		print("Count of basis functions doesn't match. Failing.")
		return False

# Get molecular orbitals
	MOsA=(molA.mocoeffs[0])
	MOsB=(molB.mocoeffs[0])
	MOsAB=(molAB.mocoeffs[0])

	#print "MOsA: ", MOsA
	#print "MOsB: ", MOsB
	#print "MOsAB: ", MOsAB

# Get overlaps
	SAB=molAB.aooverlaps

	#print "Overlaps: ", SAB


# Get eigenvalues of pair
	EvalsAB=molAB.moenergies[0]

	print "Energies: ", molAB.moenergies
	print "Energies: ", EvalsAB
# Find H**O and LUMO from energy splitting in dimer

	print "ESID H**O-H**O coupling", 0.5*(EvalsAB[nhomoAB]-EvalsAB[nhomoAB-1])
	print "ESID LUMO-LUMO coupling", 0.5*(EvalsAB[nhomoAB+2]-EvalsAB[nhomoAB+1])

# Calculate the molecular orbitals of A and B in the AB basis set

	MolAB_Pro = (np.dot(MOsAB,SAB)).T
	PsiA_AB_BS = np.dot(MOsA, MolAB_Pro)
	PsiB_AB_BS = np.dot(MOsB, MolAB_Pro)

	#MolAB_Pro = (np.dot(MOsAB,SAB)).T
	#PsiA_AB_BS = np.dot(MOsA, MolAB_Pro)
	#PsiB_AB_BS = np.dot(MOsB, MolAB_Pro)

	#print "MolA in basis of dimer: ", PsiA_AB_BS

	#print "MolB in basis of dimer: ", PsiB_AB_BS

# Calculate the matrix of transfer integrals
	JAB=np.dot(np.dot(np.diagflat(EvalsAB),PsiA_AB_BS),PsiB_AB_BS.T)
	print "J matrix: ", JAB

# Print the H**O-H**O and LUMO-LUMO coupling
	print "H**O-H**O coupling: ", JAB[nhomoA,nhomoB]
	print "LUMO-LUMO coupling: ", JAB[nhomoA+1,nhomoB+1]
Example #34
0
def extract(filenames, equilibrium_length=None):

    frequencies = []
    intensities = []
    geometry_params = dict()
    geometry_params['geometry'] = []
    geometry_params['l1'] = []
    geometry_params['l2'] = []
    geometry_params['l12'] = []
    geometry_params['theta'] = []
    if equilibrium_length:
        geometry_params['l1_diff'] = []
        geometry_params['l2_diff'] = []
        geometry_params['l12_diff'] = []
        geometry_params['o12_diff'] = []

    for filename in filenames:

        try:

            job = ccopen(filename)
            data = job.parse()

            vibfreqs = data.vibfreqs
            vibirs = data.vibirs
            geometry = data.atomcoords[0]

            assert len(vibfreqs) == len(vibirs) >= 3

            frequencies.append(vibfreqs)
            intensities.append(vibirs)

            C, O1, O2 = 0, 1, 2

            d_C_O1 = distance(geometry[C], geometry[O1])
            d_C_O2 = distance(geometry[C], geometry[O2])
            d_O1_O2 = distance(geometry[O1], geometry[O2])

            bond_sum = d_C_O1 + d_C_O2
            # bond_difference = abs(d_C_O1 - d_C_O2)

            angle = bond_angle(geometry[O1], geometry[C], geometry[O2])
            theta = 180.0 - angle

            l1 = d_C_O1
            l2 = d_C_O2
            o12 = d_O1_O2
            l12 = bond_sum
            # dl = bond_difference

            if equilibrium_length:
                l1_diff = l1 - equilibrium_length
                l2_diff = l2 - equilibrium_length
                o12_diff = o12 - (2 * equilibrium_length)
                l12_diff = l12 - (2 * equilibrium_length)
                geometry_params['l1_diff'].append(l1_diff)
                geometry_params['l2_diff'].append(l2_diff)
                geometry_params['l12_diff'].append(l12_diff)
                geometry_params['o12_diff'].append(o12_diff)

            geometry_params['geometry'].append(geometry)
            geometry_params['l1'].append(l1)
            geometry_params['l2'].append(l2)
            geometry_params['l12'].append(l12)
            geometry_params['theta'].append(theta)

        except:
            pass

    frequencies = make_numpy_array_from_ragged_list(frequencies)
    intensities = make_numpy_array_from_ragged_list(intensities)
    for k in geometry_params:
        geometry_params[k] = np.array(geometry_params[k])

    print("frequencies.shape:", frequencies.shape)
    print("intensities.shape:", intensities.shape)
    print("geometry_params['geometry'].shape:", geometry_params['geometry'].shape)

    return frequencies, intensities, geometry_params
Example #35
0
def ProJ():
    # Read in molecule log files for projective method. Requires iop(3/33=1,6/7=3) in Gaussian header for calculation on each molecule + the pair
    MOLA_proj = sys.argv[1]
    MOLB_proj = sys.argv[2]
    MOLAB_proj = sys.argv[3]
    Degeneracy_HOMO = int(sys.argv[4])
    Degeneracy_LUMO = int(
        sys.argv[5])  # =0 for non-degenerate, 2,3 etc for doubly, triply etc

    # Open the log files
    molA_parser = ccopen("%s" % (MOLA_proj))
    molB_parser = ccopen("%s" % (MOLB_proj))
    molAB_parser = ccopen("%s" % (MOLAB_proj))

    # Parse the relevant data
    molA = molA_parser.parse()
    molB = molB_parser.parse()
    molAB = molAB_parser.parse()

    #print ("Parsed...")

    # Size of basis sets
    nbasisA = molA.nbasis
    nbasisB = molB.nbasis

    #print "nbasisA: ", nbasisA
    #print "nbasisB: ", nbasisB

    Nbasis = nbasisA + nbasisB

    # Position of H**O
    nhomoA = molA.homos
    nhomoB = molB.homos

    #print "nhomoA: ", nhomoA
    #print "nhomoB: ", nhomoB

    # Get molecular orbitals. Need the transpose for our purposes.
    MOsA = (molA.mocoeffs[0]).T
    MOsB = (molB.mocoeffs[0]).T
    MOsAB = (molAB.mocoeffs[0]).T

    # Get eigenvalues of pair
    EvalsAB = molAB.moenergies[0]

    # Get overlaps. These are symmetric so transpose not required in this case
    SA = molA.aooverlaps
    SB = molB.aooverlaps
    SAB = molAB.aooverlaps

    # Set up matrices for MOs and S
    MOs = np.zeros((Nbasis, Nbasis))
    S = np.zeros((Nbasis, Nbasis))

    MOs[0:nbasisA, 0:nbasisA] = MOsA
    MOs[nbasisA:Nbasis, nbasisA:Nbasis] = MOsB

    S[0:nbasisA, 0:nbasisA] = SA
    S[nbasisA:Nbasis, nbasisA:Nbasis] = SB

    # Calculate upper diagonal matrix D, such that S=D.T*D for Lowdin orthogonalisation.
    D = sp.linalg.cholesky(S)

    Dpair = sp.linalg.cholesky(SAB)

    # Orthogonalise MOs matrix and MOsAB matrix
    MOsorth = np.dot(D, MOs)

    #print np.shape(MOsorth)

    MOspairorth = np.dot(Dpair, MOsAB)

    #print np.shape(MOspairorth)

    # Calculate the Fock matrix
    B = np.dot(MOsorth.T, MOspairorth)
    Evals = np.diagflat(EvalsAB)
    F = np.dot(np.dot(B, Evals), B.T)

    # Output the H**O-H**O and LUMO-LUMO coupling elements fromt the Fock matrix

    if Degeneracy_HOMO == 0:
        print "H**O-H**O coupling: ", F[nhomoB + nbasisA, nhomoA]

    if Degeneracy_LUMO == 0:
        print "LUMO-LUMO coupling: ", F[nhomoB + nbasisA + 1, nhomoA + 1]


# Degeneracies

    if Degeneracy_HOMO != 0:
        F_deg_HOMO = F[nhomoB + nbasisA - Degeneracy_HOMO + 1:nhomoB +
                       nbasisA + 1, nhomoA - Degeneracy_HOMO:nhomoA]
        print "H**O-H**O coupling", (np.sum(np.absolute(
            F_deg_HOMO**2))) / Degeneracy_HOMO**2

    if Degeneracy_LUMO != 0:
        F_deg_LUMO = F[nhomoB + nbasisA:nhomoB + nbasisA + Degeneracy_LUMO,
                       nhomoA:nhomoA + Degeneracy_LUMO]
        print "LUMO-LUMO coupling", (np.sum(np.absolute(
            F_deg_LUMO**2))) / Degeneracy_LUMO**2
import sys
import os
import numpy as np
import cclib

from cclib.parser import ccopen

if __name__ == "__main__":

    # read in filename and parse log file
    filename = sys.argv[2]
    mylogfile = ccopen(filename)
    data = mylogfile.parse()

    # if TS calculation
    if sys.argv[1] == "TS":
        energy = data.scfenergies

        print(energy)

    # if NF calculation
    if sys.argv[1] == "NF":
        G = data.freeenergy
        freqs = data.vibfreqs
        imaginary = freqs[freqs < 0]

        print(G, imaginary)
Example #37
0
def load_calc_list(job_dir, pname='nwchem.out', context=None):

    meta_data = Munch()
    calc = Munch(meta_data=meta_data, properties=Munch())

    outfile = join(job_dir, pname)
    myfile = ccopen(outfile)

    #myfile.logger.setLevel(logging.ERROR)

    data = myfile.parse()

    t = PeriodicTable()

    #   Vdd calc
    #    print     data.nmo
    #    print data.moenergies[-1]
    #    print data.homos
    #    print data.scfenergies[-1]

    if 'optdone' in data.__dict__:
        calc.optdone = data.optdone
        if context == 'opt':
            return calc
    else:
        calc.optdone = None
        if len(data.scfenergies) > 0:
            calc.optdone = False
        else:
            calc.optdone = None


#       return calc

    if calc.optdone:
        meta_data.version = data.metadata['package_version']

        meta_data.program = data.metadata['package']
        #meta_data.wall_clock_time = data.walltime
        #meta_data.wall_clock_time = data.walltime

        meta_data.worker_name = pname

        calc.theory = data.metadata['methods'][-1]
        calc.functional = data.metadata['functional']
        calc.basisset = data.metadata['basis_set']

        calc.properties.total_energy = convertor(data.scfenergies[-1], "eV",
                                                 "hartree")
        #    calc.properties.total_energy =  data.scfenergies[-1]

        nmotot = data.nmo
        numoc = len(data.nooccnos[-1])
        low = len(data.moenergies[-1]) - numoc
        newmoe = data.moenergies[-1][low:nmotot]
        newmoe = convertor(data.moenergies[-1], "eV", "hartree")[low:nmotot]
        occ = []
        unocc = []
        for index, value in enumerate(data.nooccnos[-1]):
            if value != 0.0:
                occ_info = dict(method="rhf",
                                spin="alpha",
                                type="occ",
                                number=index + 1,
                                energy=newmoe[index])
                occ.append(occ_info)
            else:
                unocc_info = dict(method="rhf",
                                  spin="alpha",
                                  type="unocc",
                                  number=index + 1,
                                  energy=newmoe[index])
                unocc.append(unocc_info)
        for index, value in enumerate(data.nooccnos[-1]):
            if value == 0.0:
                lumo = newmoe[index]
                h**o = newmoe[index - 1]
                break
    #
        calc.properties.h**o = h**o
        calc.properties.lumo = lumo
        calc.properties.gap = lumo - h**o
        #calc.properties.electric_dipole_moment_norm
        calc.properties.occupied_orbital_number = len(occ)
        calc.orbital_energy_list = occ + unocc

    coords = []
    for index, value in enumerate(data.atomcoords[-1]):
        x, y, z = value
        elem = t.element[data.atomnos[index]]
        coords.append(dict(element=elem, x=x, y=y, z=z))
    calc.coords = coords

    return calc
# uses modified cclib 1.00
import sys

sys.path.insert(1, sys.argv[2])  # add $RMG/source to the PYTHONPATH so that import statements below work properly
import logging
from cclib.parser import ccopen

myfile = ccopen(sys.argv[1])
myfile.logger.setLevel(
    logging.ERROR
)  # cf. http://cclib.sourceforge.net/wiki/index.php/Using_cclib#Additional_information
data = myfile.parse()
print data.natom  # print line 1
# print data.atomnos #print line 2; this has a problem with wrapping; Richard West suggested a couple of alternatives as shown below
print [i for i in data.atomnos]  # this will put a comma between each element; alternative is:
# for i in data.atomnos:
#    print i,
print data.atomcoords[-1]  # print the final optimized atom coordinates
print data.scfenergies[
    -1
] / 27.2113845  # print the final optimized PM3 energy (cclib gives this in eV, but I have converted here to Hartree); conversion value taken from cclib code; compare CODATA 2006 value 27.21138386(68) eV/Hartree
print data.molmass  # print the molecular mass (in amu)
if data.natom > 1:  # for species with more than one atom, display vibrational frequencies and rotational constants
    # print data.vibfreqs #print the vibrational frequencies; see atomnos discussion above
    print [i for i in data.vibfreqs]
    print data.rotcons[
        -1
    ]  # print the final rotational constants (note that ideally we would use next to last value ([-2]) as this has more significant digits and is for the same geometry, but there is a complication for linear molecules (labeled as "Rotational constant" rather than "...constants"...there might be some ways around this like looking for "Rotational constant" string instead, but it is probably not a big deal to just use rounded values
    CMy = sum(positions[:, 1] * masses) / mass_sum
    CMz = sum(positions[:, 2] * masses) / mass_sum
    return (CMx, CMy, CMz)

def zpe(real_frequencies):
    zpe = zpe_prefactor * sum(real_frequencies)
    return zpe

if __name__ == '__main__':

    filename = sys.argv[1]

    print('=' * 78)
    print('filename:', filename)

    job = ccopen(filename)
    data = job.parse()

    hessian_scf = data.hessian

    # Before obtaining frequencies from the SCF Hessian, we must remove any
    # blocks that correspond to ghost atoms, then mass-weight it.

    gh_indices = list(i for i in range(len(data.atomnos))
                      if data.atomnos[i] < 1)
    atom_indices = list(i for i in range(len(data.atomnos))
                        if data.atomnos[i] > 0)
    hessian_dim = 3 * len(atom_indices)
    hessian_scf_noghost = np.empty(shape = (hessian_dim, hessian_dim))

    # Transfer non-ghost blocks to the new Hessian:
def ProJ():
    # Read in molecule log files for projective method. Requires iop(3/33=1,6/7=3) in Gaussian header for calculation on each molecule + the pair
    #MOLA_proj=sys.argv[1]
    #MOLB_proj=sys.argv[2]
    #Degeneracy_HOMO=int(sys.argv[4])
    #Degeneracy_LUMO=int(sys.argv[5])    # =0 for non-degenerate, 2,3 etc for doubly, triply etc

    # Open the log files
    molA_parser = ccopen("%s" % (MOLA_CP))
    molB_parser = ccopen("%s" % (MOLB_CP))
    molAB_parser = ccopen("%s" % (MOLAB_CP))
    
    # Parse the relevant data
    molA = molA_parser.parse()
    molB = molB_parser.parse()
    molAB = molAB_parser.parse()

    print ("Parsed...")

    # Size of basis sets
    nbasisA = molA.nbasis
    nbasisB = molB.nbasis
    nbasisAB = molAB.nbasis

    print ("nbasisA: ", nbasisA)
    print ("nbasisB: ", nbasisB)
    print ("nbasisAB: ", nbasisAB)

    Nbasis = nbasisA + nbasisB

    # Position of H**O
    nhomoA = molA.homos
    nhomoB = molB.homos
    nhomoAB = molAB.homos


    # Get molecular orbitals. Need the transpose for our purposes.
    MOsA=(molA.mocoeffs[0]).T
    MOsB=(molB.mocoeffs[0]).T
    MOsAB=(molAB.mocoeffs[0]).T

    # Get eigenvalues of pair
    EvalsAB = molAB.moenergies[0]
    
    # Check degeneracy
    deg_homo=1
    deg_lumo=1

    for i in range(1, 10):
        if (np.absolute(EvalsAB[nhomoAB] - EvalsAB[nhomoAB - i]) < 0.005):
            deg_homo+=1
        if (np.absolute(EvalsAB[nhomoAB + 1 + i] - EvalsAB[nhomoAB + 1]) < 0.005):
            deg_lumo+=1

    print ("Deg H**O: ", deg_homo)
    print ("Deg LUMO: ", deg_lumo)    

    # Get overlaps. These are symmetric so transpose not required in this case
    SA = molA.aooverlaps
    SB = molB.aooverlaps
    SAB = molAB.aooverlaps

    # Set up matrices for MOs and S
    MOs = np.zeros((Nbasis, Nbasis))
    S = np.zeros((Nbasis, Nbasis))

    # First N/2 columns correspond to MO of molA
    MOs[:nbasisA, :nbasisA] = MOsA
    #MOs[:nbasisA, :MOsA.shape[1]] = MOsA
    
    # Second N/2 columns correspond to MO of molB
    MOs[nbasisA:Nbasis, nbasisA:Nbasis] = MOsB
    #MOs[nbasisA:Nbasis, MOsA.shape[1]:MOsA.shape[1] + MOsB.shape[1]] = MOsB
    
    # Same for overlaps:
    S[0:nbasisA, 0:nbasisA] = SA
    S[nbasisA:Nbasis, nbasisA:Nbasis] = SB

    # Calculate upper diagonal matrix D, such that S=D.T*D for Lowdin orthogonalisation.
    D=sp.linalg.cholesky(S) 
    Dpair=sp.linalg.cholesky(SAB)

    # Orthogonalise MOs matrix and MOsAB matrix
    MOsorth = np.dot(D, MOs)
    MOspairorth=np.dot(Dpair,MOsAB)

    # Calculate the Fock matrix
    B = np.dot(MOsorth.T, MOspairorth)
    Evals = np.diagflat(EvalsAB)
    F = np.dot(np.dot(B, Evals), B.T)


    # Output the H**O-H**O and LUMO-LUMO coupling elements fromt the Fock matrix
    if deg_homo == 1:
        print ("H**O-H**O coupling: ", F[int(nhomoB + nbasisA), int(nhomoA)])

    if deg_lumo == 1:
        print ("LUMO-LUMO coupling: ", F[int(nhomoB + nbasisA + 1), int(nhomoA + 1)])

    # Degeneracies
    # If orbitals are degenerate, take root mean square.
    # e.g. RMS of H**O-H**O, H**O-H**O-1, H**O-1-H**O and H**O-1-H**O-1
    if deg_homo == 2:
        j0 = F[int(nhomoB + nbasisA), int(nhomoA)]
        print ("H**O-H**O coupling: ", j0)
        j1 = F[int(nhomoB + nbasisA - 1), int(nhomoA)]
        print ("H**O-H**O-1 coupling: ", j1)
        j2 = F[int(nhomoB + nbasisA), int(nhomoA - 1)]
        print ("H**O-1-H**O coupling: ", j2)
        j3 = F[int(nhomoB + nbasisA - 1), int(nhomoA - 1)]
        print ("H**O-1-H**O-1 coupling: ", j3)
        print('------------------------------')
        print (' H**O-H**O RMS equals', np.sqrt(np.mean(np.square([j0, j3]))))
        print('------------------------------')

        #Degeneracy_HOMO = deg_homo
        #F_deg_HOMO = F[int(nhomoB + nbasisA - Degeneracy_HOMO + 1):int(nhomoB + nbasisA + 1), int(nhomoA - Degeneracy_HOMO):int(nhomoA)]
        #F_deg_HOMO = F[int(nhomoB + nbasisA - deg_homo): int(nhomoB + nbasisA), int(nhomoA - deg_homo):int(nhomoA)]
        # print(F_deg_HOMO)
        # print ("H**O-H**O coupling", (np.sum(np.absolute(F_deg_HOMO**2))) / deg_homo**2) # Strange way to get RMS?
        #print ("Degenerate H**O-H**O coupling: ", np.sqrt(np.mean(np.square(F_deg_HOMO))))

    if deg_lumo == 2:
        j0 = F[int(nhomoB + nbasisA + 1), int(nhomoA + 1)]
        print ("LUMO-LUMO coupling: ", j0)
        j1 = F[int(nhomoB + nbasisA + 1), int(nhomoA + 1 + 1)]
        print ("LUMO-LUMO+1 coupling: ", j1)
        j2 = F[int(nhomoB + nbasisA + 1 + 1), int(nhomoA + 1)]
        print ("LUMO+1-LUMO coupling: ", j2)
        j3 = F[int(nhomoB + nbasisA + 1 + 1), int(nhomoA + 1 + 1)]
        print ("LUMO+1-LUMO+1 coupling: ", j3)
        print('------------------------------')
        print ('LUMO-LUMO-RMS equals', np.sqrt(np.mean(np.square([j0, j3]))))
        print('------------------------------')

        #print ("LUMO-LUMO coupling: ", F[int(nhomoB + nbasisA + 1), int(nhomoA + 1)])
        #F_deg_LUMO = F[int(nhomoB + nbasisA):int(nhomoB + nbasisA + deg_lumo - 1), int(nhomoA + 1):int(nhomoA + 1 + deg_lumo - 1)]
        #print(F_deg_LUMO)
        ## print ("LUMO-LUMO coupling", (np.sum(np.absolute(F_deg_LUMO**2))) / deg_lumo**2)
        #print ("Degenerate LUMO-LUMO coupling: ", np.sqrt(np.mean(np.square(F_deg_LUMO))))
        pass
Example #41
0
def CountPJ():
    # Read in molecule log files for counterpoise method. Requires IOp(6/7=3) in Gaussian header + ghost atoms to make up basis sets in individual com files
    # MOLA_CP=sys.argv[1]
    # MOLB_CP=sys.argv[2]
    # MOLAB_CP=sys.argv[3]

    # Open the log files
    molA_parser = ccopen("%s" % (MOLA_CP))
    molB_parser = ccopen("%s" % (MOLB_CP))
    molAB_parser = ccopen("%s" % (MOLAB_CP))

    # Parse the relevant data
    molA = molA_parser.parse()
    molB = molB_parser.parse()
    molAB = molAB_parser.parse()

    print("Parsed...")

    # H**O and LUMO index
    nhomoA = molA.homos
    nhomoB = molB.homos
    nhomoAB = molAB.homos

    nlumoA = nhomoA + 1
    nlumoB = nhomoB + 1
    #print ("H**O AB: ", nhomoAB)

    # Every basis set should have the same size (the size of the pair)
    if molA.nbasis != molB.nbasis:
        print("Count of basis functions doesn't match. Failing.")

    # Get molecular orbitals
    MOsA = molA.mocoeffs[0]
    MOsB = molB.mocoeffs[0]
    MOsAB = molAB.mocoeffs[0]

    # Get eigenvalues of pair
    EvalsAB = molAB.moenergies[0]

    # print ("Energies: ", EvalsAB)
    print('----------------------------')
    print('molA H**O-3: \t', nhomoA - 3, molA.moenergies[0][nhomoA - 3])
    print('molA H**O-2: \t', nhomoA - 2, molA.moenergies[0][nhomoA - 2])
    print('molA H**O-1: \t', nhomoA - 1, molA.moenergies[0][nhomoA - 1])
    print('molA H**O: \t', nhomoA, molA.moenergies[0][nhomoA])
    print('molA LUMO: \t', nhomoA + 1, molA.moenergies[0][nhomoA + 1])

    print('----------------------------')

    print('molB H**O: \t', nhomoB, molB.moenergies[0][nhomoB])
    print('molB LUMO: \t', nhomoB + 1, molB.moenergies[0][nhomoB + 1])
    print('molB LUMO+1: \t', nhomoB + 2, molB.moenergies[0][nhomoB + 2])
    print('molB LUMO+2: \t', nhomoB + 3, molB.moenergies[0][nhomoB + 3])
    print('molB LUMO+3: \t', nhomoB + 4, molB.moenergies[0][nhomoB + 4])

    print('----------------------------')

    print('molAB H**O-4: \t', nhomoAB - 4, molAB.moenergies[0][nhomoAB - 4])
    print('molAB H**O-3: \t', nhomoAB - 3, molAB.moenergies[0][nhomoAB - 3])
    print('molAB H**O-2: \t', nhomoAB - 2, molAB.moenergies[0][nhomoAB - 2])
    print('molAB H**O-1: \t', nhomoAB - 1, molAB.moenergies[0][nhomoAB - 1])
    print('molAB H**O: \t', nhomoAB, molAB.moenergies[0][nhomoAB])
    print('molAB LUMO: \t', nhomoAB + 1, molAB.moenergies[0][nhomoAB + 1])
    print('molAB LUMO+1: \t', nhomoAB + 2, molAB.moenergies[0][nhomoAB + 2])
    print('molAB LUMO+2: \t', nhomoAB + 3, molAB.moenergies[0][nhomoAB + 3])
    print('molAB LUMO+3: \t', nhomoAB + 4, molAB.moenergies[0][nhomoAB + 4])
    print('molAB LUMO+5: \t', nhomoAB + 5, molAB.moenergies[0][nhomoAB + 5])

    print('----------------------------')

    print("Gap in isolation: ",
          molB.moenergies[0][nhomoB + 1] - molA.moenergies[0][nhomoA])
    print("Gap in pair: ", EvalsAB[nhomoAB + 1] - EvalsAB[nhomoAB])

    deg_homo = 1
    deg_lumo = 1

    for i in range(1, 10):
        if (np.absolute(EvalsAB[nhomoAB] - EvalsAB[nhomoAB - i]) < 0.005):
            deg_homo += 1
        if (np.absolute(EvalsAB[nhomoAB + 1 + i] - EvalsAB[nhomoAB + 1]) <
                0.005):
            deg_lumo += 1

    print("Deg H**O: ", deg_homo)
    print("Deg LUMO: ", deg_lumo)

    # Find H**O and LUMO from energy splitting in dimer
    #print ("ESID H**O-H**O coupling", 0.5 * (EvalsAB[nhomoAB] - EvalsAB[nhomoAB - 1]))
    #print ("ESID LUMO-LUMO coupling", 0.5 * (EvalsAB[nhomoAB + 2] - EvalsAB[nhomoAB + 1]))

    # Calculate the molecular orbitals of A and B in the AB basis set
    SAB = molAB.aooverlaps
    MolAB_Pro = (np.dot(MOsAB, SAB)).T
    PsiA_AB_BS = np.dot(MOsA, MolAB_Pro)
    PsiB_AB_BS = np.dot(MOsB, MolAB_Pro)

    # print ('PsiA_AB_BS = ',PsiA_AB_BS[nhomoA, nlumoB])
    # print ('PsiB_AB_BS = ',PsiB_AB_BS[nhomoA, nlumoB])
    # temp = np.dot(PsiA_AB_BS, np.diagflat(EvalsAB))
    # print ('PsiA_AB_BS dot E_lk = ', temp[nhomoA,nlumoB])
    # temp2 = PsiB_AB_BS.T
    # print ('PsiB_AB_BS^T = ',temp2[nhomoA, nlumoB])
    # temp3 = np.dot(temp, temp2)
    # print ('PsiA_AB_BS dot E_lk dot PsiA_AB_BS^T = ', temp3[nhomoA,nlumoB])

    # Calculate the matrix of transfer integrals
    JAB = np.dot(np.dot(PsiA_AB_BS, np.diagflat(EvalsAB)), PsiB_AB_BS.T)
    JAA = np.dot(np.dot(PsiA_AB_BS, np.diagflat(EvalsAB)), PsiA_AB_BS.T)
    JBB = np.dot(np.dot(PsiB_AB_BS, np.diagflat(EvalsAB)), PsiB_AB_BS.T)
    S = np.dot(PsiA_AB_BS, PsiB_AB_BS.T)

    # Symmetric Lowdin transformation
    J_eff = (JAB - 0.5 * (JAA + JBB) * S) / (1.0 - S**2)

    # print ('j_AB = ',JAB[nhomoA, nlumoB])
    # print ('j_AA = ',JAA[nhomoA, nlumoB])
    # print ('j_BB = ',JBB[nhomoA, nlumoB])
    # print ('S_AB = ',S[nhomoA, nlumoB])

    # Energy eigenvalues
    # eA_eff = 0.5*( (JAA + JBB) - 2 * JAB * S + (JAA - JBB) * np.sqrt(1 - S**2 ))/ ( 1 - S**2 )
    # eB_eff = 0.5*( (JAA + JBB) - 2 * JAB * S - (JAA - JBB) * np.sqrt(1 - S**2 ))/ ( 1 - S**2 )

    # Print the H**O-H**O and LUMO-LUMO coupling
    print('\n ---------------------------- \n')
    with open(path + jobtitle + '/' + jobtitle + '-CP-calc.txt',
              "w") as text_file:
        print("Job title: ", jobtitle)
        print(f"Job title: {jobtitle}", file=text_file)
        if deg_homo == 1:
            # print ("nHOMO A: ", nhomoA)
            # print ("nHOMO B: ", nlumoB)
            # print ("H**O A: ", nhomoA, eA_eff[nhomoA,nhomoA])
            # print (f"H**O A: {eA_eff[nhomoA,nhomoA]}", file=text_file)
            # print ("LUMO B: ", nlumoB, eB_eff[nlumoB,nlumoB])
            # print (f"LUMO B: {eB_eff[nlumoB,nlumoB]}", file=text_file)
            # print ("ESID H**O-H**O coupling", 0.5 * (EvalsAB[nhomoAB] - EvalsAB[nhomoAB - 1]))
            # print (f"ESID H**O-H**O coupling {0.5 * (EvalsAB[nhomoAB] - EvalsAB[nhomoAB - 1])}", file=text_file)
            # print ("H**O-H**O coupling: ", J_eff[nhomoA,nhomoB])
            # print (f"H**O-H**O coupling: {J_eff[nhomoA,nhomoB]}", file=text_file)
            print("H**O", nhomoA, "-LUMO", nlumoB, " coupling: ",
                  J_eff[nhomoA, nlumoB])
            print(f"H**O-LUMO coupling: {J_eff[nhomoA,nlumoB]}",
                  file=text_file)
        if deg_lumo == 1:
            # print ("ESID LUMO-LUMO coupling", 0.5 * (EvalsAB[nhomoAB + 2] - EvalsAB[nhomoAB + 1]))
            # print (f"ESID LUMO-LUMO coupling {0.5 * (EvalsAB[nhomoAB + 2] - EvalsAB[nhomoAB + 1])}", file=text_file)
            # print ("LUMO-LUMO coupling: ", J_eff[nlumoA,nlumoB])
            # print (f"LUMO-LUMO coupling: {J_eff[nlumoA,nlumoB]}", file=text_file)
            #print ("LUMO-H**O coupling: ", J_eff[nlumoA,nhomoB])
            #print (f"LUMO-H**O coupling: {J_eff[nlumoA,nhomoB]}", file=text_file)
            pass
        if deg_homo == 2:
            # doubly degenerate

            # %H00=H_eff(nhomo_mon+nbasis,   nhomo_mon  );
            # %H01=H_eff(nhomo_mon+nbasis,   nhomo_mon-1);
            # %H10=H_eff(nhomo_mon+nbasis-1, nhomo_mon  );
            # %H11=H_eff(nhomo_mon+nbasis-1, nhomo_mon-1);

            # %L00=H_eff(nhomo_mon+nbasis+1, nhomo_mon+1);
            # %L01=H_eff(nhomo_mon+nbasis+1, nhomo_mon);
            # %L10=H_eff(nhomo_mon+nbasis,   nhomo_mon+1);
            # %L11=H_eff(nhomo_mon+nbasis,   nhomo_mon  );

            # %Doubly_degenerate_HOMO_coupling=(abs(H00)+abs(H01)+abs(H10)+abs(H11))/4
            # %Doubly_degenerate_LUMO_coupling=(abs(L00)+abs(L01)+abs(L10)+abs(L11))/4
            j0 = J_eff[nhomoA, nhomoB]
            print("H**O-H**O", nhomoA, nhomoB, "coupling: ", j0)
            j1 = J_eff[nhomoA, nhomoB - 1]
            print("H**O-H**O-1 coupling: ", j1)
            j2 = J_eff[nhomoA - 1, nhomoB]
            print("H**O-1-H**O coupling: ", j2)
            j3 = J_eff[nhomoA - 1, nhomoB - 1]
            print("H**O-1-H**O-1 coupling: ", j3)
            print('------------------------------')
            print(' H**O-H**O RMS equals', np.sqrt(np.mean(np.square([j0,
                                                                      j3]))))
            print('------------------------------')

            # deg_homo_J = J_eff[int(nhomoA - deg_homo + 1):int(nhomoA + 1), int(nhomoB - deg_homo + 1):int(nhomoB + 1)]
            # print ("Degenerate H**O-H**O coupling: ", np.sqrt(np.mean(np.square(deg_homo_J))))
            # print (f"Degenerate H**O-H**O coupling: {np.sqrt(np.mean(np.square(deg_homo_J)))}", file=text_file)
        if deg_lumo == 2:
            j0 = J_eff[nlumoA, nlumoB]
            print("LUMO-LUMO", nlumoA, nlumoB, " coupling: ", j0)
            j1 = J_eff[nlumoA, nlumoB + 1]
            print("LUMO-LUMO+1 coupling: ", j1)
            j2 = J_eff[nlumoA + 1, nlumoB]
            print("LUMO+1-LUMO coupling: ", j2)
            j3 = J_eff[nlumoA + 1, nlumoB + 1]
            print("LUMO+1-LUMO+1 coupling: ", j3)
            print('------------------------------')
            print('LUMO-LUMO-RMS equals', np.sqrt(np.mean(np.square([j0,
                                                                     j3]))))
            print('------------------------------')
            # deg_lumo_J = J_eff[int(nlumoA):int(nlumoA + deg_lumo), int(nlumoB):int(nlumoB + deg_lumo)]
            # print ("Degenerate LUMO-LUMO coupling: ", np.sqrt(np.mean(np.square(deg_lumo_J))))
            # print (f"Degenerate LUMO-LUMO coupling: {np.sqrt(np.mean(np.square(deg_lumo_J)))}", file=text_file)

        if deg_homo == 4:
            # molA H**O
            j0 = J_eff[nhomoA, nhomoB]
            print("H**O-H**O coupling: ", j0)
            # j1 = J_eff[nhomoA, nhomoB - 1]
            # j2 = J_eff[nhomoA, nhomoB - 2]
            # j3 = J_eff[nhomoA, nhomoB - 3]
            # molA H**O-1
            # j4 = J_eff[nhomoA-1, nhomoB]
            j5 = J_eff[nhomoA - 1, nhomoB - 1]
            # j6 = J_eff[nhomoA-1, nhomoB - 2]
            # j7 = J_eff[nhomoA-1, nhomoB - 3]
            # molA H**O-2
            # j8 = J_eff[nhomoA-2, nhomoB]
            # j9 = J_eff[nhomoA-2, nhomoB - 1]
            j10 = J_eff[nhomoA - 2, nhomoB - 2]
            # j11 = J_eff[nhomoA-2, nhomoB - 3]
            # molA H**O-3
            # j12 = J_eff[nhomoA-3, nhomoB]
            # j13 = J_eff[nhomoA-3, nhomoB - 1]
            # j14 = J_eff[nhomoA-3, nhomoB - 2]
            j15 = J_eff[nhomoA - 3, nhomoB - 3]

            print('------------------------------')
            # print (' H**O-H**O RMS equals', np.sqrt(np.mean(np.square([j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15]))))
            print(' H**O-H**O RMS equals',
                  np.sqrt(np.mean(np.square([j0, j5, j10, j15]))))
            print('------------------------------')

            deg_homo_J = J_eff[int(nhomoA - deg_homo + 1):int(nhomoA + 1),
                               int(nhomoB - deg_homo + 1):int(nhomoB + 1)]
            print("Degenerate H**O-H**O coupling: ",
                  np.sqrt(np.mean(np.square(deg_homo_J))))
            print(
                f"Degenerate H**O-H**O coupling: {np.sqrt(np.mean(np.square(deg_homo_J)))}",
                file=text_file)

        if deg_lumo == 4:
            # molA H**O
            j0 = J_eff[nlumoA, nlumoB]
            # print ("LUMO-LUMO coupling: ", j0)
            j1 = J_eff[nlumoA, nlumoB + 1]
            # print ("LUMO-LUMO+1 coupling: ", j1)
            j2 = J_eff[nlumoA, nlumoB + 2]
            # print ("LUMO-LUMO+2 coupling: ", j2)
            j3 = J_eff[nlumoA, nlumoB + 3]
            # print ("LUMO-LUMO+3 coupling: ", j3)
            # molA H**O-1
            j4 = J_eff[nlumoA + 1, nlumoB]
            # print ("LUMO+1-LUMO coupling: ", j4)
            j5 = J_eff[nlumoA + 1, nlumoB + 1]
            # print ("LUMO+1-LUMO+1 coupling: ", j5)
            j6 = J_eff[nlumoA + 1, nlumoB + 2]
            # print ("LUMO+1-LUMO+2 coupling: ", j6)
            j7 = J_eff[nlumoA + 1, nlumoB + 3]
            # print ("LUMO+1-LUMO+3 coupling: ", j7)
            # molA H**O-2
            j8 = J_eff[nlumoA + 2, nlumoB]
            # print ("LUMO+2-LUMO coupling: ", j8)
            j9 = J_eff[nlumoA + 2, nlumoB + 1]
            # print ("LUMO+2-LUMO+1 coupling: ", j9)
            j10 = J_eff[nlumoA + 2, nlumoB + 2]
            # print ("LUMO+2-LUMO+2 coupling: ", j10)
            j11 = J_eff[nlumoA + 2, nlumoB + 3]
            # print ("LUMO+2-LUMO+3 coupling: ", j11)
            # molA H**O-3
            j12 = J_eff[nlumoA + 3, nlumoB]
            # print ("LUMO+3-LUMO coupling: ", j12)
            j13 = J_eff[nlumoA + 3, nlumoB + 1]
            # print ("LUMO+3-LUMO+1 coupling: ", j13)
            j14 = J_eff[nlumoA + 3, nlumoB + 2]
            # print ("LUMO+3-LUMO+2 coupling: ", j14)
            j15 = J_eff[nlumoA + 3, nlumoB + 3]
            # print ("LUMO+3-LUMO+3 coupling: ", j15)
            # print(j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15)

            print('------------------------------')
            # print (' LUMO-LUMO RMS equals', np.sqrt(np.mean(np.square([j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15]))))
            print(' LUMO-LUMO RMS equals',
                  np.sqrt(np.mean(np.square([j0, j5, j10, j15]))))
            print('------------------------------')
            deg_lumo_J = J_eff[int(nlumoA):int(nlumoA + deg_lumo),
                               int(nlumoB):int(nlumoB + deg_lumo)]
            print("Degenerate LUMO-LUMO coupling: ",
                  np.sqrt(np.mean(np.square(deg_lumo_J))))
            print(
                f"Degenerate LUMO-LUMO coupling: {np.sqrt(np.mean(np.square(deg_lumo_J)))}",
                file=text_file)
def CountPJ():
# Read in molecule log files for counterpoise method. Requires IOp(6/7=3) in Gaussian header + ghost atoms to make up basis sets in individual com files  
	MOLA_CP=sys.argv[1]
	MOLB_CP=sys.argv[2]
	MOLAB_CP=sys.argv[3]

# Open the log files
	molA_parser=ccopen("%s"%(MOLA_CP))
	molB_parser=ccopen("%s"%(MOLB_CP))
	molAB_parser=ccopen("%s"%(MOLAB_CP))

# Parse the relevant data
	molA=molA_parser.parse()
	molB=molB_parser.parse()
	molAB=molAB_parser.parse()

	print ("Parsed...")

# Size of basis sets
	Nbasis=molAB.nbasis

# H**O index
	nhomoA=molA.homos
	nhomoB=molB.homos
	nhomoAB=molAB.homos

	nlumoA=nhomoA+1
	nlumoB=nhomoB+1

	print "H**O A: ", nhomoA
	print "H**O B: ", nhomoB
	print "H**O AB: ", nhomoAB

# Every basis set should have the same size (the size of the pair) 
	if molA.nbasis!=molB.nbasis:
		print("Count of basis functions doesn't match. Failing.")
		return False

# Get molecular orbitals
	MOsA=molA.mocoeffs[0]
	MOsB=molB.mocoeffs[0]
	MOsAB=molAB.mocoeffs[0]

# Get eigenvalues of pair
	EvalsAB=molAB.moenergies[0]

	print "Energies: ", EvalsAB
	print "Gap: ", EvalsAB[nhomoAB+1]-EvalsAB[nhomoAB]
    
# Find H**O and LUMO from energy splitting in dimer

	print "ESID H**O-H**O coupling", 0.5*(EvalsAB[nhomoAB]-EvalsAB[nhomoAB-1])
	print "ESID LUMO-LUMO coupling", 0.5*(EvalsAB[nhomoAB+2]-EvalsAB[nhomoAB+1])

# Calculate the molecular orbitals of A and B in the AB basis set

	SAB=molAB.aooverlaps

	MolAB_Pro = (np.dot(MOsAB,SAB)).T
	PsiA_AB_BS = np.dot(MOsA, MolAB_Pro)
	PsiB_AB_BS = np.dot(MOsB, MolAB_Pro)

# Calculate the matrix of transfer integrals

	JAB=np.dot(np.dot(PsiB_AB_BS,np.diagflat(EvalsAB)),PsiA_AB_BS.T)
	JAA=np.dot(np.dot(PsiA_AB_BS,np.diagflat(EvalsAB)),PsiA_AB_BS.T)
	JBB=np.dot(np.dot(PsiB_AB_BS,np.diagflat(EvalsAB)),PsiB_AB_BS.T)

	S = np.dot(PsiB_AB_BS,PsiA_AB_BS.T)

# Symmetric Lowdin transformation for required J

	J_eff_HOMO = (JAB[nhomoA,nhomoB]- 0.5*(JAA[nhomoA,nhomoA]+JBB[nhomoB,nhomoB])*S[nhomoA,nhomoB])/(1.0-S[nhomoA,nhomoB]*S[nhomoA,nhomoB])
	J_eff_LUMO = (JAB[nlumoA,nlumoB]- 0.5*(JAA[nlumoA,nlumoA]+JBB[nlumoB,nlumoB])*S[nlumoA,nlumoB])/(1.0-S[nlumoA,nlumoB]*S[nlumoA,nlumoB])


# Print the H**O-H**O and LUMO-LUMO coupling
	print "H**O-H**O coupling: ", J_eff_HOMO
	print "LUMO-LUMO coupling: ", J_eff_LUMO
Example #43
0
def parse(file_name, local_directory, output_file_name):
    result = OrderedDict()
    identifiers = OrderedDict()
    calculation = OrderedDict()
    molecule = OrderedDict()
    calculated_properties = OrderedDict()
    execution_environment = OrderedDict()
    molecule_structural_formats = OrderedDict()
    files_dict = OrderedDict()

    # extracting fields from open-babel
    mol = pybel.readfile('g98', file_name).next()
    identifiers['InChI'] = mol.write('inchi').strip()
    identifiers['InChIKey'] = mol.write('inchikey').strip()
    identifiers['SMILES'] = mol.write('smiles').split('\t')[0]
    identifiers['CanonicalSMILES'] = mol.write('can').split('\t')[0]

    molecule_structural_formats['PDB'] = mol.write('pdb').split('\t')[0]
    molecule_structural_formats['SDF'] = mol.write('sdf').split('\t')[0]

    # extracting fields from ccdbt
    parser_pyramid = ParserPyramid()
    meta_f = metafile(file_name)
    if meta_f.parse(parser_pyramid):
        if 'CodeVersion' in meta_f.record:
            calculation['Package'] = meta_f.record['CodeVersion']
        if 'CalcType' in meta_f.record:
            calculation['CalcType'] = meta_f.record['CalcType']
        if 'Methods' in meta_f.record:
            calculation['Methods'] = meta_f.record['Methods']
        if 'Basis' in meta_f.record:
            calculation['Basis'] = __extract(meta_f.record['Basis'])
        if 'Keywords' in meta_f.record:
            calculation['Keywords'] = meta_f.record['Keywords']
        if 'JobStatus' in meta_f.record:
            calculation['JobStatus'] = __extract(meta_f.record['JobStatus'])

        if 'Formula' in meta_f.record:
            molecule['Formula'] = meta_f.record['Formula']
        if 'OrbSym' in meta_f.record:
            molecule['OrbSym'] = meta_f.record['OrbSym']
        if 'Multiplicity' in meta_f.record:
            molecule['Multiplicity'] = meta_f.record['Multiplicity']
        if 'Charge' in meta_f.record:
            molecule['Charge'] = meta_f.record['Charge']
        if 'ElecSym' in meta_f.record:
            molecule['ElecSym'] = meta_f.record['ElecSym']

        if 'Energy' in meta_f.record:
            calculated_properties['Energy'] = meta_f.record['Energy']
        if 'Dipole' in meta_f.record:
            calculated_properties['Dipole'] = meta_f.record['Dipole']
        if 'HF' in meta_f.record:
            calculated_properties['HF'] = meta_f.record['HF']

        # Calling the jar to get distribution values
        process = Popen(
            ['java', '-jar', './gaussian-helper.jar', '--arg=' + file_name],
            stdout=PIPE,
            stderr=STDOUT)
        for line in process.stdout:
            value = line.split(':')
            if value[0] == 'Iterations':
                calculated_properties['Iterations'] = value[1]
            elif value[0] == 'MaximumGradientDistribution':
                calculated_properties['MaximumGradientDistribution'] = value[1]
            elif value[0] == 'RMSGradientDistribution':
                calculated_properties['RMSGradientDistribution'] = value[1]
            elif value[0] == 'EnergyDistribution':
                calculated_properties['EnergyDistribution'] = value[1]

        if 'CalcMachine' in meta_f.record:
            tmp = str(meta_f.record['CalcMachine'])
            if ';' in tmp:
                line = tmp.split(';')[0]
                bits = line.split('-')
                if len(bits) == 4:
                    execution_environment['CalcMachine'] = bits[1]
                else:
                    execution_environment['CalcMachine'] = line

            else:
                bits = tmp.split('-')
                if len(bits) == 4:
                    execution_environment['CalcMachine'] = bits[1]
                else:
                    execution_environment['CalcMachine'] = tmp

        if 'FinTime' in meta_f.record:
            execution_environment['FinTime'] = __extract(
                meta_f.record['FinTime'])
            fin_date = datetime.strptime(execution_environment['FinTime'],
                                         '%d %b %y')
            execution_environment['FinTimeStamp'] = datetime.utcfromtimestamp(
                calendar.timegm(fin_date.timetuple()))

        if 'CalcBy' in meta_f.record:
            execution_environment['CalcBy'] = __extract(
                meta_f.record['CalcBy'])

        for f in listdir(WORKING_DIR):
            if isfile(join(WORKING_DIR, f)):  # Check this in docker container
                if f.endswith('.out') or f.endswith('.log'):
                    files_dict['GaussianOutputFile'] = join(
                        local_directory,
                        f)  # If exists include the absolute path
                elif f.endswith('.com') or f.endswith('.in'):
                    files_dict['GaussianInputFile'] = join(local_directory, f)
                elif f.endswith('.chk'):
                    files_dict['GaussianCheckpointFile'] = join(
                        local_directory, f)
                elif f.endswith('.fchk'):
                    files_dict['GaussianFCheckpointFile'] = join(
                        local_directory, f)

        with open(join(WORKING_DIR, 'structure.sdf'), 'w') as output:
            output.write(str(molecule_structural_formats['SDF']))
        files_dict['SDFStructureFile'] = join(
            local_directory,
            'structure.sdf')  # Local directory path as the key

        with open(join(WORKING_DIR, 'structure.pdb'), 'w') as output:
            output.write(str(molecule_structural_formats['PDB']))
        files_dict['PDBStructureFile'] = join(local_directory, 'structure.pdb')

        with open(join(WORKING_DIR, 'inchi.txt'), 'w') as output:
            output.write(str(identifiers['InChI']))
        files_dict['InChIFile'] = join(local_directory, 'inchi.txt')

        with open(join(WORKING_DIR, 'smiles.txt'), 'w') as output:
            output.write(str(identifiers['SMILES']))
        files_dict['SMILESFile'] = join(local_directory, 'smiles.txt')

        # Open Gaussian output file
        # Extracting some fields which cannot be extracted from existing parsers
        #   * Stoichiometry
        #   * Job cpu time
        #   * %mem
        #   * %nprocshare

        with open(file_name) as f:
            content = f.readlines()

        if content is not None and len(content) > 0:
            for line in content:
                if line.lower().startswith(' stoichiometry'):
                    formula = line.replace('Stoichiometry', '').strip()
                    molecule['Formula'] = formula
                elif ' job cpu time' in line.lower():
                    time = line.split(':')[1].strip()
                    time.replace('days', '')
                    time.replace('hours', '')
                    time.replace('minutes', '')
                    time.replace('seconds', '')
                    time.replace(' +', '')

                    time_arr = time.split(' ')
                    time_in_seconds = 0.0
                    time_in_seconds += float(time_arr[0]) * 86400
                    time_in_seconds += float(time_arr[1]) * 3600
                    time_in_seconds += float(time_arr[2]) * 60
                    time_in_seconds += float(time_arr[3])

                    execution_environment['JobCPURunTime'] = time_in_seconds

                elif line.lower().startswith(' %mem'):
                    memory = line.split('=')[1].strip().lower()
                    # default memory is 256 MB
                    memory_int = 256
                    if memory.endswith('gw'):
                        memory_int = int(memory[:-2]) * 1000 * 8
                    elif memory.endswith('gb'):
                        memory_int = int(memory[:-2]) * 1000
                    elif memory.endswith('mw'):
                        memory_int = int(memory[:-2]) * 8
                    elif memory.endswith('mb'):
                        memory_int = int(memory[:-2])

                    execution_environment['Memory'] = memory_int

                elif line.lower().startswith(' %nproc'):
                    nproc = line.split('=')[1].strip()
                    execution_environment['NProcShared'] = nproc

        # Rest of the key value pairs are not updated by the seagrid-data
        if 'ParsedBy' in meta_f.record:
            result['ParsedBy'] = meta_f.record['ParsedBy']
        if 'NumBasis' in meta_f.record:
            result['NumBasis'] = meta_f.record['NumBasis']
        if 'NumFC' in meta_f.record:
            result['NumFC'] = meta_f.record['NumFC']
        if 'NumVirt' in meta_f.record:
            result['NumVirt'] = meta_f.record['NumVirt']
        if 'InitGeom' in meta_f.record:
            result['InitGeom'] = meta_f.record['InitGeom']
        if 'FinalGeom' in meta_f.record:
            result['FinalGeom'] = meta_f.record['FinalGeom']
        if 'PG' in meta_f.record:
            result['PG'] = meta_f.record['PG']
        if 'NImag' in meta_f.record:
            result['NImag'] = meta_f.record['NImag']
        if 'EnergyKcal' in meta_f.record:
            result['EnergyKcal'] = meta_f.record['EnergyKcal']
        if 'ZPE' in meta_f.record:
            result['ZPE'] = meta_f.record['ZPE']
        if 'ZPEKcal' in meta_f.record:
            result['ZPEKcal'] = meta_f.record['ZPEKcal']
        if 'HFKcal' in meta_f.record:
            result['HFKcal'] = meta_f.record['HFKcal']
        if 'Thermal' in meta_f.record:
            result['Thermal'] = meta_f.record['Thermal']
        if 'ThermalKcal' in meta_f.record:
            result['ThermalKcal'] = meta_f.record['ThermalKcal']
        if 'Enthalpy' in meta_f.record:
            result['Enthalpy'] = meta_f.record['Enthalpy']
        if 'EnthalpyKcal' in meta_f.record:
            result['EnthalpyKcal'] = meta_f.record['EnthalpyKcal']
        if 'Entropy' in meta_f.record:
            result['Entropy'] = meta_f.record['Entropy']
        if 'EntropyKcal' in meta_f.record:
            result['EntropyKcal'] = meta_f.record['EntropyKcal']
        if 'Gibbs' in meta_f.record:
            result['Gibbs'] = meta_f.record['Gibbs']
        if 'GibbsKcal' in meta_f.record:
            result['GibbsKcal'] = meta_f.record['GibbsKcal']
        if 'Freq' in meta_f.record:
            result['Freq'] = meta_f.record['Freq']
        if 'AtomWeigh' in meta_f.record:
            result['AtomWeigh'] = meta_f.record['AtomWeigh']
        if 'Conditions' in meta_f.record:
            result['Conditions'] = meta_f.record['Conditions']
        if 'ReacGeom' in meta_f.record:
            result['ReacGeom'] = meta_f.record['ReacGeom']
        if 'ProdGeom' in meta_f.record:
            result['ProdGeom'] = meta_f.record['ProdGeom']
        if 'MulCharge' in meta_f.record:
            result['MulCharge'] = meta_f.record['MulCharge']
        if 'NatCharge' in meta_f.record:
            result['NatCharge'] = meta_f.record['NatCharge']
        if 'S2' in meta_f.record:
            result['S2'] = meta_f.record['S2']
        if 'MemCost' in meta_f.record:
            result['MemCost'] = meta_f.record['MemCost']
        if 'TimeCost' in meta_f.record:
            result['TimeCost'] = meta_f.record['TimeCost']
        if 'CPUTime' in meta_f.record:
            result['CPUTime'] = meta_f.record['CPUTime']
        if 'Convergence' in meta_f.record:
            result['Convergenece'] = meta_f.record['Convergence']
        if 'FullPath' in meta_f.record:
            result['FullPath'] = meta_f.record['FullPath']
        if 'InputButGeom' in meta_f.record:
            result['InputButGeom'] = meta_f.record['InputButGeom']
        if 'Otherinfo' in meta_f.record:
            result['Otherinfo'] = meta_f.record['Otherinfo']
        if 'Comments' in meta_f.record:
            result['Comments'] = meta_f.record['Comments']

    # extracting fields from cclib
    my_file = ccopen(file_name)
    try:
        data = my_file.parse()
        data.listify()
        if hasattr(data, 'natom'):
            molecule['NAtom'] = data.natom
        if hasattr(data, 'homos'):
            calculated_properties['Homos'] = data.homos
        if hasattr(data, 'scfenergies'):  # Not updated by the seagrid-data
            result['ScfEnergies'] = data.scfenergies
        if hasattr(data, 'coreelectrons'):  # Not updated by the seagrid-data
            result['CoreElectrons'] = data.coreelectrons
        if hasattr(data, 'moenergies'):
            calculation['MoEnergies'] = data.moenergies
        if hasattr(data, 'atomcoords'):  # Not updated by the seagrid-data
            result['AtomCoords'] = data.atomcoords
        if hasattr(data, 'scftargets'):  # Not updated by the seagrid-data
            result['ScfTargets'] = data.scftargets
        if hasattr(data, 'nmo'):
            calculation['Nmo'] = data.nmo
        if hasattr(data, 'nbasis'):
            calculation['NBasis'] = data.nbasis
        if hasattr(data, 'atomnos'):  # Not updated by the seagrid-data
            result['AtomNos'] = data.atomnos
    except:
        sys.stderr.write('cclib parsing failed!')

    # Drawing the molecule
    # mol.draw(show=False, filename=molecule_image_file)

    result['Identifiers'] = identifiers
    result['Calculation'] = calculation
    result['Molecule'] = molecule
    result['CalculatedProperties'] = calculated_properties
    result['ExecutionEnvironment'] = execution_environment
    result['FinalMoleculeStructuralFormats'] = molecule_structural_formats
    result['Files'] = files_dict

    result = json.dumps(result,
                        separators=(',', ':'),
                        sort_keys=False,
                        indent=4)
    output_file = open(output_file_name, 'w')
    for row in result:
        output_file.write(row)
    output_file.close()
Example #44
0
        density.data = density.data*2. # doubly-occupied
    
    return density


if __name__=="__main__":

    try:
        import psyco
        psyco.full()
    except ImportError:
        pass

    from cclib.parser import ccopen
    import logging
    a = ccopen("../../../data/Gaussian/basicGaussian03/dvb_sp_basis.log")
    a.logger.setLevel(logging.ERROR)
    c = a.parse()
    
    b = ccopen("../../../data/Gaussian/basicGaussian03/dvb_sp.out")
    b.logger.setLevel(logging.ERROR)
    d = b.parse()

    vol = Volume( (-3.0,-6,-2.0), (3.0, 6, 2.0), spacing=(0.25,0.25,0.25) )
    wavefn = wavefunction(d.atomcoords[0], d.mocoeffs[0][d.homos[0]],
                          c.gbasis, vol)
    assert abs(wavefn.integrate())<1E-6 # not necessarily true for all wavefns
    assert abs(wavefn.integrate_square() - 1.00)<1E-3 #   true for all wavefns
    print wavefn.integrate(), wavefn.integrate_square()

    vol = Volume( (-3.0,-6,-2.0), (3.0, 6, 2.0), spacing=(0.25,0.25,0.25) )
Example #45
0
def extractdata(folder):
    smiles = [
        x.rstrip()
        for x in open(os.path.join(folder,
                                   os.path.basename(folder) +
                                   ".txt"), "r").readlines()
    ]
    print smiles
    archivefile = open(os.path.join(folder, "zindo.txt"), "w")
    print >> archivefile, "\t".join([
        "File ID", "SMILES", "H**O (eV)", "LUMO (eV)", "Trans (eV)", "Osc",
        "..."
    ])

    #getnum = lambda x: int(x.split("/")[1].split(".")[0])
    getnum = lambda x: int(x.split("/")[7].split(".")[0])
    homos = []
    lumos = []
    trans = []
    convert = 1.0 / utils.convertor(1, "eV", "cm-1")

    #for filename in sorted(glob.glob("*.gz"), key=getnum):
    for filename in sorted(glob.glob(os.path.join(folder, "*.gz")),
                           key=getnum):

        number = getnum(filename)
        smile = smiles[number]
        text = gzip.open(filename, "r").read()

        if text.find("Excitation energies and oscillator strength") < 0:
            continue
        lines = iter(text.split("\n"))

        for line in lines:
            if line.startswith(" Initial command"): break
        text = StringIO.StringIO("\n".join(list(lines)))

        logfile = ccopen(text)
        #logfile.logger.setLevel(logging.ERROR)
        data = logfile.parse()

        assert (len(data.homos) == 1)
        smiles.append(smile)
        h**o = data.homos[0]
        homos.append(data.moenergies[0][h**o])
        lumos.append(data.moenergies[0][h**o + 1])
        trans.append(zip(data.etenergies, data.etoscs))

        archivefile.write("%d\t%s\t%f\t%f" %
                          (number, smile, homos[-1], lumos[-1]))
        for x in trans[-1]:
            archivefile.write("\t%f\t%f" % (x[0] * convert, x[1]))
        archivefile.write("\n")
        ##        print >> open("tmp.txt", "w"), text.getvalue()
        if smile != "c(s1)c(SN=N2)c2c1c(s1)c(SN=N2)c2c1c(s1)c(SN=N2)c2c1c(s1)c(SN=N2)c2c1c(s1)c(SN=N2)c2c1c(s1)c(SN=N2)c2c1":
            mol = pybel.readstring('g09', text.getvalue())
            mol.write("xyz",
                      os.path.join(folder, "%d.xyz" % number),
                      overwrite=True)

    print "%s: Created zindo.txt, plus various xyz files." % folder
Example #46
0
def stretch(outputfile, shift=2.0, templatefiles=None):
    """
    Generate transition state search for given xyzfile,
    assuming that the first 2 atoms are the bond forming atoms

    outputfile is assumed to be a geometry optimization Q-Chem output

    TODO: option to set fname, and default to the templatefilename + index?
    """
    savexyz = True

    # If templatefiles doesn't exist, we only save stretched xyz
    if templatefiles:

        # Always convert templatefiles into list
        if not type(templatefiles) is list:
            templatefiles = [templatefiles]

        # Only keep the templatefiles that exists
        templatefiles = [
            templatefile for templatefile in templatefiles
            if templates.exists(templatefile)
        ]

        # If at least one templatefile exists, we don't save xyz
        if templatefiles:
            savexyz = False

    ccdata = ccopen(outputfile).parse()

    fname, _ = os.path.splitext(outputfile)
    #xyzfile = fname+'.xyz'
    #write.xyzfile(outputccdata, xyzfile)

    product = ccData_xyz(ccdata.getattributes())
    ccdatas = []
    #product = parse.xyzfile(xyzfile, ccxyz=True)
    product.build_zmatrix()
    reactant = copy.deepcopy(product)
    reactant.distances[1] += shift

    # TODO:If reactants provided, use their geometry internal coords
    # and modify internalcoords of reactant

    # FIXME hardcoded paths instead of cli args
    #rpaths = ['../../initiators/MeO/0.omegab97x-d_opt.out', '../../ketenes/TMS/0.omegab97x-d_opt.out']

    #reactants = []
    #for rpath in rpaths:
    #    reactants.append(parse.xyzfile(rpath, ccdata_xyz=True))

    #for r in reactants:
    #    r.build_zmatrix()

    # TODO Determine which reactant is which
    # Some ways to do this:
    # numatom, atomnos
    # TODO How to deal with symmetrical reactants?
    # Just guess (1/2 chance) - possibly cli to swap if wrong

    product.build_xyz()
    reactant.build_xyz()

    ccdatas.append(reactant)
    ccdatas.append(product)

    if not savexyz:
        for i in range(len(templatefiles)):
            if len(templatefiles) == 1:
                idx = ''
            else:
                idx = '-' + str(i)

            if 'opt' in fname:
                fname = fname.replace('opt', 'fsm')
            else:
                fname = fname + '_fsm'

            write.inputfile(ccdatas, templatefiles[i], fname + idx + '.qcm')
    else:
        reactant.print_xyz()
Example #47
0
def CountPJ():
    # Read in molecule log files for counterpoise method. Requires IOp(6/7=3) in Gaussian header + ghost atoms to make up basis sets in individual com files
    MOLA_CP = sys.argv[1]
    MOLB_CP = sys.argv[2]
    MOLAB_CP = sys.argv[3]

    # Open the log files
    molA_parser = ccopen("%s" % (MOLA_CP))
    molB_parser = ccopen("%s" % (MOLB_CP))
    molAB_parser = ccopen("%s" % (MOLAB_CP))

    # Parse the relevant data
    molA = molA_parser.parse()
    molB = molB_parser.parse()
    molAB = molAB_parser.parse()

    print("Parsed...")

    # Size of basis sets
    Nbasis = molAB.nbasis

    # H**O index
    nhomoA = molA.homos
    nhomoB = molB.homos
    nhomoAB = molAB.homos

    nlumoA = nhomoA + 1
    nlumoB = nhomoB + 1

    print "H**O A: ", nhomoA
    print "H**O B: ", nhomoB
    print "H**O AB: ", nhomoAB

    # Every basis set should have the same size (the size of the pair)
    if molA.nbasis != molB.nbasis:
        print("Count of basis functions doesn't match. Failing.")
        return False


# Get molecular orbitals
    MOsA = molA.mocoeffs[0]
    MOsB = molB.mocoeffs[0]
    MOsAB = molAB.mocoeffs[0]

    # Get eigenvalues of pair
    EvalsAB = molAB.moenergies[0]

    print "Energies: ", EvalsAB
    print "Gap: ", EvalsAB[nhomoAB + 1] - EvalsAB[nhomoAB]

    # Find H**O and LUMO from energy splitting in dimer

    print "ESID H**O-H**O coupling", 0.5 * (EvalsAB[nhomoAB] -
                                            EvalsAB[nhomoAB - 1])
    print "ESID LUMO-LUMO coupling", 0.5 * (EvalsAB[nhomoAB + 2] -
                                            EvalsAB[nhomoAB + 1])

    # Calculate the molecular orbitals of A and B in the AB basis set

    SAB = molAB.aooverlaps

    MolAB_Pro = (np.dot(MOsAB, SAB)).T
    PsiA_AB_BS = np.dot(MOsA, MolAB_Pro)
    PsiB_AB_BS = np.dot(MOsB, MolAB_Pro)

    # Calculate the matrix of transfer integrals

    JAB = np.dot(np.dot(PsiB_AB_BS, np.diagflat(EvalsAB)), PsiA_AB_BS.T)
    JAA = np.dot(np.dot(PsiA_AB_BS, np.diagflat(EvalsAB)), PsiA_AB_BS.T)
    JBB = np.dot(np.dot(PsiB_AB_BS, np.diagflat(EvalsAB)), PsiB_AB_BS.T)

    S = np.dot(PsiB_AB_BS, PsiA_AB_BS.T)

    # Symmetric Lowdin transformation for required J

    J_eff_HOMO = (JAB[nhomoA, nhomoB] - 0.5 *
                  (JAA[nhomoA, nhomoA] + JBB[nhomoB, nhomoB]) *
                  S[nhomoA, nhomoB]) / (1.0 -
                                        S[nhomoA, nhomoB] * S[nhomoA, nhomoB])
    J_eff_LUMO = (JAB[nlumoA, nlumoB] - 0.5 *
                  (JAA[nlumoA, nlumoA] + JBB[nlumoB, nlumoB]) *
                  S[nlumoA, nlumoB]) / (1.0 -
                                        S[nlumoA, nlumoB] * S[nlumoA, nlumoB])

    # Print the H**O-H**O and LUMO-LUMO coupling
    print "H**O-H**O coupling: ", J_eff_HOMO
    print "LUMO-LUMO coupling: ", J_eff_LUMO
Example #48
0
files = ['A1-Opt_6-31G(d)_B3LYP_Singlet_RHF.log',
		 'A1-Opt_6-31G(d)_B3LYP_Singlet_UHF.log',
		 'A1-Opt_6-31G(d)_B3LYP_Triplet.log']

#to hold the data
energies = []
symmetries = []
occupied = []

#the number of MOs to be output. is the min no of MOs in the input files
nMOs = 1000

#read and extract
for f in files:
	print "Reading file: %s" % f
	qmRaw = ccopen(os.path.join(path, f))
	qmRaw.logger.setLevel(logging.ERROR) #reduce logging info
	qmParsed = qmRaw.parse()
	energies.append(qmParsed.moenergies[0])
	symmetries.append(qmParsed.mosyms[0])
	occupied.append(range(qmParsed.nmo)<=qmParsed.homos[0])
	if (qmParsed.nmo<nMOs):
		nMOs=qmParsed.nmo
		print "Will export %i MO energies" % nMOs

#write out as groups of columns as CSV
print "Writing out MO data to %s" % outFile
output = open(os.path.join(path,outFile), "w")

#group titles
for f in files:
Example #49
0
def main(which=[], traceback=False, status=False):

    dummyfiles = [eval(n)("") for n in testall.parsers]

    # It would be nice to fix the structure of this nested list,
    # because in its current form it is not amenable to tweaks.
    regdir = os.path.join("..", "data", "regression")
    programs = [os.path.join(regdir,testall.get_program_dir(p)) for p in testall.parsers]
    try:
        filenames = [[os.path.join(p,version,fn) for version in os.listdir(p) for fn in os.listdir(os.path.join(p,version))] for p in programs]
    except OSError as e:
        print(e)
        print("\nERROR: At least one program direcory is missing.")
        print("Run regression_download.sh in the ../data directory to update.")
        sys.exit(1)

    # This file should contain the paths to all regresssion test files we have gathered
    # over the years. It is not really necessary, since we can discover them on the disk,
    # but we keep it as a legacy and a way to track double check the regression tests.
    regfile = open(os.path.join("..", "data", "regressionfiles.txt"), "r")
    regfilenames = [os.sep.join(x.strip().split("/")) for x in regfile.readlines()]
    regfile.close()

    # We will want to print a warning if you haven't downloaded all of the regression
    # test files, or when, vice versa, not all of the regression test files found on disk
    # are included in filenames. However, gather that data here and print the warnings
    # at the end so that we test all available files and the messages are displayed
    # prominently at the end.
    missing_on_disk = []
    missing_in_list = []
    for fn in regfilenames:
        if not os.path.isfile(os.path.join("..", "data", "regression", fn)):
            missing_on_disk.append(fn)
    for fn in glob.glob(os.path.join('..', 'data', 'regression', '*', '*', '*')):
        if os.path.join(*fn.split(os.path.sep)[3:]) not in regfilenames:
            missing_in_list.append(fn)

    # Create the regression test functions from logfiles that were old unittests.
    for path, test_class in old_unittests.items():
        funcname = "test" + normalisefilename(path)
        func = make_regression_from_old_unittest(test_class)
        globals()[funcname] = func

    # Gather orphaned tests - functions starting with 'test' and not corresponding
    # to any regression file name.
    orphaned_tests = []
    for ip, parser in enumerate(testall.parsers):
        prefix = "test%s" % parser
        tests = [fn for fn in globals() if fn[:len(prefix)] == prefix]
        normalize = lambda fn: normalisefilename("_".join(fn.split(os.sep)[3:]))
        normalized = [normalize(fname) for fname in filenames[ip]]
        orphaned = [t for t in tests if t[4:] not in normalized]
        orphaned_tests.extend(orphaned)

    failures = errors = total = 0
    for iname, name in enumerate(testall.parsers):

        # Continue to next iteration if we are limiting the regression and the current
        #   name was not explicitely chosen (that is, passed as an argument).
        if len(which) > 0 and not name in which:
            continue;

        print("Are the %s files ccopened and parsed correctly?" % name)
        current_filenames = filenames[iname]
        current_filenames.sort()
        for fname in current_filenames:
            total += 1
            print("  %s..."  % fname, end=" ")

            # Check if there is a test (needs to be an appropriately named function).
            # If not, there can also be a test that does not assume the file is
            # correctly parsed (for fragments, for example), and these test need
            # to be additionaly prepended with 'testnoparse'.
            test_this = test_noparse = False
            fname_norm = normalisefilename("_".join(fname.split(os.sep)[3:]))

            funcname = "test" + fname_norm
            test_this = funcname in globals()

            funcname_noparse = "testnoparse" + fname_norm
            test_noparse = not test_this and funcname_noparse in globals()

            if not test_noparse:
                try:
                    logfile  = ccopen(fname)
                except:
                    errors += 1
                    print("ccopen error")
                else:
                    if type(logfile) == type(dummyfiles[iname]):
                        try:
                            logfile.logger.setLevel(logging.ERROR)
                            logfile.data = logfile.parse()
                        except KeyboardInterrupt:
                            sys.exit(1)
                        except:
                            print("parse error")
                            errors += 1
                        else:
                            if test_this:
                                try:
                                    res = eval(funcname)(logfile)
                                    if res and len(res.failures) > 0:
                                        failures += len(res.failures)
                                        print("%i test(s) failed" % len(res.failures))
                                        if traceback:
                                            for f in res.failures:
                                                print("Failure for", f[0])
                                                print(f[1])
                                        continue
                                except AssertionError:
                                    print("test failed")
                                    failures += 1
                                else:
                                    print("parsed and tested")
                            else:
                                print("parsed")
                    else:
                        print("ccopen failed")
                        failures += 1
            else:
                try:
                    eval(funcname_noparse)(fname)
                except AssertionError:
                    print("test failed")
                    failures += 1
                except:
                    print("parse error")
                    errors += 1
                else:
                    print("test passed")
                
        print()
            
    print("Total: %d   Failed: %d  Errors: %d" % (total, failures, errors))
    if not traceback and failures + errors > 0:
        print("\nFor more information on failures/errors, add 'traceback' as an argument.")

    # Show these warnings at the end, so that they're easy to notice. Notice that the lists
    # were populated at the beginning of this function.
    if len(missing_on_disk) > 0:
        print("\nWARNING: You are missing %d regression file(s)." % len(missing_on_disk))
        print("Run regression_download.sh in the ../data directory to update.")
        print("Missing files:")
        print("\n".join(missing_on_disk))
    if len(missing_in_list) > 0:
        print("\nWARNING: The list in 'regressionfiles.txt' is missing %d file(s)." % len(missing_in_list))
        print("Add these files paths to the list and commit the change.")
        print("Missing files:")
        print("\n".join(missing_in_list))
    if len(orphaned_tests) > 0:
        print("\nWARNING: There are %d orphaned regression test functions." % len(orphaned_tests))
        print("Please make sure these function names correspond to regression files:")
        print("\n".join(orphaned_tests))

    if status and errors > 0:
        os.exit(1)
def ProJ():
# Read in molecule log files for projective method. Requires iop(3/33=1,6/7=3) in Gaussian header for calculation on each molecule + the pair
    MOLA_proj=sys.argv[1]
    MOLB_proj=sys.argv[2]
    MOLAB_proj=sys.argv[3]
    Degeneracy_HOMO=int(sys.argv[4])
    Degeneracy_LUMO=int(sys.argv[5])    # =0 for non-degenerate, 2,3 etc for doubly, triply etc

# Open the log files
    molA_parser=ccopen("%s"%(MOLA_proj))
    molB_parser=ccopen("%s"%(MOLB_proj))
    molAB_parser=ccopen("%s"%(MOLAB_proj))

# Parse the relevant data
    molA=molA_parser.parse()
    molB=molB_parser.parse()
    molAB=molAB_parser.parse()

    #print ("Parsed...")

# Size of basis sets
    nbasisA=molA.nbasis
    nbasisB=molB.nbasis
    
    #print "nbasisA: ", nbasisA
    #print "nbasisB: ", nbasisB
    
    Nbasis=nbasisA+nbasisB

# Position of H**O    
    nhomoA=molA.homos
    nhomoB=molB.homos
    
    #print "nhomoA: ", nhomoA
    #print "nhomoB: ", nhomoB
    
# Get molecular orbitals. Need the transpose for our purposes.
    MOsA=(molA.mocoeffs[0]).T
    MOsB=(molB.mocoeffs[0]).T
    MOsAB=(molAB.mocoeffs[0]).T

# Get eigenvalues of pair    
    EvalsAB=molAB.moenergies[0]
    
# Get overlaps. These are symmetric so transpose not required in this case
    SA=molA.aooverlaps
    SB=molB.aooverlaps
    SAB=molAB.aooverlaps
 
# Set up matrices for MOs and S   
    MOs=np.zeros((Nbasis,Nbasis))
    S=np.zeros((Nbasis,Nbasis))
    
    MOs[0:nbasisA,0:nbasisA]=MOsA
    MOs[nbasisA:Nbasis,nbasisA:Nbasis]=MOsB

    S[0:nbasisA,0:nbasisA]=SA
    S[nbasisA:Nbasis,nbasisA:Nbasis]=SB

# Calculate upper diagonal matrix D, such that S=D.T*D for Lowdin orthogonalisation.       
    D=sp.linalg.cholesky(S)

    Dpair=sp.linalg.cholesky(SAB)

# Orthogonalise MOs matrix and MOsAB matrix
    MOsorth=np.dot(D,MOs)

    #print np.shape(MOsorth)

    MOspairorth=np.dot(Dpair,MOsAB)

    #print np.shape(MOspairorth)

# Calculate the Fock matrix    
    B=np.dot(MOsorth.T,MOspairorth)
    Evals=np.diagflat(EvalsAB)    
    F=np.dot(np.dot(B,Evals),B.T)


# Output the H**O-H**O and LUMO-LUMO coupling elements fromt the Fock matrix

    if Degeneracy_HOMO==0:
        print "H**O-H**O coupling: ", F[nhomoB+nbasisA,nhomoA]

    if Degeneracy_LUMO==0:
        print "LUMO-LUMO coupling: ", F[nhomoB+nbasisA+1,nhomoA+1]

# Degeneracies

    if Degeneracy_HOMO!=0:
        F_deg_HOMO=F[nhomoB+nbasisA-Degeneracy_HOMO+1:nhomoB+nbasisA+1,nhomoA-Degeneracy_HOMO:nhomoA]
        print "H**O-H**O coupling", (np.sum(np.absolute(F_deg_HOMO**2)))/Degeneracy_HOMO**2

    if Degeneracy_LUMO!=0:
        F_deg_LUMO=F[nhomoB+nbasisA:nhomoB+nbasisA+Degeneracy_LUMO,nhomoA:nhomoA+Degeneracy_LUMO]
        print "LUMO-LUMO coupling", (np.sum(np.absolute(F_deg_LUMO**2)))/Degeneracy_LUMO**2
Example #51
0
        density.data = density.data*2. # doubly-occupied
    
    return density


if __name__=="__main__":

    try:
        import psyco
        psyco.full()
    except ImportError:
        pass

    from cclib.parser import ccopen
    import logging
    a = ccopen("../../../data/Gaussian/basicGaussian03/dvb_sp_basis.log")
    a.logger.setLevel(logging.ERROR)
    c = a.parse()
    
    b = ccopen("../../../data/Gaussian/basicGaussian03/dvb_sp.out")
    b.logger.setLevel(logging.ERROR)
    d = b.parse()

    vol = Volume( (-3.0,-6,-2.0), (3.0, 6, 2.0), spacing=(0.25,0.25,0.25) )
    wavefn = wavefunction(d.atomcoords[0], d.mocoeffs[0][d.homos[0]],
                          c.gbasis, vol)
    assert abs(wavefn.integrate())<1E-6 # not necessarily true for all wavefns
    assert abs(wavefn.integrate_square() - 1.00)<1E-3 #   true for all wavefns
    print wavefn.integrate(), wavefn.integrate_square()

    vol = Volume( (-3.0,-6,-2.0), (3.0, 6, 2.0), spacing=(0.25,0.25,0.25) )
Example #52
0
def main(which=[], traceback=False):

    # Print a warning if you haven't downloaded all of the regression test files,
    # or an error if not all of the regression test files are included in filenames.
    regfile = open(os.path.join("..", "data", "regressionfiles.txt"), "r")
    regfilenames = [os.sep.join(x.strip().split("/")) for x in regfile.readlines()]
    regfile.close()

    missing = 0
    for x in regfilenames:
        if not os.path.isfile(os.path.join("..", "data", x)):
            missing += 1
        elif os.path.join("..", "data", x) not in flatten(filenames):
            print("\nERROR: The regression file %s is present, but not included in " \
                  "the 'filenames' variable.\n\nPlease add a new glob statement." % x)
            sys.exit(1)       

    if missing > 0:
        print("\nWARNING: You are missing %d regression file(s).\n" \
              "         Run wget.sh in the ../data directory to update.\n" % missing)
        try:
            input("(Press ENTER to continue or CTRL+C to exit)")
        except KeyboardInterrupt:
            print("\n")
            sys.exit(0)

    # When a unit test is removed or replaced by a newer version, the old logfile
    # typically becomes a regression, and normally we still want to run the unit test
    # within the regression suite. To this end, add the logfile location to a list
    # called 'old_tests' in the appropriate unit test class, in which case the
    # following code will find it and create the becessary regression test function.
    for mod in test_modules:
        mod_name = "test" + mod
        tests = inspect.getmembers(__import__(mod_name), inspect.isclass)
        tests = [tc for tc in tests if tc[0][-4:] == "Test"]
        for test_name, test_class in tests:
            for old in getattr(test_class, "old_tests", []):
                funcname = "test" + normalisefilename(old)
                func = make_regression_from_old_unittest(old, mod_name, test_name)
                globals()[funcname] = func

    failures = errors = total = 0
    for iname, name in enumerate(parsers):

        # Continue to next iteration if we are limiting the regression and the current
        #   name was not explicitely chosen (that is, passed as an argument).
        if len(which) > 0 and not name in which:
            continue;

        print("Are the %s files ccopened and parsed correctly?" % name)
        current_filenames = filenames[iname]
        current_filenames.sort()
        for fname in current_filenames:
            total += 1
            print("  %s..."  % fname, end=" ")

            # Check if there is a test (needs to be an appropriately named function).
            # If not, there can also be a test that does not assume the file is
            # correctly parsed (for fragments, for example), and these test need
            # to be additionaly prepended with 'testnoparse'.
            test_this = test_noparse = False
            fname_norm = normalisefilename("_".join(fname.split(os.sep)[2:]))

            funcname = "test" + fname_norm
            test_this = funcname in globals()

            funcname_noparse = "testnoparse" + fname_norm
            test_noparse = not test_this and funcname_noparse in globals()

            if not test_noparse:
                try:
                    logfile  = ccopen(fname)
                except:
                    errors += 1
                    print("ccopen error")
                else:
                    if type(logfile) == type(dummyfiles[iname]):
                        try:
                            logfile.logger.setLevel(logging.ERROR)
                            logfile.data = logfile.parse()
                        except KeyboardInterrupt:
                            sys.exit(1)
                        except:
                            print("parse error")
                            errors += 1
                        else:
                            if test_this:
                                try:
                                    res = eval(funcname)(logfile)
                                    if res and len(res.failures) > 0:
                                        failures += len(res.failures)
                                        print("%i test(s) failed" % len(res.failures))
                                        if traceback:
                                            for f in res.failures:
                                                print("Failure for", f[0])
                                                print(f[1])
                                        continue
                                except AssertionError:
                                    print("test failed")
                                    failures += 1
                                else:
                                    print("parsed and tested")
                            else:
                                print("parsed")
                    else:
                        print("ccopen failed")
                        failures += 1
            else:
                try:
                    eval(funcname_noparse)(filename)
                except AssertionError:
                    print("test failed")
                    failures += 1
                except:
                    print("parse error")
                    errors += 1
                else:
                    print("test passed")
                
        print
            
    print("Total: %d   Failed: %d  Errors: %d" % (total, failures, errors))
    if not traceback and failures + errors > 0:
        print("\nFor more information on failures/errors, add 'traceback' as argument.")
Example #53
0
File: moldy.py Project: shrx/moldy
    def readGaussian(self):
        global vsShifted
        self.ZMatModel.dataChanged.disconnect(self.clearUpdateView)
        filename = self.fileDialog.getOpenFileName(self, 'Open file', expanduser('~'), '*.log;;*.*')
        if filename:
            self.gaussianPlot.clear()
            self.inp = []
            self.populateZMatModel()
            file = ccopen(filename)
            data = file.parse().getattributes()
            self.natom = data['natom']
            self.atomnos = data['atomnos'].tolist()
            self.atomsymbols = [ str(elements[e]) for e in self.atomnos ]
            self.atomcoords = data['atomcoords'].tolist()
            self.scfenergies = data['scfenergies'].tolist()
            self.geovalues = data['geovalues'].T.tolist()
            self.geotargets = data['geotargets'].tolist()
            if 'vibfreqs' in data.keys():
                self.vibfreqs = data['vibfreqs']
                #print(self.vibfreqs)
                self.vibirs = data['vibirs']
                #print(self.vibirs)
                #print(data.keys())
                if 'vibramans' in data.keys():
                    self.vibramans = data['vibramans']
                else:
                    self.vibramans = [''] * len(self.vibirs)
                self.vibdisps = data['vibdisps']
                #print(self.vibdisps)
            self.inp = xyz2zmat(self.atomcoords[0], self.atomsymbols)
            self.populateZMatModel()

            titles = ['SCF Energies', 'RMS & Max Forces', 'RMS & Max Displacements']
            for i in range(3):
                self.gaussianPlot.addPlot(row=1, col=i+1)
                plot = self.gaussianPlot.getItem(1, i+1)
                plot.setTitle(title=titles[i])
                if i == 0:
                    c = ['c']
                    x = [0]
                    y = [self.scfenergies]
                else:
                    c = ['r', 'y']
                    x = [0, 0]
                    y = [self.geovalues[2*i-2], self.geovalues[2*i-1]]
                    targety = [self.geotargets[2*i-2], self.geotargets[2*i-1]]
                plot.clear()
                plot.maxData = plot.plot(y[0], symbol='o', symbolPen=c[0], symbolBrush=c[0], pen=c[0], symbolSize=5, pxMode=True, antialias=True, autoDownsample=False)
                plot.highlight=plot.plot(x, [ yy[0] for yy in y ], symbol='o', symbolPen='w', symbolBrush=None, pen=None, symbolSize=15, pxMode=True, antialias=True, autoDownsample=False)
                plot.maxData.sigPointsClicked.connect(self.gausclicked)
                if i > 0:
                    for j in range(2):
                        plot.addLine(y=np.log10(targety[j]), pen=mkPen((255, 255*j, 0, int(255/2)), width=1))
                    plot.RMSData=plot.plot(y[1], symbol='o', symbolPen=c[1], symbolBrush=c[1], pen=c[1], symbolSize=5, pxMode=True, antialias=True, autoDownsample=False)
                    plot.RMSData.sigPointsClicked.connect(self.gausclicked)
                    plot.setLogMode(y=True)
            self.showGauss()
            self.updateView()
            self.statusBar.clearMessage()
            self.statusBar.showMessage('Read molecule from '+filename+'.', 5000)
            self.ZMatModel.dataChanged.connect(self.clearUpdateView)
            if self.natom:
                self.showGaussAction.setEnabled(True)
            if 'vibfreqs' in data.keys():
                self.showFreqAction.setEnabled(True)

                # populate the FreqModel
                self.populateFreqModel()

                self.freqPlot.clear()
                irPlot = self.freqPlot.addPlot(row=1, col=1)
                irPlot.clear()
                minFreq = np.min(self.vibfreqs)
                maxFreq = np.max(self.vibfreqs)
                maxInt = np.max(self.vibirs)
                x = np.sort(np.concatenate([np.linspace(minFreq-100, maxFreq+100, num=1000), self.vibfreqs]))
                y = x*0
                for f,i in zip(self.vibfreqs, self.vibirs):
                    y += lorentzv(x, f, 2*np.pi, i)
                #xy = np.array([np.concatenate([x, np.array(self.vibfreqs)]), np.concatenate([y, np.array(self.vibirs)])]).T
                #xysort = xy[xy[:,0].argsort()]
                irPlot.maxData = irPlot.plot(x, y, antialias=True)
                markers = ErrorBarItem(x=self.vibfreqs, y=self.vibirs, top=maxInt/30, bottom=None, pen='r')
                irPlot.addItem(markers)
                self.showFreq()
                #self.vibdisps = np.append(self.vibdisps, [np.mean(self.vibdisps, axis=0)], axis=0)
                maxt = 100
                vsShifted = np.array([ [ vs + self.vibdisps[i]*np.sin(t*2*np.pi/maxt)/3 for t in range(maxt) ] for i in range(len(self.vibfreqs)) ])
            else:
                self.showFreqAction.setEnabled(False)
                self.freqWidget.hide()
Example #54
0
def stretch(outputfile, shift=2.0, templatefiles=None):
    """
    Generate transition state search for given xyzfile,
    assuming that the first 2 atoms are the bond forming atoms

    outputfile is assumed to be a geometry optimization Q-Chem output

    TODO: option to set fname, and default to the templatefilename + index?
    """
    savexyz = True

    # If templatefiles doesn't exist, we only save stretched xyz
    if templatefiles:

        # Always convert templatefiles into list
        if not type(templatefiles) is list:
            templatefiles = [templatefiles]

        # Only keep the templatefiles that exists
        templatefiles = [templatefile for templatefile in templatefiles
                         if templates.exists(templatefile)]

        # If at least one templatefile exists, we don't save xyz
        if templatefiles:
            savexyz = False

    ccdata = ccopen(outputfile).parse()

    fname, _ = os.path.splitext(outputfile)
    #xyzfile = fname+'.xyz'
    #write.xyzfile(outputccdata, xyzfile)

    product = ccData_xyz(ccdata.getattributes())
    ccdatas = []
    #product = parse.xyzfile(xyzfile, ccxyz=True)
    product.build_zmatrix()
    reactant = copy.deepcopy(product)
    reactant.distances[1] += shift

    # TODO:If reactants provided, use their geometry internal coords
    # and modify internalcoords of reactant

    # FIXME hardcoded paths instead of cli args
    #rpaths = ['../../initiators/MeO/0.omegab97x-d_opt.out', '../../ketenes/TMS/0.omegab97x-d_opt.out']

    #reactants = []
    #for rpath in rpaths:
    #    reactants.append(parse.xyzfile(rpath, ccdata_xyz=True))

    #for r in reactants:
    #    r.build_zmatrix()

    # TODO Determine which reactant is which
    # Some ways to do this:
        # numatom, atomnos
    # TODO How to deal with symmetrical reactants?
        # Just guess (1/2 chance) - possibly cli to swap if wrong

    product.build_xyz()
    reactant.build_xyz()

    ccdatas.append(reactant)
    ccdatas.append(product)

    if not savexyz:
        for i in range(len(templatefiles)):
            if len(templatefiles) == 1:
                idx = ''
            else:
                idx = '-'+str(i)

            if 'opt' in fname:
                fname = fname.replace('opt', 'fsm')
            else:
                fname = fname + '_fsm'

            write.inputfile(ccdatas,
                            templatefiles[i],
                            fname+idx+'.qcm')
    else:
        reactant.print_xyz()