Example #1
0
 def _Parse(self):
     lines = open(self.inputfile)
     atoms = []
     try:
         # . Read header
         #   MNDOD  1SCF  CHARGE=-2      GRAD  XYZ  MULLIK  DEBUG MOL_QMMM
         line = next(lines)
         tokens = TokenizeLine(line)
         self.keywords = tokens
         xyz = False
         for token in tokens:
             if token.startswith("MNDOD"):
                 pass
             elif token.startswith("CHARGE"):
                 keyword, charge = token.split("=")
                 self._charge = float(charge)
             elif token.startswith("MULLIK"):
                 pass
             elif token.startswith("XYZ"):
                 xyz = True
         # . Read comment
         line = next(lines)
         self.comment = line
         # . Skip one line
         line = next(lines)
         # . Read geometry
         #    C       3.6661  1       6.4850  1      12.9735  1
         #    O       4.8715  1       6.4228  1      13.6710  1
         #    O       4.0062  1       5.5052  1      15.8884  1
         # (...)
         while True:
             line = next(lines)
             if xyz:
                 tokens = TokenizeLine(
                     line,
                     converters=[None, float, int, float, int, float, int])
                 # . There may be a blank line at the end
                 if len(tokens) > 0:
                     atomLabel = tokens[0]
                     atomX, atomY, atomZ = tokens[1], tokens[3], tokens[5]
                     atom = Atom(
                         label=atomLabel,
                         x=atomX,
                         y=atomY,
                         z=atomZ,
                     )
                     atoms.append(atom)
     except StopIteration:
         pass
     # . Close the file
     lines.close()
     # . Finish up
     self.atoms = atoms
Example #2
0
 def Parse_ToList(self):
     data = open(self.filename)
     steps = []
     try:
         while True:
             line = data.next()
             if line.count("steps"):
                 pairs = []
                 while True:
                     line = data.next()
                     if not (line.count("average distance")
                             or line.strip() == ""):
                         tokens = TokenizeLine(
                             line,
                             reverse=True,
                             converters=[float, float, int, int, int])
                         electro, distance, pairb, paira, step = tokens
                         if step:
                             if pairs:
                                 steps.append(pairs)
                                 pairs = []
                         pairs.append(distance)
     except StopIteration:
         pass
     data.close()
     if pairs:
         steps.append(pairs)
     self.steps = steps
Example #3
0
 def Parse_ToDictionary(self):
     data = open(self.filename)
     pairs = {}
     try:
         while True:
             line = data.next()
             if line.count("steps"):
                 while True:
                     line = data.next()
                     if not (line.count("average distance")
                             or line.strip() == ""):
                         tokens = TokenizeLine(
                             line,
                             reverse=True,
                             converters=[float, float, int, int, int])
                         electro, distance, pairb, paira, step = tokens
                         key = (paira, pairb)
                         if not pairs.has_key(key):
                             pairs[key] = []
                         distances = pairs[key]
                         distances.append(distance)
     except StopIteration:
         pass
     data.close()
     # . Also create swapped pairs
     for key in pairs.keys():
         keya, keyb = key
         swap = (keyb, keya)
         pairs[swap] = pairs[key]
     self.pairs = pairs
Example #4
0
 def _Parse (self, filename):
     lines  = open (filename)
     steps  = []
     if self.logging:
         print ("# . %s> Parsing file \"%s\"" % (_MODULE_LABEL, filename))
     try:
         #                   0  0.00100000 0.00    2 0.0000 0.0000   0   0.0000000  -1.0000000
         #       0       -7215.96    -1601300.60
         #       1       -7230.30    -1601303.26
         #   (...)
         # . Read and ignore header
         line   = next (lines)
         # . Read steps
         while True:
             line   = next (lines)
             tokens = TokenizeLine (line, converters=[int, float, float])
             index, potentialReference, potentialTarget = tokens
             step   = GapStep (
                 target    = potentialTarget     ,
                 reference = potentialReference  , )
             if index < 1:
                 if self.ignoreStepZero:
                     continue
             steps.append (step)
     except StopIteration:
         pass
     # . Finalize
     lines.close ()
     if hasattr (self, "steps"):
         self.steps.extend (steps)
     else:
         self.steps = steps
     if self.logging:
         nsteps = len (steps)
         print ("# . %s> Read %d steps" % (_MODULE_LABEL, nsteps))
Example #5
0
 def _GetContainer(self, data, ntokens):
     serials = TokenizeLine(next(data), converters=([
         int,
     ] * ntokens))
     types = TokenizeLine(next(data), converters=([
         int,
     ] * self.nforms))
     exist = TokenizeLine(next(data), converters=([
         int,
     ] * self.nforms))
     container = EVBContainer(
         serials=serials,
         types=types,
         exist=exist,
     )
     return container
Example #6
0
 def _Parse (self, filename):
     lines  = open (filename)
     steps  = []
     if self.logging:
         print ("# . %s> Parsing file \"%s\"" % (_MODULE_LABEL, filename))
     try:
         #                   0  0.00100000 0.00    2 0.0000 1.0000   0   0.0000000  -1.0000000
         # -233.01     0.00    0.03      0.10    0.00  -251.70    0.00    18.55    0.00  -214.51    0.00    0.00    0.22   -18.86    0.00    0.00    1.76  -9648.77    0.00    0.00    0.00    0.00    6.96    0.00
         #    0.00     0.00    0.00 0  0
         #    0.00  -233.01    0.03      0.10    0.00  -251.70    0.00    18.55    0.00  -214.51    0.00    0.00    0.22   -18.86    0.00    0.00   10.08  -9648.77    0.00    0.00    0.00    0.00    6.96    0.00
         #    0.00     0.00    0.00 0  0
         while True:
             # . Read each step's header
             line   = next (lines)
             tokens = TokenizeLine (line, converters=[int, ])
             index  = tokens[0]
             # . Read data for state I
             line   = next (lines)
             tokens = TokenizeLine (line, converters=[float, ] * 24)
             # TODO: Include other terms too
             Ea     = tokens[16]
             line   = next (lines)
             # . Read data for state II
             line   = next (lines)
             tokens = TokenizeLine (line, converters=[float, ] * 24)
             # TODO: Include other terms too
             Eb     = tokens[16]
             line   = next (lines)
             step   = GapStep (
                 target    = Ea ,
                 reference = Eb , )
             if index < 1:
                 if self.ignoreStepZero:
                     continue
             steps.append (step)
     except StopIteration:
         pass
     # . Finalize
     lines.close ()
     if hasattr (self, "steps"):
         self.steps.extend (steps)
     else:
         self.steps = steps
     if self.logging:
         nsteps = len (steps)
         print ("# . %s> Read %d steps" % (_MODULE_LABEL, nsteps))
Example #7
0
 def SplitComment(self):
     """Return tokens of atom's comment."""
     try:
         (charge, atype, label,
          group) = TokenizeLine(self.comment,
                                converters=[float, None, None, None])
         return (charge, atype, label, group)
     except:
         pass
     return (0., "", "", "")
Example #8
0
 def _ParseVMDFile(self, filename, wrapTorsions=False):
     lines = open(filename, "r").readlines()
     collect = []
     for line in lines:
         (foo, value) = TokenizeLine(line, converters=[float, float])
         if wrapTorsions:
             if (value < 0.):
                 if (value < 90.):
                     value += 360.
         collect.append(value)
     return collect
Example #9
0
    def GetPairs(self, state=1):
        """Get a pair (label, type) for each EVB atom.

        Atoms must have comments generated by GenerateEVBList, since these comments contain atom labels:

        evb_atm     1     1.15    P0        1.15    P0    #   0.700    P4    PG    A
        evb_atm     2    -0.76    O-       -0.76    O-    #  -0.900    O3   O1G    A
        (...)"""
        pairs = []
        atoms = self.states[state - 1]
        for atom in atoms:
            (enzymixCharge, enzymixType, label,
             groupLabel) = TokenizeLine(atom.comment,
                                        converters=[float, None, None, None])
            pair = (label, atom.atype)
            pairs.append(pair)
        return pairs
 def _Parse(self):
     lines = open(self.inputfile)
     field = []
     try:
         while True:
             line = next(lines)
             (ex, ey, ez) = TokenizeLine(line,
                                         converters=[float, float, float])
             # . There is not need to multiply the gradients by -1, since Molaris does it after reading the d.o file.
             vector = (
                 ex * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                 ey * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                 ez * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
             )
             field.append(vector)
     except StopIteration:
         pass
     # . Close file
     lines.close()
     self.field = field
Example #11
0
 def _Parse (self, reverse, convert):
     lines = open (self.inputfile)
     # . Get the number of atoms
     line   = next (lines)
     natoms = int (line)
     # . Read forces
     forces = []
     for i in range (natoms):
         line   = next (lines)
         gx, gy, gz = TokenizeLine (line, converters=[float, float, float])
         if reverse:
             gx, gy, gz = (-gx, -gy, -gz)
         if convert:
             gx, gy, gz = (gx * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM, gy * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM, gz * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM)
         force = Force (
             x   =   gx  ,
             y   =   gy  ,
             z   =   gz  ,
             )
         forces.append (force)
     self.forces = forces
     # . Close the file
     lines.close ()
    def _Parse(self):
        lines = open(self.inputfile)
        try:
            while True:
                line = next(lines)
                # . Get geometry
                #             Standard Nuclear Orientation (Angstroms)
                #    I     Atom           X                Y                Z
                # ----------------------------------------------------------------
                #    1      C       0.3610741620    -1.0892812370     0.3333499280
                #    2      H      -0.5915297190    -0.4548440630     0.3617850530
                # (...)
                # ----------------------------------------------------------------
                if line.count("Standard Nuclear Orientation (Angstroms)"):
                    for i in range(2):
                        next(lines)
                    atoms = []
                    line = next(lines)
                    while not line.count("----"):
                        (serial, symbol, x, y, z) = TokenizeLine(
                            line, converters=[int, None, float, float, float])
                        atom = Atom(symbol=symbol, x=x, y=y, z=z)
                        atoms.append(atom)
                        line = next(lines)
                    self.atoms = atoms

                # . Get Mulliken charges
                #          Ground-State Mulliken Net Atomic Charges
                #
                #     Atom                 Charge (a.u.)
                #  ----------------------------------------
                #      1 C                    -0.564153
                #      2 H                     0.296853
                # (...)
                #  ----------------------------------------
                elif line.count("Ground-State Mulliken Net Atomic Charges"):
                    for i in range(3):
                        next(lines)
                    charges = []
                    line = next(lines)
                    while not line.count("----"):
                        tokens = TokenizeLine(line,
                                              converters=[int, None, float])
                        charges.append(tokens[2])
                        line = next(lines)
                    self.charges = charges

                # . Get self energy of point charges
                #
                # Charge-charge energy     =  -250.9297020579 hartrees
                elif line.startswith(" Charge-charge energy"):
                    tokens = TokenizeLine(line,
                                          converters=[None, float],
                                          reverse=True)
                    self.Echrg = tokens[1] * HARTREE_TO_KCAL_MOL

                # . Get final SCF energy
                #
                # SCF   energy in the final basis set = -1211.5551873917
                elif line.startswith(" SCF   energy in the final basis set"):
                    tokens = TokenizeLine(line,
                                          converters=[
                                              float,
                                          ],
                                          reverse=True)
                    self.Efinal = tokens[0] * HARTREE_TO_KCAL_MOL

                # . Get gradients on QM atoms
                #
                # Calculating analytic gradient of the SCF energy
                # Gradient of AOints
                #            1           2           3           4           5           6
                #    1   5.1830948   0.7198311  -1.3316471   5.4310464   8.1701661 -15.4180387
                #    2  -1.7031303  -3.3832442   7.5553033  -3.1040094  -0.7271863  -5.9138090
                #    3  -6.0741297  -1.1303131   6.6925970   6.6271716  -4.8774107   6.8801270
                # (...)
                #           13
                #    1   1.7575832
                #    2   8.2313758
                #    3  -5.5451689
                elif line.startswith(
                        " Calculating analytic gradient of the SCF energy"):
                    line = next(lines)
                    if line.startswith(" Gradient of AOints"):
                        nblocks = self.natoms / _ATOMS_PER_LINE
                        if (self.natoms % _ATOMS_PER_LINE != 0):
                            nblocks += 1
                        forces = []
                        for i in range(nblocks):
                            header = next(lines)
                            coordinates = []
                            for j in range(3):
                                line = next(lines)
                                tokens = TokenizeLine(line,
                                                      converters=([
                                                          None,
                                                      ] + [
                                                          float,
                                                      ] * _ATOMS_PER_LINE))
                                coordinates.append(tokens[1:])
                            for (x, y, z) in zip(coordinates[0],
                                                 coordinates[1],
                                                 coordinates[2]):
                                if x != None:
                                    force = Force(
                                        x=-x,
                                        y=-y,
                                        z=-z,
                                    )
                                    forces.append(force)
                        self.forces = forces
        except StopIteration:
            pass
        # . Close file
        lines.close()
