示例#1
0
def test_read_logfile():
    """Tests the logfile parser"""
    structure = get_fn('PRL.psf')
    logfiles = [get_fn('PRL.scan2.neg.log'), get_fn('PRL.scan2.pos.log')]
    scan = qmdb.parse_gauss(logfiles, structure)
    scan1 = Gaussian(logfiles[0])
    scan2 = Gaussian(logfiles[1])
    data1 = scan1.parse()
    data2 = scan2.parse()
    assert_almost_equal(scan.xyz[:40] * 10, data1.atomcoords, decimal=6)
    assert_almost_equal(scan.xyz[40:] * 10, data2.atomcoords, decimal=6)
示例#2
0
def gaussian_modes(path_or_parser):
    """
    Read the modes
    Create a prody.modes instance

    Parameters
    ----------
    path_or_parser : str or cclib.Gaussian
        gaussian frequencies output path
        or already parsed cclib.Gaussian instance

    Returns
    -------
    modes : ProDy modes ANM or RTB
    """
    if isinstance(path_or_parser, basestring):
        parsed = Gaussian(path_or_parser).parse()
    else:
        parsed = path_or_parser
    shape = parsed.vibdisps.shape
    modes_vectors = parsed.vibdisps.reshape(shape[0], shape[1] * shape[2]).T
    modes_frequencies = np.abs(parsed.vibfreqs)
    modes = prody.NMA()
    modes.setEigens(vectors=modes_vectors, values=modes_frequencies)
    return modes
示例#3
0
def process_cmd_line(argv):
    prefix = ""
    gauss_fn = sys.argv[1]
    pdb_fn = sys.argv[2]

    import cclib
    from cclib.parser import Gaussian
    #from cclib.method import CSPA #MPA
    myfile = Gaussian(gauss_fn)
    data = myfile.parse()
    opt_coords = data.atomcoords[-1]  # last coords from the optimization

    charges = get_mulliken_charges(fn)[-1]
    #analysis = CSPA(myfile)#MPA(myfile)
    #if analysis.calculate():
    #    charges = analysis.fragcharges # last coords from the optimization
    #    print(charges)

    paramslines = []
    try:
        with open(sys.argv[3]) as f:
            paramslines = f.readlines()
    except:
        with open(
                ROSETTA +
                "/main/database/chemical/residue_type_sets/fa_standard/residue_types/{}.params"
                .format(params)) as f:
            paramslines = f.readlines()

    pdb = []
    with open(pdb_fn) as f:
        pdb = f.readlines()

    return opt_coords, charges, pdb, paramslines
示例#4
0
def test_converged_structures():
    """Tests that non converged coordinates in Gaussian log files are discarded"""
    structure = get_fn('MPR.psf')
    scan = qmdb.parse_gauss(get_fn('MPR.scan1.pos.log'), structure)
    log = Gaussian(get_fn('MPR.scan1.pos.log'))
    data = log.parse()
    assert_array_equal(data.atomcoords.shape, scan.xyz.shape)
    converted = convertor(data.scfenergies, "eV", "kJmol-1") - \
                min(convertor(data.scfenergies[:len(data.atomcoords)], "eV", "kJmol-1"))
    assert_array_equal(converted[:47], scan.qm_energy)
示例#5
0
 def from_gaussian(cls, gaussian_path, task=None):
     """
     initializes from a gaussian output file
     """
     gaussian_parser = Gaussian(gaussian_path).parse()
     modes = gaussian_modes(gaussian_parser)
     chimera_molecule = convert_gaussian_molecule_to_chimera(
         gaussian_parser)
     chimera.openModels.add([chimera_molecule])
     return cls(chimera_molecule, modes)
示例#6
0
def testnoparseGaussian_Gaussian09_coeffs_zip(filename):
    """This is a test for a Gaussian file with more than 999 basis functions.

    The log file is too big, so we are just including a section. Before
    parsing, we set some attributes of the parser so that it all goes smoothly.
    """

    d = Gaussian(filename)
    d.logger.setLevel(logging.ERROR)
    d.nmo = 5
    d.nbasis = 1128

    logfile = d.parse()
    assert logfile.data.mocoeffs[0].shape == (5, 1128)
    assert logfile.data.aonames[-1] == "Ga71_19D-2"
    assert logfile.data.aonames[0] == "Mn1_1S"
示例#7
0
def convert_gaussian_molecule_to_chimera(path_or_parser):
    if isinstance(path_or_parser, basestring):
        parsed = Gaussian(path_or_parser).parse()
    else:
        parsed = path_or_parser

    elements = parsed.atomnos
    coords = parsed.atomcoords[-1]
    m = chimera.Molecule()
    r = m.newResidue("UNK", " ", 1, " ")
    for i, (element, xyz) in enumerate(zip(elements, coords)):
        element = chimera.Element(element)
        a = m.newAtom('{}{}'.format(element, i), element)
        r.addAtom(a)
        a.setCoord(chimera.Point(*xyz))
        a.serialNumber = i
    chimera.connectMolecule(m)
    return m
