def GetTorsions(atoms, bond_graph):
    """Determine torsion angle atom quartets and parameters from bond graph.
  
  Search bond graph for torsion angle quartets, and parameter tables for mm
  parameters. Use to create a new Torsion object and append to Molecule. Count
  as torsion if ij and jk and kl are bonded in quartet ijkl.
  
  Args:
    atoms (mmlib.molecule.Atom*): Array of molecule's Atom objects.
    bond_graph (int:(int:float)): Dictionary of bond connectivity.

  Returns:
    torsions (mmlib.molecule.Torsion*): Array of molecule's Torsion objects.
  """
    torsions = []
    for j, at2 in enumerate(atoms):
        for i, k in itertools.permutations(bond_graph[j], 2):
            if j > k:
                continue
            at1, at3 = atoms[i], atoms[k]
            for l in bond_graph[k]:
                if l == i or l == j:
                    continue
                at4 = atoms[l]
                t_ijkl = geomcalc.GetTijkl(at1.coords, at2.coords, at3.coords,
                                           at4.coords)
                params = param.GetTorsionParam(at1.type_, at2.type_, at3.type_,
                                               at4.type_)
                for v_n, gamma, nfold, paths in params:
                    if v_n:
                        torsions.append(
                            molecule.Torsion(i, j, k, l, v_n, gamma, nfold,
                                             paths, t_ijkl))
    torsions.sort(key=lambda t: (t.at1, t.at2, t.at3, t.at4))
    return torsions
def GetTorsionFromPrm(record, atoms):
    """Parses torsion record into an Torsion object.

  Args:
    record (str*): Array of strings from line of prm file.
    atoms (mmlib.molecule.Atom*): Array of molecule's Atom objects.

  Returns:
    torsion (mmlib.molecule.Torsion): Torsion object.
  """
    at1, at2, at3, at4 = (x - 1 for x in map(int, record[1:5]))
    v_n, gamma = tuple(map(float, record[5:7]))
    nfold, paths = tuple(map(int, record[7:9]))
    c1, c2, c3, c4 = (atoms[i].coords for i in (at1, at2, at3, at4))
    t_ijkl = geomcalc.GetTijkl(c1, c2, c3, c4)
    return molecule.Torsion(at1, at2, at3, at4, t_ijkl, v_n, gamma, nfold,
                            paths)
def GetTorsions(mol):
    """Determine torsion angle atom quartets and parameters from bond graph.
  
  Search bond graph for torsion angle quartets, and parameter tables for mm
  parameters. Use to create a new Torsion object and append to Molecule. Count
  as torsion if ij and jk and kl are bonded in quartet ijkl.
  
  Args:
    mol (mmlib.molecule.Molecule): Molecule object with bond graph of atom pairs
        within covalent radius cutoff threshold.
  """
    for j in range(mol.n_atoms):
        at2 = mol.atoms[j]
        for k in mol.bond_graph[j].keys():
            if j >= k:
                continue
            at3 = mol.atoms[k]
            r_jk = mol.bond_graph[j][k]
            for i in mol.bond_graph[j].keys():
                if i == j or i == k:
                    continue
                at1 = mol.atoms[i]
                r_ij = mol.bond_graph[i][j]
                for l in mol.bond_graph[k].keys():
                    if i == l or j == l or k == l:
                        continue
                    at4 = mol.atoms[l]
                    r_kl = mol.bond_graph[k][l]
                    t_ijkl = geomcalc.GetTijkl(at1.coords, at2.coords,
                                               at3.coords, at4.coords, r_ij,
                                               r_jk, r_kl)
                    params = param.GetTorsionParam(at1.type_, at2.type_,
                                                   at3.type_, at4.type_)
                    for p in range(len(params)):
                        v_n, gamma, nfold, paths = params[p]
                        if v_n > 0.0:
                            mol.torsions.append(
                                molecule.Torsion(i, j, k, l, t_ijkl, v_n,
                                                 gamma, nfold, paths))
    mol.torsions = sorted(mol.torsions, key=lambda t: t.at4)
    mol.torsions = sorted(mol.torsions, key=lambda t: t.at3)
    mol.torsions = sorted(mol.torsions, key=lambda t: t.at2)
    mol.torsions = sorted(mol.torsions, key=lambda t: t.at1)
    mol.n_torsions = len(mol.torsions)