Example #13
0
    def _Parse(self):
        lines = open(self.inputfile)
        try:
            while True:
                line = next(lines)
                # . Read the header
                if line.count("MD step"):
                    line = line[:line.find("MD step")]
                    tokens = TokenizeLine(line)
                    if len(tokens) != 9:
                        # . Old format
                        tokens = TokenizeLine(line,
                                              converters=[
                                                  int, float, float, float,
                                                  float, float, float, int
                                              ])
                        step, energy = tokens[:2]
                    else:
                        # . New format
                        tokens = TokenizeLine(line,
                                              converters=[
                                                  int, float, float, float,
                                                  float, float, float, int, int
                                              ])
                        (step, energy), stateID = tokens[:2], tokens[-1]
                        self.stateID = stateID
                    self.mdstep = step
                    self.Etot = energy

                # . Read the QM section
                elif line.count("# of qmmm atoms"):
                    nquantum, nlink = TokenizeLine(line, converters=[int, int])
                    # . Read QM atoms proper
                    self.qatoms = self._ReadAtoms(lines, nquantum)
                    # . Read QM link atoms
                    self.latoms = self._ReadAtoms(lines, nlink)

                elif line.count(
                        "# of total frozen protein atoms, # of groups in Region I`"
                ):
                    pass

                elif line.count("# of frozen water atoms in Region I`"):
                    pass

                # . Read the protein section
                elif line.count("# of non-frozen protein atoms in Region II"):
                    nprot = TokenizeLine(line, converters=[int])[0]
                    self.patoms = self._ReadAtoms(lines,
                                                  nprot,
                                                  includeCharge=True)

                # . Read the free water section
                elif line.count("# of non-frozen water atoms in the system"):
                    nwater = TokenizeLine(line, converters=[int])[0]
                    self.watoms = self._ReadAtoms(lines,
                                                  nwater,
                                                  includeCharge=True)
        except StopIteration:
            pass
        # . Close the file
        lines.close()
Example #14
0
    def _Parse(self):
        lines = open(self.inputfile)
        scan = []
        opt = []
        # . Assume the job is failed until finding a "Normal termination" statement
        jobOK = False
        try:
            while True:
                line = next(lines)
                # . Get the version and revision of Gaussian
                if line.startswith(" Gaussian"):
                    if line.count("Revision"):
                        tokens = TokenizeLine(
                            line, converters=[None, None, None, None])
                        self.version = tokens[1][:-1]
                        self.revision = tokens[3][:-1]

                # . Get the number of atoms and their coordinates
                elif line.count("Input orientation:") or line.count(
                        "Z-Matrix orientation:"):
                    for skip in range(4):
                        next(lines)
                    natoms = 0
                    atoms = []
                    while True:
                        line = next(lines)
                        if line.count("----"):
                            break
                        tokens = TokenizeLine(
                            line,
                            converters=[int, int, int, float, float, float])
                        atomicNumber, x, y, z = tokens[1], tokens[3], tokens[
                            4], tokens[5]
                        atom = Atom(symbol=atomicNumberToSymbol[atomicNumber],
                                    x=x,
                                    y=y,
                                    z=z,
                                    charge=0.)
                        atoms.append(atom)
                        natoms += 1
                    self.atoms = atoms

                # . Get the final energy (for semiempirical calculations)
                elif line.count("NIter="):
                    tokens = TokenizeLine(line,
                                          converters=[None, float, None, None])
                    self.Efinal = tokens[1] * HARTREE_TO_KCAL_MOL

                # . Get the final energy (for ab initio/DFT calculations)
                # SCF Done:  E(RB+HF-LYP) =  -882.208703983     A.U. after   28 cycles
                elif line.count("SCF Done"):
                    tokens = TokenizeLine(line,
                                          converters=[
                                              None, None, None, None, float,
                                              None, None, int, None
                                          ])
                    self.Efinal = tokens[4] * HARTREE_TO_KCAL_MOL

                # . Get the final, PCM-corrected energy (replace the regular energy)
                #
                # After PCM corrections, the SCF energy is  -2571.87944471     a.u.
                elif line.count("After PCM corrections, the SCF energy is"):
                    tokens = TokenizeLine(line,
                                          converters=([
                                              None,
                                          ] * 7 + [
                                              float,
                                          ]))
                    Efinal = tokens[-1] * HARTREE_TO_KCAL_MOL
                    if hasattr(self, "Efinal"):
                        self.PCMcorr = Efinal - self.Efinal
                    self.Efinal = Efinal

                # . Get the thermochemistry
                #
                #  Zero-point correction=                           0.381354 (Hartree/Particle)
                #  Thermal correction to Energy=                    0.400762
                #  Thermal correction to Enthalpy=                  0.401706
                #  Thermal correction to Gibbs Free Energy=         0.334577
                #  Sum of electronic and zero-point Energies=           -965.928309
                #  Sum of electronic and thermal Energies=              -965.908901
                #  Sum of electronic and thermal Enthalpies=            -965.907957
                #  Sum of electronic and thermal Free Energies=         -965.975086
                elif line.startswith(
                        " Sum of electronic and zero-point Energies"):
                    tokens = TokenizeLine(line,
                                          converters=[
                                              float,
                                          ],
                                          reverse=True)
                    thermoZPE = tokens[-1] * HARTREE_TO_KCAL_MOL
                elif line.startswith(
                        " Sum of electronic and thermal Energies"):
                    tokens = TokenizeLine(line,
                                          converters=[
                                              float,
                                          ],
                                          reverse=True)
                    thermoU = tokens[-1] * HARTREE_TO_KCAL_MOL
                elif line.startswith(
                        " Sum of electronic and thermal Enthalpies"):
                    tokens = TokenizeLine(line,
                                          converters=[
                                              float,
                                          ],
                                          reverse=True)
                    thermoH = tokens[-1] * HARTREE_TO_KCAL_MOL
                elif line.startswith(
                        " Sum of electronic and thermal Free Energies"):
                    tokens = TokenizeLine(line,
                                          converters=[
                                              float,
                                          ],
                                          reverse=True)
                    thermoG = tokens[-1] * HARTREE_TO_KCAL_MOL
                    thermo = Thermo(
                        Ezpe=thermoZPE,
                        U=thermoU,
                        H=thermoH,
                        G=thermoG,
                    )
                    self.thermo = thermo

                # . Get the self energy of the charges
                # . In g03, there is no "a.u." at the end
                # Self energy of the charges =      -252.7809376522 a.u.
                elif line.count("Self energy of the charges"):
                    tokens = TokenizeLine(line,
                                          converters=[None] * 6 + [float])
                    self.Echrg = tokens[6] * HARTREE_TO_KCAL_MOL

                # . Get ESP charges (can be Merz-Kollman or CHELPG)
                elif line.count("Charges from ESP fit"):
                    for i in range(2):
                        next(lines)
                    self.espcharges = []
                    for i in range(natoms):
                        tokens = TokenizeLine(next(lines),
                                              converters=[int, None, float])
                        charge = tokens[2]
                        self.espcharges.append(charge)

                # . Get Mulliken charges
                # . The second condition is for Gaussian 09
                elif line.startswith(
                        " Mulliken atomic charges:") or line.startswith(
                            " Mulliken charges:"):
                    next(lines)
                    self.charges = []
                    for i in range(natoms):
                        tokens = TokenizeLine(next(lines),
                                              converters=[int, None, float])
                        charge = tokens[2]
                        self.charges.append(charge)

                # . Get Mulliken charges summed into heavy atoms
                elif line.startswith(
                        " Mulliken charges with hydrogens summed into heavy atoms"
                ):
                    nheavy = 0
                    for atom in self.atoms:
                        if atom.symbol[0] != "H":
                            nheavy += 1
                    next(lines)
                    self.sumcharges = []
                    #while True:
                    for i in range(nheavy):
                        line = next(lines)
                        #if line.startswith (" Electronic spatial extent (au):"):
                        #    break
                        tokens = TokenizeLine(line,
                                              converters=[int, None, float])
                        charge = tokens[2]
                        self.sumcharges.append(charge)

                # . Get forces
                # . http://www.gaussian.com/g_tech/g_ur/k_force.htm
                # . Gaussian prints gradients, not forces, despite the misleading label "Forces" (?)
                # . There is not need to multiply the gradients by -1, since Molaris does it after reading the d.o file.
                # . In Plotnikov's script, there was no multiplication by -1.
                # elif line.count ("***** Axes restored to original set *****"):
                #     for skip in range (4):
                #         next (lines)
                elif line.count(
                        "Center     Atomic                   Forces (Hartrees/Bohr)"
                ):
                    for i in range(2):
                        next(lines)
                    self.forces = []
                    for i in range(natoms):
                        tokens = TokenizeLine(
                            next(lines),
                            converters=[int, int, float, float, float])
                        force = Force(
                            x=tokens[2] * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                            y=tokens[3] * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                            z=tokens[4] * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM)
                        self.forces.append(force)

                # . Read coordinates and values of point charges
                # Point Charges:
                # XYZ=    2.0006    1.0001    0.0000 Q=    0.1110 A=    0.0000 R=    0.0000 C=    0.0000
                # XYZ=    2.0009    2.0911    0.0000 Q=   -0.3675 A=    0.0000 R=    0.0000 C=    0.0000
                # XYZ=    1.4863    2.4537    0.8897 Q=    0.1110 A=    0.0000 R=    0.0000 C=    0.0000
                #  (...)
                # Sum of input charges=            0.000000
                elif line.startswith(" Point Charges:"):
                    points = []
                    line = next(lines)
                    while line.startswith(" XYZ="):
                        tokens = TokenizeLine(line,
                                              converters=[
                                                  None, float, float, float,
                                                  None, float
                                              ])
                        (x, y, z), charge = tokens[1:4], tokens[5]
                        point = (x, y, z, charge)
                        points.append(point)
                        line = next(lines)

                # . Read in positions of points in space, other than nuclei, where electrostatic
                # . properties are evaluated.
                #
                # **********************************************************************
                #
                #            Electrostatic Properties Using The SCF Density
                #
                # **********************************************************************
                #
                #       Atomic Center    1 is at   3.665580  6.467202 12.974383
                #       Atomic Center    2 is at   4.909670  6.386763 13.616169
                #   (...)
                #      Read-in Center 2400 is at   5.504554 14.162232 26.811879
                #      Read-in Center 2401 is at   5.086579 15.682876 27.049785
                elif line.count(
                        "Electrostatic Properties Using The SCF Density"):
                    positions = []
                    for i in range(3):
                        next(lines)
                    line = next(lines)
                    while (line.count("Atomic Center")
                           or line.count("Read-in Center")):
                        # . Fixed format!
                        x = float(line[32:42])
                        y = float(line[42:52])
                        z = float(line[52:62])
                        position = (x, y, z)
                        if line.count("Read-in Center"):
                            positions.append(position)
                        line = next(lines)

                #              Electrostatic Properties (Atomic Units)
                #
                # -----------------------------------------------------------------
                #    Center     Electric         -------- Electric Field --------
                #               Potential          X             Y             Z
                # -----------------------------------------------------------------
                #    1 Atom    -14.711204     -0.022648      0.000626     -0.009472
                #    2 Atom    -22.331530      0.084739      0.046163     -0.012921
                # (...)
                elif line.count("Electrostatic Properties (Atomic Units)"):
                    pointsElectric = []
                    atomsElectric = []
                    for i in range(6):
                        line = next(lines)
                    while not line.count("----"):
                        onNucleus = True if line.count("Atom") else False
                        line = line.replace("Atom", "")
                        tokens = TokenizeLine(
                            line, converters=[int, float, float, float, float])
                        if len(tokens) != 5:
                            # . Electric field components may not always be there. In such cases, set all to zero.
                            potential, (ex, ey, ez) = tokens[1], (0., 0., 0.)
                        else:
                            potential, (ex, ey, ez) = tokens[1], tokens[2:]
                        field = (ex, ey, ez, potential)
                        if onNucleus:
                            # . Electrostatic potential and field on a nucleus
                            atomsElectric.append(field)
                        else:
                            # . Electrostatic potential and field on a point charge
                            pointsElectric.append(field)
                        line = next(lines)
                    self.atomsElectric = atomsElectric

                    # . Save point charges
                    try:
                        pointCharges = []
                        for (x, y, z, charge), (ex, ey, ez, potential) in zip(
                                points, pointsElectric):
                            pc = PointCharge(
                                x=x,
                                y=y,
                                z=z,
                                charge=charge,
                                # . Convert from Eh/bohr to kcal/(mol*A)
                                ex=ex * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                                ey=ey * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                                ez=ez * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                                # . Convert from Eh/e to kcal/(mol*e)
                                potential=potential * HARTREE_TO_KCAL_MOL,
                            )
                            pointCharges.append(pc)
                        self.pointCharges = pointCharges
                    except:
                        pass

                    # . Save electric (=electrostatic) properties
                    properties = []
                    for (x, y, z), (ex, ey, ez,
                                    potential) in zip(positions,
                                                      pointsElectric):
                        prop = ElectricProperty(
                            x=x,
                            y=y,
                            z=z,
                            # . Convert from Eh/bohr to kcal/(mol*A)
                            ex=ex * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                            ey=ey * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                            ez=ez * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                            # . Convert from Eh/e to kcal/(mol*e)
                            potential=potential * HARTREE_TO_KCAL_MOL,
                        )
                        properties.append(prop)
                    self.properties = properties

                # . Get atoms from the input file
                #  Symbolic Z-matrix:
                #  Charge =  1 Multiplicity = 1
                #  LI                   -0.112     0.       -0.104
                #  XX                   -0.796    -1.788    -0.682
                #  O                     0.093     0.        1.723
                #   (...)
                elif line.count("Symbolic Z-matrix"):
                    next(lines)
                    atomsInput = []
                    while True:
                        tokens = TokenizeLine(
                            next(lines),
                            converters=[None, float, float, float])
                        if not tokens:
                            break
                        symbol, x, y, z = tokens
                        atom = Atom(
                            symbol=symbol,
                            x=x,
                            y=y,
                            z=z,
                            charge=0.,
                        )
                        atomsInput.append(atom)
                    self.atomsInput = atomsInput

                # . Get job time in seconds
                elif line.count("Job cpu time"):
                    tokens = TokenizeLine(line,
                                          converters=[
                                              None, None, None, int, None, int,
                                              None, int, None, float, None
                                          ])
                    days, hours, minutes, seconds = tokens[3], tokens[
                        5], tokens[7], tokens[9]
                    self.jobtime = (days * 24 * 3600) + (hours * 3600) + (
                        minutes * 60) + seconds
                    # . Quit here, since composite jobs are not supported (?)
                    # break

                # . Check for a failed job
                elif line.startswith(" Normal termination of Gaussian"):
                    jobOK = True

                # . Determine if we have reached the end of an IRC step
                elif line.count("-- Optimized point #"):
                    newStep = ScanStep(Efinal=self.Efinal,
                                       atoms=self.atoms[:],
                                       forces=self.forces[:],
                                       charges=self.charges[:],
                                       espcharges=[])  # <--FIX ME
                    scan.append(newStep)

                # . Determine if we have reached the end of a geometry optimization step
                elif line.startswith(" Berny optimization."):
                    if hasattr(self, "Efinal"):
                        optStep = ScanStep(Efinal=self.Efinal,
                                           atoms=self.atoms[:],
                                           forces=self.forces[:],
                                           charges=self.charges[:],
                                           espcharges=[])  # <--FIX ME
                        opt.append(optStep)
        except StopIteration:
            pass
        # . Close the file
        lines.close()
        # . Check for a failed job
        if not jobOK:
            raise exceptions.StandardError("Job %s did not end normally." %
                                           self.inputfile)

        # . Does the job involve a scan (IRC or PES)?
        if scan: self.scan = scan
        # . Does the job involve a geometry optimization?
        if opt: self.opt = opt