示例#8
0
def gaussian_modes(path):
    """
    Read the modes
    Create a prody.modes instance

    Parameters
    ----------
    path : str
        gaussian frequencies output path

    Returns
    -------
    modes : ProDy modes ANM or RTB
    """
    gaussian_parser = Gaussian(path).parse()
    shape = gaussian_parser.vibdisps.shape
    modes_vectors = gaussian_parser.vibdisps.reshape(shape[0],
                                                     shape[1] * shape[2]).T
    modes_frequencies = numpy.abs(gaussian_parser.vibfreqs)
    modes = prody.NMA()
    modes.setEigens(vectors=modes_vectors, values=modes_frequencies)
    return modes
示例#9
0
def parse_gauss(logfiles, structure):
    """ parses Guassian09 torsion-scan log file

    parameters
    ----------
    logfiles: str of list of str
                Name of Guassian 09 torsion scan log file
    structure: charmm psf file

    returns
    -------
    TorsionScanSet
    """
    topology = md.load_psf(structure)
    structure = CharmmPsfFile(structure)
    positions = np.ndarray((0, topology.n_atoms, 3))
    qm_energies = np.ndarray(0)
    torsions = np.ndarray((0, 4), dtype=int)
    directions = np.ndarray(0, dtype=int)
    steps = np.ndarray((0, 3), dtype=int)

    if type(logfiles) != list:
        logfiles = [logfiles]

    for file in (logfiles):
        direction = np.ndarray(1)
        torsion = np.ndarray((1, 4), dtype=int)
        step = np.ndarray((0, 3), dtype=int)
        index = (2, 12, -1)
        log = Gaussian(file)
        data = log.parse()
        # convert angstroms to nanometers
        positions = np.append(positions, data.atomcoords * 0.1, axis=0)
        # Only add qm energies for structures that converged (because cclib throws out those coords but not other info)
        qm_energies = np.append(qm_energies, (convertor(
            data.scfenergies[:len(data.atomcoords)], "eV", "kJmol-1") - min(
                convertor(data.scfenergies[:len(data.atomcoords)], "eV",
                          "kJmol-1"))),
                                axis=0)

        fi = open(file, 'r')
        for line in fi:
            if re.search('   Scan   ', line):
                t = line.split()[2].split(',')
                t[0] = t[0][-1]
                t[-1] = t[-1][0]
                for i in range(len(t)):
                    torsion[0][i] = (int(t[i]) - 1)
            if re.search('^ D ', line):
                d = line.split()[-1]
                if d[0] == '-':
                    direction[0] = 0
                elif d[0] == '1':
                    direction[0] = 1
            if re.search('Step', line):
                try:
                    point = np.array(([int(line.rsplit()[j]) for j in index]))
                    point = point[np.newaxis, :]
                    step = np.append(step, point, axis=0)
                except:
                    pass

        fi.close()
        # only add scan points from converged structures
        steps = np.append(steps, step[:len(data.atomcoords)], axis=0)
        for i in range(len(data.atomcoords)):
            torsions = np.append(torsions, torsion, axis=0)
            directions = np.append(directions, direction, axis=0)
        del log
        del data
    return QMDataBase(positions=positions,
                      topology=topology,
                      structure=structure,
                      torsions=torsions,
                      steps=steps,
                      qm_energies=qm_energies,
                      directions=directions)
示例#10
0
    j = 0
    for excitation in eStr:
        if excitation > bestExcitationStr:
            bestExcitationStr = excitation
            bestExcitationIdx = j
        j += 1

    # OK, now bestExcitationIdx has the best index
    exState[smiles] = homos[smiles] + float(eTrans[bestExcitationIdx])
    exStr[smiles] = bestExcitationStr

i = 0
t = open('hexamer/top_smiles.txt', 'r')

for line in t:
    smiles = line.split(' ')[0].split('_')[0]
    eff = line.split(' ')[1].rstrip()

    myfile = Gaussian("gaussian/hex-00/%d.g09" % i)
    myfile.logger.setLevel(logging.ERROR)
    data = myfile.parse()
    homoE = data.moenergies[0][data.homos[0]]
    excitation = data.etenergies[0] * 0.00012398
    lumoE = homoE + excitation

    eff2 = efficient.efficiency(homoE, excitation, -4.61)

    print smiles, eff, homos[smiles], exState[smiles], exStr[
        smiles], eff2, homoE, lumoE, data.etoscs[0]
    i += 1
示例#11
0
   bestExcitationStr = 0.0
   j = 0
   for excitation in eStr:
      if excitation > bestExcitationStr:
         bestExcitationStr = excitation
         bestExcitationIdx = j
      j += 1

   # OK, now bestExcitationIdx has the best index
   exState[smiles] = homos[smiles] + float(eTrans[bestExcitationIdx])
   exStr[smiles] = bestExcitationStr

i = 0
t = open('octamer/top_smiles.txt', 'r')

for line in t:
   smiles = line.split(' ')[0].split('_')[0]
   eff = line.split(' ')[1].rstrip()

   myfile = Gaussian("gaussian/oct-00/%d.g09" % i)
   myfile.logger.setLevel(logging.ERROR)
   data = myfile.parse()
   homoE = data.moenergies[0][data.homos[0]]
   excitation = data.etenergies[0] * 0.00012398
   lumoE = homoE + excitation

   eff2 = efficient.efficiency(homoE, excitation, -4.61)

   print smiles, eff, homos[smiles], exState[smiles], exStr[smiles], eff2, homoE, lumoE, data.etoscs[0]
   i += 1