示例#4
0
def GetTorsionFromPrm(row):
  """Parses torsion row into an Torsion object.

  Args:
    row (str*): Array of strings from line of prm file.

  Returns:
    torsion (mmlib.molecule.Torsion): Torsion object.

  Raises:
    IndexError: If insufficient number of fields.
    ValueError: If incorrect data type of any field.
  """
  if len(row) < 9:
    raise IndexError('Insufficient columns to parse prm file row into Torsion '
                     'object: %s' % ' '.join(row))

  at1, at2, at3, at4, v_n, gamma, nfold, paths = row[1:9]

  if not _IsType(int, at1) or not int(at1) > 0:
    raise ValueError('Torsion atom1 index must be positive integer: %s' % at1)
  if not _IsType(int, at2) or not int(at2) > 0:
    raise ValueError('Torsion atom2 index must be positive integer: %s' % at2)
  if not _IsType(int, at3) or not int(at3) > 0:
    raise ValueError('Torsion atom3 index must be positive integer: %s' % at3)
  if not _IsType(int, at4) or not int(at4) > 0:
    raise ValueError('Torsion atom4 index must be positive integer: %s' % at4)
  if not _IsType(float, v_n) or not float(v_n) > 0.0:
    raise ValueError(
        'Torsion half-barrier must be positive numeric value: %s' % v_n)
  if not _IsType(float, gamma) or not -180.0 <= float(gamma) <= 180.0:
    raise ValueError(
        'Torsion offset angle must be between -180.0 and 180.0: %s' % gamma) 
  if not nfold.isdigit() or not int(nfold) > 0:
    raise ValueError(
        'Torsion barrier frequency must be positive integer: %s' % nfold)
  if not paths.isdigit() or not int(paths) > 0:
    raise ValueError(
        'Torsion path number must be positive integer: %s' % paths)

  return molecule.Torsion(
      int(at1)-1, int(at2)-1, int(at3)-1, int(at4)-1, float(v_n), float(gamma),
      int(nfold), int(paths))
def _GetTorsion(mol, record):
  """Parse torsion record into a torsion object and append to molecule.
  
  Appends mmlib.molecule.Torsion object to mmlib.molecule.Molecule object.
  Contents of torsion object include (int) 4 atomic indices, (float)
  half-barrier height [kcal/mol], (float) barrier offset [degrees], (int)
  barrier frequency, (int) barrier paths, and (float) torsion angle [degrees].
  
  Args:
    mol (mmlib.molecule.Molecule): Molecule to append torsion.
    record (str*): Array of strings from line of prm file.
  """
  at1, at2, at3, at4 = [x-1 for x in list(map(int, record[1:5]))]
  v_n, gamma = list(map(float, record[5:7]))
  nfold, paths = list(map(int, record[7:9]))
  c1, c2, c3, c4 = [mol.atoms[i].coords for i in [at1, at2, at3, at4]]

  t_ijkl = geomcalc.GetTijkl(c1, c2, c3, c4)
  tors = molecule.Torsion(at1, at2, at3, at4, t_ijkl, v_n, gamma, nfold, paths)
  mol.torsions.append(tors)
def get_torsion(mol, record):
    """Parse torsion record into a torsion object and append to molecule.
    
    Appends mmlib.molecule.Torsion object to mmlib.molecule.Molecule
    object. Contents of torsion object include (int) 4 atomic indices,
    (float) half-barrier height [kcal/mol], (float) barrier offset [degrees],
    (int) barrier frequency, (int) barrier paths, and (float) torsion
    angle [degrees].
    
    Args:
        mol (mmlib.molecule.Molecule): Molecule to append torsion.
        record (str*): Array of strings from line of prm file.
    """
    at1, at2, at3, at4 = (int(record[1])-1, int(record[2])-1,
        int(record[3])-1, int(record[4])-1)
    v_n, gamma, nfold, paths = (float(record[5]), float(record[6]),
        int(record[7]), int(record[8]))
    c1, c2, c3, c4 = (mol.atoms[at1].coords, mol.atoms[at2].coords,
        mol.atoms[at3].coords, mol.atoms[at4].coords)
    t_ijkl = geomcalc.get_t_ijkl(c1, c2, c3, c4)
    torsion = molecule.Torsion(at1, at2, at3, at4, t_ijkl,
        v_n, gamma, nfold, paths)
    mol.torsions.append(torsion)
def GetTorsions(records, atoms):
    """Parses torsion records into an array of Torsion objects.
  
  Args:
    records (str**): 2d array of strings from lines of prm file.
    atom (mmlib.molecule.Atom*): Array of molecule's Atom objects.

  Returns:
    torsions (mmlib.molecule.Torsion*): Array of Torsion objects with parameters
        from record.
  """
    torsions = []
    for record in records:
        if not record[0].upper() == 'TORSION':
            continue
        at1, at2, at3, at4 = [x - 1 for x in list(map(int, record[1:5]))]
        v_n, gamma = list(map(float, record[5:7]))
        nfold, paths = list(map(int, record[7:9]))
        c1, c2, c3, c4 = [atoms[i].coords for i in [at1, at2, at3, at4]]
        t_ijkl = geomcalc.GetTijkl(c1, c2, c3, c4)
        torsions.append(
            molecule.Torsion(at1, at2, at3, at4, t_ijkl, v_n, gamma, nfold,
                             paths))
    return torsions
示例#8
0
 def testArbitrary(self):
     """Asserts correct Torsion object for arbitrary input parameters."""
     param = ['ANGLE', '62', '64', '67', '51', '10.0', '90.0', '3', '9']
     test.assertObjectEqual(
         self, fileio.GetTorsionFromPrm(param),
         molecule.Torsion(61, 63, 66, 50, 10.0, 90.0, 3, 9))
示例#9
0
 def testSmallestValues(self):
     """Asserts correct Torsion object for smallest allowed values."""
     param = ['TORSION', '1', '2', '3', '4', '0.000001', '-180.0', '1', '1']
     test.assertObjectEqual(
         self, fileio.GetTorsionFromPrm(param),
         molecule.Torsion(0, 1, 2, 3, 0.000001, -180.0, 1, 1))