Example #15
0
    def _Parse(self, logging=False):
        # . fepSteps are the FEP steps (usually 11), each consisting of many MD steps (usually 500)
        fepSteps = []
        mdSteps = []
        currentMDStep = None
        residues = []
        lines = open(self.filename)
        _fileOK = False
        try:
            while True:
                line = lines.next()

                if line.startswith(
                        "  NORMAL TERMINATION OF MOLARIS"
                ) or line.startswith(
                        " Molaris has completed this run successfully without any warning"
                ):
                    self._fileOK = True

                #  Energies for the system at step          0:
                #  ------------------------------------------------------------------------
                elif line.startswith(" Energies for the system at step"):
                    currentMDStep = MDStep()
                    while True:
                        line = lines.next()

                        #  protein - ebond    :      2.57 ethet    :      4.29
                        #            ephi     :      0.00 eitor    :      0.00
                        #            evdw     :     -0.24 emumu    :      0.00
                        #            ehb_pp   :      0.00
                        #
                        if line.startswith(" protein"):
                            toka = line.split()
                            tokb = lines.next().split()
                            tokc = lines.next().split()
                            tokd = lines.next().split()
                            protein = Protein(
                                ebond=float(toka[4]),
                                ethet=float(toka[7]),
                                ephi=float(tokb[2]),
                                eitor=float(tokb[5]),
                                evdw=float(tokc[2]),
                                emumu=float(tokc[5]),
                                ehb_pp=float(tokd[2]),
                            )
                            currentMDStep.protein = protein

                        #  water   - ebond    :    674.31 ethet    :    414.66
                        #            evdw     :    949.15 emumu    :  -8517.96
                        #            ehb_ww   :      0.00
                        #
                        elif line.startswith(" water"):
                            pass
                        #  pro-wat - evdw     :     -5.33 emumu    :      0.00
                        #            ehb_pw   :      0.00
                        #
                        elif line.startswith(" pro-wat"):
                            pass
                        #  long    - elong    :     89.62
                        #
                        elif line.startswith(" long"):
                            pass
                        #  ac      - evd_ac   :      0.00 emumuac  :      0.00
                        #            evd_acw  :      0.00 emumuacw :      0.00
                        #            ehb_ac   :      0.00
                        #            ehb_acw  :      0.00
                        #
                        elif line.startswith(" ac"):
                            pass
                        #  evb     - ebond    :      0.00 ethet    :      0.00 ephi     :      0.00
                        #            evdw     :     11.93 emumu    :      0.00 eoff     :      0.00
                        #            egashift :      0.00 eindq    :      0.00 ebulk    :    -99.57
                        #
                        elif line.startswith(" evb"):
                            toka = line.split()
                            tokb = lines.next().split()
                            tokc = lines.next().split()
                            evb = Evb(
                                ebond=float(toka[4]),
                                ethet=float(toka[7]),
                                ephi=float(toka[10]),
                                evdw=float(tokb[2]),
                                emumu=float(tokb[5]),
                                eoff=float(tokb[8]),
                                egashift=float(tokc[2]),
                                eindq=float(tokc[5]),
                                ebulk=float(tokc[8]),
                            )
                            currentMDStep.evb = evb

                        #  induce  - eindp    :      0.00 eindw    :      0.00
                        #
                        elif line.startswith(" induce"):
                            pass
                        #  const.  - ewatc    :     27.05 eproc    :      1.45 edistc   :     45.08
                        #
                        elif line.startswith(" const."):
                            pass
                        #  langevin- elgvn    :    -33.50 evdw_lgv :     81.45 eborn    :    -33.07
                        #
                        elif line.startswith(" langevin"):
                            pass
                        #  classic - epot     :  -6518.24 equantum :   -199.94
                        #
# FIXME
#                        elif line.startswith ( " classic"  ):
#                            toka     = line.split (":")
#                            tokb     = toka[1].split ()
#                            tokc     = toka[2].split ()
#                            energies = Classic (
#                                    classic = float ( tokb[0] ) ,
#                                    quantum = float ( tokc[0] ) ,)
#                            currentMDStep.classic = energies

#  system  - epot     :  -6718.18 ekin     :   2140.90 etot     :  -4577.28
#  _____________________________________________________________________________
                        elif line.startswith(" system"):
                            toka = line.split()
                            system = System(
                                epot=float(toka[4]),
                                ekin=float(toka[7]),
                                etot=float(toka[10]),
                            )
                            currentMDStep.system = system
                            break
                    mdSteps.append(currentMDStep)
                    if logging:
                        nsteps = len(mdSteps)
                        print("# Read energies for %d MD step%s." %
                              (nsteps, "" if nsteps < 2 else "s"))

                elif line.startswith(
                        " Average energies for the system at the step"):
                    fepSteps.append(mdSteps)
                    mdSteps = []
                    if logging:
                        nfep = len(fepSteps)
                        print("# Read FEP step %d." % nfep)

                #  EVB Total Energies -- Hamiltonian Breakdown
                #
                #   State    Total    Egas    Bond   Angle  Torsion   Eqmu   Eind     Vdw    Bulk
                #  -------  ------   ------  -----  ------- -------  ------ ------  ------- ------
                #  1(0.00) -1543.0     0.0    18.7    19.2     2.5  -1504.6    0.0    -30.2  -48.6
                #  2(1.00) -1543.0     0.0    18.7    19.2     2.5  -1504.6    0.0    -30.2  -48.6
                # (...)
                elif line.count("EVB Total Energies -- Hamiltonian Breakdown"):
                    for i in range(4):
                        line = next(lines)
                    # . Read energies of state I
                    tokens = TokenizeLine(line,
                                          converters=([
                                              None,
                                          ] + [
                                              float,
                                          ] * 9))
                    components = EVBComponents(
                        density=float(tokens[0][2:6]),
                        Etotal=tokens[1],
                        Egas=tokens[2],
                        Ebond=tokens[3],
                        Eangle=tokens[4],
                        Etorsion=tokens[5],
                        Eqmu=tokens[6],
                        Eind=tokens[7],
                        Evdw=tokens[8],
                        Ebulk=tokens[9],
                    )
                    if not hasattr(self, "evbComponentsI"):
                        self.evbComponentsI = []
                    self.evbComponentsI.append(components)

                    # . Read energies of state II
                    line = next(lines)
                    tokens = TokenizeLine(line,
                                          converters=([
                                              None,
                                          ] + [
                                              float,
                                          ] * 9))
                    components = EVBComponents(
                        density=float(tokens[0][2:6]),
                        Etotal=tokens[1],
                        Egas=tokens[2],
                        Ebond=tokens[3],
                        Eangle=tokens[4],
                        Etorsion=tokens[5],
                        Eqmu=tokens[6],
                        Eind=tokens[7],
                        Evdw=tokens[8],
                        Ebulk=tokens[9],
                    )
                    if not hasattr(self, "evbComponentsII"):
                        self.evbComponentsII = []
                    self.evbComponentsII.append(components)

                # Now running quantum program ..., with the script on evb state:  2
                #
                # (...)
                #
                #  E_evb(eminus)=     -1016.25
                #  E_classical  = E_tot-E_evb-evdw_12 =     -6235.77
                #  Equantum =  -1595163.80
                #  e_qmmm = E_tot-E_evb+Equantum =  -1601411.16
                elif line.startswith(" Now running quantum program ..."):
                    tokens = TokenizeLine(line,
                                          converters=[
                                              int,
                                          ],
                                          reverse=True)
                    state = tokens[0]
                    while True:
                        line = next(lines)
                        if line.startswith(" E_evb(eminus)="):
                            tokens = TokenizeLine(line,
                                                  converters=[
                                                      float,
                                                  ],
                                                  reverse=True)
                            Eevb = tokens[0]
                        elif line.startswith(" E_classical"):
                            tokens = TokenizeLine(line,
                                                  converters=[
                                                      float,
                                                  ],
                                                  reverse=True)
                            Eclassical = tokens[0]
                        elif line.startswith(" Equantum"):
                            tokens = TokenizeLine(line,
                                                  converters=[
                                                      float,
                                                  ],
                                                  reverse=True)
                            Equantum = tokens[0]
                        elif line.startswith(" e_qmmm"):
                            tokens = TokenizeLine(line,
                                                  converters=[
                                                      float,
                                                  ],
                                                  reverse=True)
                            Eqmmm = tokens[0]
                            break
                    components = QMMMComponents(
                        Eevb=Eevb,
                        Eqmmm=Eqmmm,
                        Equantum=Equantum,
                        Eclassical=Eclassical,
                    )
                    if state == 1:
                        if not hasattr(self, "qmmmComponentsI"):
                            self.qmmmComponentsI = []
                        self.qmmmComponentsI.append(components)
                    else:
                        if not hasattr(self, "qmmmComponentsII"):
                            self.qmmmComponentsII = []
                        self.qmmmComponentsII.append(components)

                # atom list for residue:     2_WAT,    # of atoms in this residue:   3
                #
                # number  name  type      x          y          z      charge      atoms bonded(name)      atoms bonded(number)
                # ------  ----  ----   -------    -------    -------   ------   ------------------------ ------------------------
                elif line.count("atom list for residue"):
                    tokens = line.split()
                    residue = tokens[4]
                    resSerial, resLabel = residue.split("_")
                    resSerial = int(resSerial)
                    resLabel = resLabel.replace(",", "")
                    # . Skip a few lines
                    for i in range(3):
                        next(lines)
                    # . Read atoms
                    #    2    OH     O2     -0.087     -0.022      2.081   -0.800   H1   H2                      3     4
                    #    3    H1     H2     -0.139     -0.807      2.652    0.400   OH                           2
                    #    4    H2     H2     -0.056      0.751      2.671    0.400   OH                           2
                    #
                    # Total charge of this residue:     0.000
                    atoms = []
                    while True:
                        line = next(lines)
                        if line.count("Total charge"):
                            break
                        tokens = line.split()
                        if len(tokens) > 0:
                            if tokens[0].isdigit():
                                (atomSerial, atomLabel,
                                 atomType), atomCharge = tokens[:3], tokens[6]
                                atomSerial = int(atomSerial)
                                atomCharge = float(atomCharge)
                                x, y, z = map(float, tokens[3:6])
                                # . Read atoms the current atom is connected to
                                bondAtoms = tokens[7:]
                                bondLabels = []
                                bondSerials = []
                                for atom in bondAtoms:
                                    if atom.isdigit():
                                        bondSerials.append(int(atom))
                                    else:
                                        bondLabels.append(atom)
                                # . Prepare bonded atoms
                                bonds = []
                                for serial, label in zip(
                                        bondSerials, bondLabels):
                                    bondedAtom = (serial, label)
                                    bonds.append(bondedAtom)
                                # . Add a new atom
                                atom = Atom(
                                    label=atomLabel,
                                    atype=atomType,
                                    serial=atomSerial,
                                    charge=atomCharge,
                                    bonds=bonds,
                                    x=x,
                                    y=y,
                                    z=z,
                                )
                                atoms.append(atom)
                    # . Add a new residue
                    residue = Residue(
                        serial=resSerial,
                        label=resLabel,
                        atoms=atoms,
                    )
                    residues.append(residue)
                    if logging:
                        natoms = len(atoms)
                        print("# Found residue %s-%d with %d atom%s." %
                              (resLabel, resSerial, natoms,
                               "" if natoms < 2 else "s"))

                # Classical forces which are not calculated in qm:
                #   evb_atom     fx        fy        fz
                #         6     2.792   -10.205     9.635
                #         5    -7.012    14.479   -21.646
                # (...)
                elif line.count(
                        "Classical forces which are not calculated in qm"):
                    for i in range(2):
                        line = next(lines)
                    forcesClassical = []
                    while line != "\n":
                        tokens = TokenizeLine(
                            line, converters=[int, float, float, float])
                        evbSerial, fx, fy, fz = tokens
                        force = (evbSerial, fx, fy, fz)
                        forcesClassical.append(force)
                        line = next(lines)
                    self.forcesClassical = forcesClassical
                    if logging:
                        nforces = len(forcesClassical)
                        print("# Read classical forces for %d atoms." %
                              nforces)

                #  Forces(classical+qm) and Charges will be used for dynamics:
                #  EVB_atom	 x         y         z        fx        fy       fz      crg
                #         6     3.666     6.485    12.973    -8.915    -1.595    -4.922   0.272
                #         5     4.872     6.423    13.671     1.443     1.123     0.273  -0.750
                # (...)
                elif line.count(
                        "Forces(classical+qm) and Charges will be used for dynamics:"
                ):
                    for i in range(2):
                        line = next(lines)
                    forcesQMMM = []
                    while line != "\n":
                        tokens = TokenizeLine(line,
                                              converters=[
                                                  int, float, float, float,
                                                  float, float, float, float
                                              ])
                        evbSerial, x, y, z, fx, fy, fz, charge = tokens
                        force = (evbSerial, fx, fy, fz)
                        forcesQMMM.append(force)
                        line = next(lines)
                    self.forcesQMMM = forcesQMMM
                    if logging:
                        nforces = len(forcesQMMM)
                        print("# Read QM/MM forces for %d atoms." % nforces)

                # . Skip reading a table that has no use
                #
                #  CALCULATING EVB ENERGY FOR QMMM FEP:
                #  Classical force for user-specified atoms:
                #  atom     fx        fy        fz
                #     1     0.736     0.000     6.360
                elif line.count("CALCULATING EVB ENERGY FOR QMMM FEP"):
                    next(lines)

                # Classical force for user-specified atoms:
                # atom#    fx        fy        fz
                #    1     0.859     0.000     7.456
                #    2    -5.120     0.000   -45.629
                #   (...)
                elif line.count("Classical force for user-specified atoms"):
                    next(lines)
                    line = next(lines)
                    forcesClassicalCustom = []
                    while line != "\n":
                        tokens = TokenizeLine(
                            line, converters=[int, float, float, float])
                        serial, fx, fy, fz = tokens
                        force = (serial, fx, fy, fz)
                        forcesClassicalCustom.append(force)
                        line = next(lines)
                    if hasattr(self, "forcesClassical"):
                        self.forcesClassical.extend(forcesClassicalCustom)
                    if logging:
                        nforces = len(forcesClassicalCustom)
                        print(
                            "# Read classical forces for %d user-specified atoms."
                            % nforces)

                # Forces(classical+qm) for user-specified atoms:
                #      atom     x         y         z        fx        fy        fz      crg
                #    1    -0.612     0.000     2.392     0.859     0.000     7.456     1.000
                #    2    -0.612     0.000     2.392    -4.938     0.000   -44.075    -0.778
                #   (...)
                elif line.count(
                        "Forces(classical+qm) for user-specified atoms"):
                    next(lines)
                    line = next(lines)
                    forcesQMMMCustom = []
                    while line != "\n":
                        tokens = TokenizeLine(line,
                                              converters=[
                                                  int, float, float, float,
                                                  float, float, float, float
                                              ])
                        serial, x, y, z, fx, fy, fz, charge = tokens
                        force = (serial, fx, fy, fz)
                        forcesQMMMCustom.append(force)
                        line = next(lines)
                    if hasattr(self, "forcesQMMM"):
                        self.forcesQMMM.extend(forcesQMMMCustom)
                    if logging:
                        nforces = len(forcesQMMMCustom)
                        print(
                            "# Read QM/MM forces for %d user-specified atoms."
                            % nforces)
        except StopIteration:
            pass
        # . Close the file
        lines.close()
        # . Finish up
        if fepSteps != []:
            self.fepSteps = fepSteps
        if currentMDStep != None:
            self.currentMDStep = currentMDStep
        if residues != []:
            self.residues = residues
Example #16
0
    def _Parse(self):
        lines = open(self.filename)
        fileOK = False
        try:
            while True:
                line = next(lines)
                if line.startswith("  NORMAL TERMINATION OF MOLARIS"):
                    fileOK = True
                elif line.startswith(" Energies for the system at step"):
                    while True:
                        line = next(lines)
                        if line.startswith(
                                " EVB Total Energies -- Hamiltonian Breakdown"
                        ):
                            # . State I
                            for i in range(4):
                                line = next(lines)
                            tokens = TokenizeLine(line,
                                                  converters=([
                                                      None,
                                                  ] + [
                                                      float,
                                                  ] * 9))
                            Eevb = tokens[1]
                            if not hasattr(self, "Eevba"):
                                self.Eevba = []
                            self.Eevba.append(Eevb)
                            # . State II
                            line = next(lines)
                            tokens = TokenizeLine(line,
                                                  converters=([
                                                      None,
                                                  ] + [
                                                      float,
                                                  ] * 9))
                            Eevb = tokens[1]
                            if not hasattr(self, "Eevbb"):
                                self.Eevbb = []
                            self.Eevbb.append(Eevb)

                        elif line.startswith(
                                " Now running quantum program ..."):
                            tokens = TokenizeLine(line,
                                                  converters=[
                                                      int,
                                                  ],
                                                  reverse=True)
                            state = tokens[0]
                            while True:
                                line = next(lines)
                                if line.startswith(" E_evb(eminus)="):
                                    pass
                                elif line.startswith(" E_classical"):
                                    pass
                                elif line.startswith(" Equantum"):
                                    pass
                                elif line.startswith(" e_qmmm"):
                                    tokens = TokenizeLine(line,
                                                          converters=[
                                                              float,
                                                          ],
                                                          reverse=True)
                                    Eqmmm = tokens[0]
                                    break
                            if state < 2:
                                if not hasattr(self, "Eqmmma"):
                                    self.Eqmmma = []
                                self.Eqmmma.append(Eqmmm)
                            else:
                                if not hasattr(self, "Eqmmmb"):
                                    self.Eqmmmb = []
                                self.Eqmmmb.append(Eqmmm)
                            # . Exit MD step
                            break

                        elif line.startswith(" Average energies"):
                            # . Last step does not report QMMM energies (bug in Molaris?)
                            break
        except StopIteration:
            pass
        # . Finalize
        lines.close()
        if not fileOK:
            raise exceptions.StandardError("Abnormal termination of file %s" %
                                           self.filename)
    def _Parse(self):
        lines = open(self.inputfile)
        try:
            while True:
                line = next(lines)
                # . Get gradients
                #                         ----------------------
                #                         GRADIENT OF THE ENERGY
                #                         ----------------------
                #
                # UNITS ARE HARTREE/BOHR    E'X               E'Y               E'Z
                #    1 P                0.000961748       0.034900593      -0.184607470
                #    2 O               -0.056832094       0.021746718      -0.036701933
                # (...)
                if line.count("GRADIENT OF THE ENERGY"):
                    for i in range(3):
                        line = next(lines)
                    # . There are two sections that start from "GRADIENT OF THE ENERGY", we are interested in the second one
                    if line.count("UNITS ARE HARTREE/BOHR"):
                        self.forces = []
                        while True:
                            tokens = TokenizeLine(
                                next(lines),
                                converters=[int, None, float, float, float])
                            if not tokens:
                                break
                            force = Force(
                                x=fx * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                                y=fy * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                                z=fz * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM,
                            )
                            self.forces.append(force)

                # . Get Mulliken charges
                #          TOTAL MULLIKEN AND LOWDIN ATOMIC POPULATIONS
                #       ATOM         MULL.POP.    CHARGE          LOW.POP.     CHARGE
                #    1 P            14.103960    0.896040        14.020001    0.979999
                #    2 O             8.406488   -0.406488         8.409966   -0.409966
                # (...)
                elif line.count(
                        "TOTAL MULLIKEN AND LOWDIN ATOMIC POPULATIONS"):
                    next(lines)
                    self.charges = []
                    while True:
                        tokens = TokenizeLine(
                            next(lines),
                            converters=[int, None, float, float, float, float])
                        if not tokens:
                            break
                        mulliken = tokens[3]
                        self.charges.append(mulliken)

                # . Get the final energy
                #                       TOTAL ENERGY =   -2179.8517336269
                elif line.count("TOTAL ENERGY ="):
                    tokens = TokenizeLine(line,
                                          converters=[None, None, None, float])
                    self.Efinal = tokens[3] * HARTREE_TO_KCAL_MOL

                # . Get atomic coordinates
                # ATOM      ATOMIC                      COORDINATES (BOHR)
                #           CHARGE         X                   Y                   Z
                # P          15.0     7.9538566823        2.4755410439       30.4000219645
                # O           8.0    10.6145908730        2.1127136543       31.2258322211
                # (...)
                elif line.count("COORDINATES (BOHR)"):
                    next(lines)
                    self.atoms = []
                    while True:
                        tokens = TokenizeLine(
                            next(lines),
                            converters=[None, float, float, float, float])
                        if not tokens:
                            break
                        atom = Atom(symbol=tokens[0],
                                    x=tokens[2] * BOHR_TO_ANGSTROM,
                                    y=tokens[3] * BOHR_TO_ANGSTROM,
                                    z=tokens[4] * BOHR_TO_ANGSTROM,
                                    charge=0.)
                        self.atoms.append(atom)

                # . Get timing information
                # TOTAL WALL CLOCK TIME=      102.7 SECONDS, CPU UTILIZATION IS  99.28%
                elif line.count("TOTAL WALL CLOCK TIME"):
                    tokens = TokenizeLine(
                        line, converters=[None, None, None, None, float])
                    seconds = tokens[-1]
                    hours, minutes, seconds = str(
                        datetime.timedelta(seconds=seconds)).split(":")
                    self.timings = {
                        "days": 0,
                        "hours": hours,
                        "minutes": minutes,
                        "seconds": seconds
                    }  # . FIXME

                # . Get version number
                #          *         GAMESS VERSION =  5 DEC 2014 (R1)          *
                elif line.count("GAMESS VERSION"):
                    tokens = TokenizeLine(line, converters=[None] * 9)
                    version = " ".join(
                        (tokens[4], tokens[5], tokens[6], tokens[7]))
                    self.version = version
        except StopIteration:
            pass
        # . Close the file
        lines.close()
Example #18
0
 def _Parse(self):
     data = open(self.filename)
     steps = []
     step = []
     try:
         while True:
             line = data.next()
             if line.count("trajec"):
                 # . Found a new step
                 tokens = TokenizeLine(line, converters=[int, None])
                 trajStep = tokens[0]
                 if step:
                     # . Save the previous step
                     steps.append(step)
                     step = []
             elif line.count("atom"):
                 tokens = TokenizeLine(line,
                                       converters=[None, None, int, float])
                 serial, charge = tokens[2], tokens[3]
                 # . Read forces
                 line = data.next()
                 tokens = TokenizeLine(
                     line, converters=[None, float, float, float])
                 fx, fy, fz = tokens[1:]
                 # . Read velocities
                 line = data.next()
                 tokens = TokenizeLine(
                     line, converters=[None, float, float, float])
                 vx, vy, vz = tokens[1:]
                 # . Read coordinates
                 line = data.next()
                 tokens = TokenizeLine(
                     line, converters=[None, float, float, float])
                 x, y, z = tokens[1:]
                 # . Calculate the force    magnitude
                 fm = math.sqrt(fx * fx + fy * fy + fz * fz)
                 # . Calculate the velocity magnitude
                 vm = math.sqrt(vx * vx + vy * vy + vz * vz)
                 # . Create an atom and add it to the current step
                 atom = FVXAtom(serial=serial,
                                charge=charge,
                                fx=fx,
                                fy=fy,
                                fz=fz,
                                vx=vx,
                                vy=vy,
                                vz=vz,
                                x=x,
                                y=y,
                                z=z,
                                fm=fm,
                                vm=vm)
                 step.append(atom)
     except StopIteration:
         pass
     # . Close the file
     data.close()
     # . Are there any steps left?
     if step:
         steps.append(step)
     self.steps = steps
    def _Parse(self):
        lines = open(self.inputfile)
        try:
            while True:
                line = next(lines)
                if line.startswith("FINAL ENERGY:"):
                    tokens = TokenizeLine(line,
                                          converters=[None, None, float, None])
                    self.Efinal = tokens[2] * HARTREE_TO_KCAL_MOL

                elif line.startswith("Scratch directory:"):
                    tokens = TokenizeLine(line, converters=[None, None, None])
                    self.scratchFolder = tokens[2]

                elif line.startswith("Total atoms:"):
                    tokens = TokenizeLine(line, converters=[None, None, int])
                    natoms = tokens[2]
                    # if (natoms != len (tempatoms)):
                    #     pass

                # ****** QM coordinates ******
                # C        -0.0178447840         0.0103903440        -0.0015978260
                # H        -0.0463346130         0.0459578690         1.0997854660
                # H         1.0186858510         0.0532897140        -0.3692509610
                # H        -0.5543873770        -0.8695391090        -0.3892902580
                # Cl        -0.8673247020         1.4796754130        -0.6190902640
                # Cl         1.5376616510        -2.4337214350         0.8399845050
                #
                elif line.startswith("****** QM coordinates ******"):
                    tempatoms = []
                    while True:
                        line = next(lines)
                        if (line.strip() == ""):
                            break
                        tokens = TokenizeLine(
                            line, converters=[None, float, float, float])
                        atom = Atom(symbol=tokens[0],
                                    x=tokens[1],
                                    y=tokens[2],
                                    z=tokens[3],
                                    charge=0.0)
                        tempatoms.append(atom)

                # ESP unrestraint charges:
                # Atom          X          Y          Z     Charge   Exposure
                # -----------------------------------------------------------
                #    C  -0.033722   0.019635  -0.003019  -0.161628     0.0529
                #    H  -0.087560   0.086848   2.078293   0.135770     0.5000
                #    H   1.925037   0.100703  -0.697783   0.150080     0.4130
                #    H  -1.047640  -1.643191  -0.735652   0.144291     0.4348
                #   Cl  -1.639006   2.796181  -1.169911  -0.328851     0.8444
                #   Cl   2.905759  -4.599067   1.587341  -0.939662     0.9270
                # -----------------------------------------------------------
                elif line.startswith("ESP unrestraint charges:"):
                    next(lines)
                    next(lines)
                    self.espcharges = []
                    while True:
                        line = next(lines)
                        if line.startswith("----"):
                            break
                        tokens = TokenizeLine(line,
                                              converters=[
                                                  None, float, float, float,
                                                  float, float
                                              ])
                        (symbol, charge) = (tokens[0], tokens[4])
                        self.espcharges.append(charge)

                # Gradient units are Hartree/Bohr
                # ---------------------------------------------------
                #         dE/dX            dE/dY            dE/dZ
                #    -0.0094514443     0.0141415195    -0.0068751376
                #    -0.0018028819     0.0035487049     0.0113054990
                #     0.0100877721     0.0051162387    -0.0050948764
                #    -0.0088062409    -0.0065296736    -0.0054152317
                #     0.0115697382    -0.0189485242     0.0072745597
                #    -0.0015969432     0.0026717342    -0.0011948132
                # ---------------------------------------------------
                elif line.startswith("Gradient units are Hartree/Bohr"):
                    next(lines)
                    next(lines)
                    self.forces = []
                    while True:
                        line = next(lines)
                        if (line.startswith("----") or line.strip() == ""):
                            break
                        tokens = TokenizeLine(line,
                                              converters=[float, float, float])
                        (fx, fy, fz) = tokens
                        force = Force(x=(fx * GRADIENT_TO_FORCE *
                                         HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM),
                                      y=(fy * GRADIENT_TO_FORCE *
                                         HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM),
                                      z=(fz * GRADIENT_TO_FORCE *
                                         HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM))
                        self.forces.append(force)

                # . Get job time in seconds
                elif line.count("Total processing time:"):
                    tokens = TokenizeLine(
                        line, converters=[None, None, None, float, None])
                    self.jobtime = tokens[3]

        except exceptions.StopIteration:
            pass
        lines.close()

        if (self.deep):
            # . Deep parsing (aka parse files in the scratch folder)
            if hasattr(self, "scratchFolder"):

                # . Collect Mulliken charges
                lines = open(
                    os.path.join(self.scratchFolder, "charge_mull.xls"))
                self.charges = []
                for i in range(natoms):
                    line = next(lines)
                    tokens = TokenizeLine(line, converters=[int, None, float])
                    self.charges.append(tokens[2])
                lines.close()

                # . Collect coordinates
                fileGeometry = os.path.join(self.scratchFolder, "xyz.xyz")
                if (os.path.exists(fileGeometry)):
                    lines = open(fileGeometry)
                    next(lines)
                    next(lines)
                    self.atoms = []
                    for i in range(natoms):
                        line = next(lines)
                        tokens = TokenizeLine(
                            line, converters=[None, float, float, float])
                        atom = Atom(symbol=tokens[0],
                                    x=tokens[1],
                                    y=tokens[2],
                                    z=tokens[3],
                                    charge=self.charges[i])
                        self.atoms.append(atom)
                    lines.close()
Example #20
0
 def _ParseCHARMM(self, cutType, logging, verbose):
     data = open(self.filename)
     if logging:
         print("# . %s> Parsing file \"%s\"" %
               (_MODULE_LABEL, self.filename))
     # . Initialize
     bonds = []
     group = []
     groups = []
     internal = []
     components = []
     try:
         while True:
             line = self._GetCleanLine(data)
             #  RESI ASP         -1.00
             #  GROUP
             #  ATOM N    NH1    -0.47
             #  ATOM H    H       0.31
             #  ATOM CA   CT1     0.07
             #  ATOM HA   HB      0.09
             #  GROUP
             #  ATOM CB   CT2    -0.28
             #   (...)
             #  BOND CB CA  CG CB  OD2 CG
             #   (...)
             #  DOUBLE  O   C   CG  OD1
             #
             # . Treat patches as components
             if line[:4] in (
                     "RESI",
                     "PRES",
             ):
                 if group:
                     groups.append(group)
                     # . Create a temporary component
                     component = (componentLabel, componentCharge, groups,
                                  bonds, internal)
                     components.append(component)
                 # . Component begins
                 tokens = TokenizeLine(line, converters=[None, None, float])
                 (componentLabel, componentCharge) = tokens[1:]
                 # . Reinitialize
                 bonds = []
                 group = []
                 groups = []
                 internal = []
             elif line.startswith("GROUP"):
                 if group:
                     groups.append(group)
                     group = []
             elif line.startswith("ATOM"):
                 tokens = TokenizeLine(line,
                                       converters=[None, None, None, float])
                 newAtom = AminoAtom(
                     # . Molaris only uses 2-character atom types
                     atomType=tokens[2][:2] if cutType else tokens[2],
                     atomLabel=tokens[1],
                     atomCharge=tokens[3],
                 )
                 group.append(newAtom)
             elif line.startswith("BOND") or line.startswith("DOUBLE"):
                 tokens = line.split()
                 labels = tokens[1:]
                 nlabels = len(labels)
                 if (nlabels % 2) != 0:
                     raise exceptions.StandardError(
                         "Incorrect BOND entry in component %s." %
                         componentLabel)
                 for i in range(0, nlabels, 2):
                     labela, labelb = labels[i], labels[i + 1]
                     # . Ignore bonds involving atoms from other residues
                     checks = []
                     for label in (labela, labelb):
                         checks.extend([
                             label[0] != "+", label[-1] != "-",
                             not label[0].isdigit()
                         ])
                     if all(checks):
                         pair = (labela, labelb)
                         bonds.append(pair)
             elif line.startswith("IC"):
                 #  IC -C   CA   *N   H     1.3551 126.4900  180.0000 115.4200  0.9996
                 #  IC -C   N    CA   C     1.3551 126.4900  180.0000 114.4400  1.5390
                 #  IC N    CA   C    +N    1.4592 114.4400  180.0000 116.8400  1.3558
                 #  IC +N   CA   *C   O     1.3558 116.8400  180.0000 122.5200  1.2297
                 #  IC CA   C    +N   +CA   1.5390 116.8400  180.0000 126.7700  1.4613
                 #   (...)
                 while (line.startswith("IC")):
                     tokens = TokenizeLine(line,
                                           converters=[
                                               None, None, None, None, None,
                                               float, float, float, float,
                                               float
                                           ])
                     (a, b, c, d) = tokens[1:5]
                     ic = InternalCoordinate(i=a,
                                             j=b,
                                             k=c.replace("*", ""),
                                             l=d,
                                             distanceLeft=tokens[5],
                                             angleLeft=tokens[6],
                                             torsion=tokens[7],
                                             angleRight=tokens[8],
                                             distanceRight=tokens[9],
                                             improper=(c[0] == "*"))
                     internal.append(ic)
                     line = self._GetCleanLine(data)
     except StopIteration:
         pass
     # . Finish up
     data.close()
     if group:
         groups.append(group)
         component = (componentLabel, componentCharge, groups, bonds,
                      internal)
         components.append(component)
     # . Set up actual amino components from temporary components
     aminoComponents = []
     for componentSerial, (componentLabel, componentCharge, groups, bonds,
                           internalCoordinates) in enumerate(components, 1):
         # . Merge atoms
         aminoAtoms = []
         for group in groups:
             for atom in group:
                 aminoAtoms.append(atom)
         aminoGroups = []
         # . Iterate temporary groups
         for igroup, group in enumerate(groups):
             # . Merge atom labels
             labels = []
             for atom in group:
                 labels.append(atom.atomLabel)
             # . Create a group
             natoms = len(group)
             aminoGroup = AminoGroup(
                 radius=5.,
                 natoms=natoms,
                 labels=labels,
                 symbol=chr(ord(_GROUP_START) + igroup),
                 centralAtom=group[natoms / 2].atomLabel,
             )
             aminoGroups.append(aminoGroup)
         # . Create a component
         component = AminoComponent(
             serial=componentSerial,
             label=componentLabel,
             groups=aminoGroups,
             atoms=aminoAtoms,
             bonds=bonds,
             internal=internalCoordinates,
             connect=("", ""),
             logging=True if (logging and verbose) else False,
             title="Generated from CHARMM topology",
         )
         aminoComponents.append(component)
     self.components = aminoComponents
Example #21
0
    def _Parse(self, logging):
        data = open(self.filename, "r")
        if logging:
            print("# . %s> Parsing file \"%s\"" %
                  (_MODULE_LABEL, self.filename))
        try:
            while True:
                line = next(data)
                if line.count("# of evb atoms, # of resforms"):
                    (natoms, nforms) = TokenizeLine(line,
                                                    converters=[int, int])
                    nlines = (natoms / _ATOMS_PER_LINE) + (
                        1 if (natoms % _ATOMS_PER_LINE) > 0 else 0)
                    # . Read atom serial numbers
                    serials = []
                    for i in range(nlines):
                        tokens = TokenizeLine(next(data),
                                              converters=([
                                                  int,
                                              ] * _ATOMS_PER_LINE))
                        for token in tokens:
                            if token != None:
                                serials.append(token)
                    # . Read atom type numbers for each form
                    forms = []
                    for i in range(nforms):
                        types = []
                        for j in range(nlines):
                            tokens = TokenizeLine(next(data),
                                                  converters=([
                                                      int,
                                                  ] * _ATOMS_PER_LINE))
                            for token in tokens:
                                if token != None:
                                    types.append(token)
                        forms.append(types)
                    self.types = forms
                    # . Read atomic charges for each form
                    charges = []
                    for i in range(nforms):
                        form = []
                        for j in range(nlines):
                            tokens = TokenizeLine(next(data),
                                                  converters=([
                                                      float,
                                                  ] * _ATOMS_PER_LINE))
                            for token in tokens:
                                if token != None:
                                    form.append(token)
                        charges.append(form)
                    self.charges = charges
                    self.natoms = natoms
                    self.nforms = nforms
                    if logging:
                        print("# . %s> Found %d EVB atoms in %d forms" %
                              (_MODULE_LABEL, natoms, nforms))
                        types = set()
                        for form in self.types:
                            for atom in form:
                                types.add(atom)
                        ntypes = len(types)
                        print("# . %s> Found %d unique atom types" %
                              (_MODULE_LABEL, ntypes))

                elif line.count("bonds(atoms,types,exist)"):
                    (nbonds, foo) = TokenizeLine(line, converters=[int, None])
                    bonds = []
                    for i in range(nbonds):
                        bond = self._GetContainer(data, 2)
                        bonds.append(bond)
                    self.bonds = bonds
                    if logging:
                        print("# . %s> Found %d EVB bonds" %
                              (_MODULE_LABEL, nbonds))

                elif line.count("angles(atoms,types,exist)"):
                    (nangles, foo) = TokenizeLine(line, converters=[int, None])
                    angles = []
                    for i in range(nangles):
                        angle = self._GetContainer(data, 3)
                        angles.append(angle)
                    self.angles = angles
                    if logging:
                        print("# . %s> Found %d EVB angles" %
                              (_MODULE_LABEL, nangles))

                elif line.count(" torsions(atoms,types,exist)"):
                    (ntorsions, foo) = TokenizeLine(line,
                                                    converters=[int, None])
                    torsions = []
                    for i in range(ntorsions):
                        torsion = self._GetContainer(data, 4)
                        torsions.append(torsion)
                    self.torsions = torsions
                    if logging:
                        print("# . %s> Found %d EVB torsions" %
                              (_MODULE_LABEL, ntorsions))

                elif line.count(
                        "morse potential parameters(r0,alpha,diss,f_harm,r_harm,type)"
                ):
                    (nparameters, foo) = TokenizeLine(line,
                                                      converters=[int, None])
                    self.parBonds = []
                    for i in range(nparameters):
                        (r0, alpha, diss, f_harm, r_harm,
                         ptype) = TokenizeLine(next(data),
                                               converters=[
                                                   float, float, float, float,
                                                   float, int
                                               ])
                        bond = EVBBond(
                            r0=r0,
                            diss=diss,
                            alpha=alpha,
                            f_harm=f_harm,
                            r_harm=r_harm,
                            ptype=ptype,
                        )
                        self.parBonds.append(bond)
                    if logging:
                        print("# . %s> Found %d EVB Morse parameters" %
                              (_MODULE_LABEL, nparameters))

                elif line.count(
                        "angle parameters(angle0(radian),force,gausD,gausig,type"
                ):
                    (nparameters, foo) = TokenizeLine(line,
                                                      converters=[int, None])
                    self.parAngles = []
                    for i in range(nparameters):
                        (angle0, force, gausD, gausig, ptype) = TokenizeLine(
                            next(data),
                            converters=[float, float, float, float, int])
                        angle = EVBAngle(
                            angle0=angle0,
                            force=force,
                            gausD=gausD,
                            gausig=gausig,
                            ptype=ptype,
                        )
                        self.parAngles.append(angle)
                    if logging:
                        print("# . %s> Found %d EVB angle parameters" %
                              (_MODULE_LABEL, nparameters))

                elif line.count(
                        "torsion parameters(force,n,phase_angle,type)"):
                    if not line.count("itorsion"):
                        (nparameters,
                         foo) = TokenizeLine(line, converters=[int, None])
                        self.parTorsions = []
                        for i in range(nparameters):
                            (force, n, phase, ptype) = TokenizeLine(
                                next(data),
                                converters=[float, float, float, int])
                            torsion = EVBTorsion(
                                force=force,
                                n=n,
                                phase=phase,
                                ptype=ptype,
                            )
                            self.parTorsions.append(torsion)
                        if logging:
                            print("# . %s> Found %d EVB torsion parameters" %
                                  (_MODULE_LABEL, nparameters))
        except StopIteration:
            pass
        # . File closing
        data.close()
Example #22
0
    def _Parse (self, reverse, convert):
        lines = open (self.inputfile)
        # . Assume the job is failed until finding a "TERMINATED NORMALLY" statement
        jobOK = False
        try:
            while True:
                line = next (lines)
                # . Get coordinates of QM atoms
                # ---------------------------------
                # CARTESIAN COORDINATES (ANGSTROEM)
                # ---------------------------------
                #   C      5.663910    4.221157   -1.234141
                #   H      5.808442    3.140412   -1.242145
                # (...)
                if line.startswith ("CARTESIAN COORDINATES (ANGSTROEM)"):
                    next (lines)
                    line     = next (lines)
                    geometry = []
                    while line != "\n":
                        tokens = TokenizeLine (line, converters=[None, float, float, float])
                        label, x, y, z = tokens
                        atom   = (label, x, y, z)
                        geometry.append (atom)
                        line   = next (lines)


                # . Get charges on QM atoms
                # -----------------------
                # MULLIKEN ATOMIC CHARGES
                # -----------------------
                #    0 C :   -0.520010
                #    1 H :    0.271953
                # (...)
                # Sum of atomic charges:   -0.0000000
                if line.startswith ("MULLIKEN ATOMIC CHARGES"):
                    next (lines)
                    line    = next (lines)
                    charges = []
                    while not line.startswith ("Sum of atomic charges:"):
                        tokens = TokenizeLine (line, separator=":", converters=[None, float])
                        charge = tokens[1]
                        charges.append (charge)
                        line   = next (lines)
                    self.charges = charges
                    # . Construct the final list of atoms with charges
                    atoms   = []
                    for (label, x, y, z), charge in zip (geometry, charges):
                        atom   = Atom (
                            symbol  =   label   ,
                            x       =   x       ,
                            y       =   y       ,
                            z       =   z       ,
                            charge  =   charge  ,
                            )
                        atoms.append (atom)
                    self.atoms = atoms


                # . Get gradients on QM atoms
                # ------------------
                # CARTESIAN GRADIENT
                # ------------------
                # 
                #    1   C   :   -0.017273415    0.000431161    0.011902545
                #    2   H   :    0.011246801   -0.004065387   -0.003492146
                # (...)
                elif line.startswith ("CARTESIAN GRADIENT"):
                    for i in range (2):
                        next (lines)
                    line   = next (lines)
                    forces = []
                    while line != "\n":
                        tokens = TokenizeLine (line, converters=[int, None, None, float, float, float])
                        gx, gy, gz = tokens[3:6]
                        if reverse:
                            gx, gy, gz = (-gx, -gy, -gz)
                        if convert:
                            gx, gy, gz = (gx * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM, gy * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM, gz * HARTREE_BOHR_TO_KCAL_MOL_ANGSTROM)
                        force  = Force (
                            x   =   gx  ,
                            y   =   gy  ,
                            z   =   gz  ,
                            )
                        forces.append (force)
                        line   = next (lines)
                    self.forces = forces


                # . Get the final energy
                # FINAL SINGLE POINT ENERGY      -263.834308915009
                elif line.startswith ("FINAL SINGLE POINT ENERGY"):
                    tokens = TokenizeLine (line, converters=[float, ], reverse=True)
                    if convert:
                        self.Efinal = tokens[-1] * HARTREE_TO_KCAL_MOL
                    else:
                        self.Efinal = tokens[-1]


                # . Check for a failed job
                elif line.count ("****ORCA TERMINATED NORMALLY****"):
                    jobOK = True
        except StopIteration:
            pass
        # . Close the file
        lines.close ()
        # . Check for a failed job
        if not jobOK:
            raise exceptions.StandardError ("Job %s did not end normally." % self.inputfile)
Example #23
0
 def _Parse(self, logging, reorder, unique, verbose):
     components = []
     names = []
     data = open(self.filename)
     if logging:
         print("# . %s> Parsing file \"%s\"" %
               (_MODULE_LABEL, self.filename))
     try:
         while True:
             line = self._GetCleanLine(data)
             # . Check if a new residue starts
             if line.startswith("---"):
                 # . Get serial and name
                 line, title = self._GetLineWithComment(data)
                 entry = TokenizeLine(line, converters=[
                     None,
                 ])[0]
                 # . Remove spaces
                 entry = entry.replace(" ", "")
                 # . Check if last residue found
                 if entry == "0":
                     break
                 for i, char in enumerate(entry):
                     if not char.isdigit():
                         break
                 componentSerial, name = int(entry[:i]), entry[i:]
                 # . Check if the component label is unique
                 if unique:
                     if name in names:
                         raise exceptions.StandardError(
                             "Component label %s is not unique." % name)
                     names.append(name)
                 # . Get number of atoms
                 line = self._GetCleanLine(data)
                 natoms = int(line)
                 # . Initiate conversion table serial->label
                 convert = {}
                 # . Read atoms
                 atoms = []
                 labels = []
                 for i in range(natoms):
                     line = self._GetCleanLine(data)
                     atomNumber, atomLabel, atomType, atomCharge = TokenizeLine(
                         line, converters=[int, None, None, float])
                     if unique:
                         # . Check if the atom label is unique
                         if atomLabel in labels:
                             raise exceptions.StandardError(
                                 "Component %s %d: Atom label %s is not unique."
                                 % (name, serial, atomLabel))
                         labels.append(atomLabel)
                     # . Create atom
                     atom = AminoAtom(atomLabel=atomLabel,
                                      atomType=atomType,
                                      atomCharge=atomCharge)
                     atoms.append(atom)
                     # . Update conversion table serial->label
                     convert[atomNumber] = atomLabel
                 # . Get number of bonds
                 line = self._GetCleanLine(data)
                 nbonds = int(line)
                 # . Read bonds
                 bonds = []
                 for i in range(nbonds):
                     line = self._GetCleanLine(data)
                     atoma, atomb = TokenizeLine(line,
                                                 converters=[int, int])
                     if reorder:
                         # . Keep the lower number first
                         if atoma > atomb:
                             atoma, atomb = atomb, atoma
                     bonds.append((atoma, atomb))
                 if reorder:
                     # . Sort bonds
                     bonds.sort(key=lambda bond: bond[0])
                 # . Convert numerical bonds to labeled bonds
                 labeledBonds = []
                 for atoma, atomb in bonds:
                     # . FIXME: Workaround for invalid entries in the amino file
                     try:
                         pair = (convert[atoma], convert[atomb])
                         labeledBonds.append(pair)
                     except:
                         pass
                 bonds = labeledBonds
                 # . Read connecting atoms
                 line = self._GetCleanLine(data)
                 seriala, serialb = TokenizeLine(line,
                                                 converters=[int, int])
                 # . Convert serials of connecting atoms to labels
                 connecta, connectb = "", ""
                 if seriala > 0:
                     connecta = convert[seriala]
                 if serialb > 0:
                     connectb = convert[serialb]
                 # . Read number of electroneutral groups
                 line = self._GetCleanLine(data)
                 ngroups = int(line)
                 # . Read groups
                 groups = []
                 for i in range(ngroups):
                     line = self._GetCleanLine(data)
                     nat, central, radius = TokenizeLine(
                         line, converters=[int, int, float])
                     line = self._GetCleanLine(data)
                     serials = TokenizeLine(line, converters=[int] * nat)
                     # . Convert central atom's serial to a label
                     # . FIXME: Workaround for invalid entries in the amino file
                     try:
                         central = convert[central]
                         # . Convert serials to labels
                         labels = []
                         for serial in serials:
                             labels.append(convert[serial])
                         symbol = chr(ord(_GROUP_START) + i)
                         group = AminoGroup(natoms=nat,
                                            centralAtom=central,
                                            radius=radius,
                                            labels=labels,
                                            symbol=symbol)
                         groups.append(group)
                     except:
                         pass
                 # . Create a component and add it to the list
                 logFlag = False
                 if logging:
                     if verbose:
                         logFlag = True
                 component = AminoComponent(serial=componentSerial,
                                            name=name,
                                            atoms=atoms,
                                            bonds=bonds,
                                            groups=groups,
                                            connect=(connecta, connectb),
                                            logging=logFlag,
                                            title=title)
                 components.append(component)
     except StopIteration:
         pass
     # . Finish up
     data.close()
     self.components = components
Example #24
0
    def _Parse(self, logging):
        lines = open(self.filename)
        if logging:
            print("# . %s> Parsing file \"%s\"" %
                  (_MODULE_LABEL, self.filename))
        stateI = []
        stateII = []
        self.bonds = []
        counter = 0
        try:
            while True:
                line, comment = self._GetLineWithComment(lines)
                counter += 1

                # . Read EVB states, assume there are only two of them
                # evb_atm         6   -0.3000    C0   -0.3000    C0
                # evb_atm         5   -0.4500    O0   -0.4500    O0
                # (...)
                if line.startswith("evb_atm"):
                    foo, serial, chargeI, atypeI, chargeII, atypeII = TokenizeLine(
                        line, converters=[None, int, float, None, float, None])
                    atomState = EVBAtom(
                        atype=atypeI,
                        serial=serial,
                        charge=chargeI,
                        comment=comment,
                    )
                    stateI.append(atomState)

                    atomState = EVBAtom(
                        atype=atypeII,
                        serial=serial,
                        charge=chargeII,
                        comment=comment,
                    )
                    stateII.append(atomState)

                # . Read EVB bonds
                #        evb_bnd   0         5     6   # O5'     C5'
                #        evb_bnd   0         7     6   # H5'1    C5'
                # (...)
                elif line.startswith("evb_bnd"):
                    foo, states, seriala, serialb = TokenizeLine(
                        line, converters=[None, int, int, int])
                    bond = EVBBond(
                        states=states,
                        seriala=seriala,
                        serialb=serialb,
                        comment=comment,
                    )
                    self.bonds.append(bond)

                elif line.startswith("constraint_pair"):
                    # . Prevent reading lines with @DIST_ATT@ or @DIST_LEA@
                    # . type of labels instead of numerical values (as in
                    # . template files)
                    try:
                        (foo, aserial, bserial, forceConst, equilDist,
                         state) = TokenizeLine(
                             line,
                             converters=[None, int, int, float, float, int])
                        pair = ConstrainedPair(
                            seriala=aserial,
                            serialb=bserial,
                            force=forceConst,
                            req=equilDist,
                            state=state,
                        )
                        if not hasattr(self, "constrainedPairs"):
                            self.constrainedPairs = []
                        self.constrainedPairs.append(pair)
                    except:
                        if logging:
                            print("# . %s> Skipping line %d in file \"%s\"" %
                                  (_MODULE_LABEL, counter, self.filename))
        except StopIteration:
            pass
        # . Close the file
        lines.close()
        # . Finalize
        self.states = [stateI, stateII]
        if logging:
            print("# . %s> Read %d EVB atoms" % (_MODULE_LABEL, self.natoms))
Example #25
0
 def _GetGradientLine(self, openfile):
     line = next(openfile)
     tokens = TokenizeLine(
         line, converters=[int, int, None, None, None, float, float, None])
     gradient = tokens[6]
     return gradient
Example #26
0
    def _Parse(self):
        lines = open(self.inputfile)
        jobOK = True
        try:
            while True:
                line = next(lines)
                # . Get the number of atoms
                # . This line does not exists in log files generated by some versions of Mopac
                if line.count("TOTAL NO. OF ATOMS:"):
                    tokens = TokenizeLine(line,
                                          converters=[
                                              int,
                                          ],
                                          reverse=True)
                    self.natoms = tokens[0]

                # . Read gradients
                elif line.count("FINAL  POINT  AND  DERIVATIVES"):
                    # . Skip the next two lines
                    next(lines)
                    next(lines)
                    self.forces = []
                    for i in range(self.natoms):
                        force = Force(
                            x=self._GetGradientLine(lines) * GRADIENT_TO_FORCE,
                            y=self._GetGradientLine(lines) * GRADIENT_TO_FORCE,
                            z=self._GetGradientLine(lines) * GRADIENT_TO_FORCE)
                        self.forces.append(force)

                # . Get the final total energy (electronic + nuclear repulsion)
                elif line.count("TOTAL ENERGY"):
                    tokens = TokenizeLine(
                        line, converters=[None, None, None, float, None])
                    self.Etotal = tokens[3] * EV_TO_KCAL_MOL

                # . Read the final heat in formation
                # . Comment: For some reason (numeric?), heat of formation was used as a final form of energy
                # . in old Plotnikov's scripts, instead of the total energy.
                elif line.count("FINAL HEAT OF FORMATION"):
                    tokens = TokenizeLine(line,
                                          converters=[
                                              None, None, None, None, None,
                                              float, None, None, float, None
                                          ])
                    self.Efinal = tokens[5]

                # . Read ESP (= Merz-Kollman) charges
                # . This line does not exists in log files generated by some versions of Mopac (relevant?)
                elif line.count("ELECTROSTATIC POTENTIAL CHARGES"):
                    # . Skip the next two lines
                    next(lines)
                    next(lines)
                    self.mkcharges = []
                    for i in range(self.natoms):
                        tokens = TokenizeLine(next(lines),
                                              converters=[int, None, float])
                        charge = tokens[2]
                        self.mkcharges.append(charge)

                # . Read Mulliken charges
                elif line.count("MULLIKEN POPULATIONS AND CHARGES"):
                    # . Skip the next two lines
                    next(lines)
                    next(lines)
                    self.charges = []
                    for i in range(self.natoms):
                        tokens = TokenizeLine(
                            next(lines), converters=[int, None, float, float])
                        charge = tokens[3]
                        self.charges.append(charge)

                # . Get the most recent coordinates of atoms
                #          CARTESIAN COORDINATES
                #
                #    NO.       ATOM         X         Y         Z
                #
                #     1         C        3.6656    6.4672   12.9744
                #     2         O        4.9097    6.3868   13.6162
                #   (...)
                elif line.count("CARTESIAN COORDINATES"):
                    for i in range(3):
                        next(lines)
                    atoms = []
                    while True:
                        line = next(lines)
                        templ = line.split()
                        if len(templ) != 5:
                            break
                        tokens = TokenizeLine(
                            line, converters=[int, None, float, float, float])
                        serial, symbol, x, y, z = tokens
                        atom = Atom(
                            symbol=symbol,
                            x=x,
                            y=y,
                            z=z,
                            charge=0.,
                        )
                        atoms.append(atom)
                    self.atoms = atoms
                    # . A workaround for some versions of Mopac that does not provide "TOTAL NO. OF ATOMS"
                    if not hasattr(self, "natoms"):
                        self.natoms = len(atoms)

                # . Check for a failed job
                elif self._CheckLine(line, _ERROR_LINES):
                    jobOK = False
        except StopIteration:
            pass
        # . Close the file
        lines.close()
        # . Check for a failed job
        if not jobOK:
            raise exceptions.StandardError("Job %s did not end normally." %
                                           self.inputfile)
Example #27
0
    def _Parse(self, logging):
        lines = open(self.filename)
        if logging:
            print("# . %s> Parsing file \"%s\"" %
                  (_MODULE_LABEL, self.filename))
        try:
            while True:
                line = next(lines)
                if line.count("BOND PARAMETERS"):
                    # . Read h-bond parameters
                    #   16                                H-BOND PARAMETERS {2A5,2(1X,F10.2)}
                    #   H2   O0  052899.00  016695.00
                    #   H2   O1  052899.00  016695.00
                    #   (...)
                    if line.count("H-BOND"):
                        tokens = TokenizeLine(line, converters=[
                            int,
                        ])
                        nhbonds = tokens[0]
                        self.hbonds = {}
                        for i in range(nhbonds):
                            line = next(lines)
                            tokens = TokenizeLine(
                                line, converters=[None, None, float, float])
                            (typea, typeb, a, b) = tokens
                            bond = HBond(
                                typea=typea,
                                typeb=typeb,
                                a=a,
                                b=b,
                            )
                            key = "%s-%s" % (typea, typeb)
                            self.hbonds[key] = bond
                        if logging:
                            print("# . %s> Read %d h-bonds" %
                                  (_MODULE_LABEL, nhbonds))

                    # . Read bond parameters
                    #  180                                    BOND PARAMETERS {2A5,2F8.3}
                    #   P5   P5 400.000   6.000
                    #   P2   C8 375.000   3.920
                    #   (...)
                    else:
                        tokens = TokenizeLine(line, converters=[
                            int,
                        ])
                        nbonds = tokens[0]
                        self.bonds = {}
                        for i in range(nbonds):
                            line = next(lines)
                            tokens = TokenizeLine(
                                line, converters=[None, None, float, float])
                            (typea, typeb, k, r0) = tokens
                            bond = Bond(
                                typea=typea,
                                typeb=typeb,
                                k=k,
                                r0=r0,
                            )
                            key = "%s-%s" % (typea, typeb)
                            self.bonds[key] = bond
                        if logging:
                            print("# . %s> Read %d bonds" %
                                  (_MODULE_LABEL, nbonds))

                # . Read angle parameters
                # 398                                   ANGLE PARAMETERS {3A5,F8.3,F8.1}
                #   P5   P5   P5  140.00   137.0
                #   C2   C2   R*   60.00   109.5
                #   (...)
                elif line.count("ANGLE PARAMETERS"):
                    tokens = TokenizeLine(line, converters=[
                        int,
                    ])
                    nangles = tokens[0]
                    self.angles = {}
                    for i in range(nangles):
                        line = next(lines)
                        tokens = TokenizeLine(
                            line, converters=[None, None, None, float, float])
                        (typea, typeb, typec, k, r0) = tokens
                        angle = Angle(
                            typea=typea,
                            typeb=typeb,
                            typec=typec,
                            k=k,
                            r0=r0,
                        )
                        key = "%s-%s-%s" % (typea, typeb, typec)
                        self.angles[key] = angle
                    if logging:
                        print("# . %s> Read %d angles" %
                              (_MODULE_LABEL, nangles))

                # . Read torsion parameters
                #   84                                TORSION PARAMETERS {2A5,2F8.3,F8.1}
                #   P5   P5   0.000   2.000     0.0
                #   C6   C8   1.500   3.000     0.0
                #   (...)
                elif line.count("TORSION PARAMETERS"):
                    tokens = TokenizeLine(line, converters=[
                        int,
                    ])
                    ntorsions = tokens[0]
                    self.torsions = {}
                    for i in range(ntorsions):
                        line = next(lines)
                        tokens = TokenizeLine(
                            line, converters=[None, None, float, float, float])
                        (typeb, typec, k, periodicity, phase) = tokens
                        # . For some reason, periodicity is written as a float number in the parm.lib file
                        periodicity = int(periodicity)
                        torsion = Torsion(
                            typeb=typeb,
                            typec=typec,
                            k=k,
                            periodicity=periodicity,
                            phase=phase,
                        )
                        key = "%s-%s" % (typeb, typec)
                        self.torsions[key] = torsion
                    if logging:
                        print("# . %s> Read %d torsions" %
                              (_MODULE_LABEL, ntorsions))

                # . Read improper torsion parameters
                #    6                                I-TORS PARAMETERS {A5,F8.3}
                #   C3   10.000
                #   N3   40.000
                #   (...)
                elif line.count("I-TORS PARAMETERS"):
                    tokens = TokenizeLine(line, converters=[
                        int,
                    ])
                    nimpropers = tokens[0]
                    self.impropers = {}
                    for i in range(nimpropers):
                        line = next(lines)
                        tokens = TokenizeLine(line, converters=[None, float])
                        (atomType, k) = tokens
                        improper = Improper(
                            atomType=atomType,
                            k=k,
                        )
                        self.impropers[atomType] = improper
                    if logging:
                        print("# . %s> Read %d impropers" %
                              (_MODULE_LABEL, nimpropers))

                # . Read van der Waals and mass paramters
                #  130                                VDW AND MASS PARAMETERS {3x,A2,1X,3F9.3}
                #   C6 01956.000  032.000  012.000
                #   C8 01956.000  032.000  012.000
                #   (...)
                elif line.count("VDW AND MASS PARAMETERS"):
                    tokens = TokenizeLine(line, converters=[
                        int,
                    ])
                    nparams = tokens[0]
                    self.nonbonded = {}
                    for i in range(nparams):
                        line = next(lines)
                        tokens = TokenizeLine(
                            line, converters=[None, float, float, float])
                        (atomType, repulsive, attractive, mass) = tokens
                        vdw = VanDerWaals(
                            atomType=atomType,
                            repulsive=repulsive,
                            attractive=attractive,
                            mass=mass,
                        )
                        self.nonbonded[atomType] = vdw
                    if logging:
                        print("# . %s> Read %d VDW and mass parameters" %
                              (_MODULE_LABEL, nparams))
        except StopIteration:
            pass
        # . Close the file
        lines.close()