def GetAngles(mol):
    """Determine bond angle atom triplets from bond graph and get parameters.
  
  Search bond graph for bond angle triplets, and parameter tables for mm
  parameters. Use to create a new Angle object and append to Molecule.
  Count as angle if ij and jk are bonded in triplet ijk.
  
  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 i in mol.bond_graph[j].keys():
            at1 = mol.atoms[i]
            r_ij = mol.bond_graph[i][j]
            for k in mol.bond_graph[j].keys():
                if i >= k:
                    continue
                at3 = mol.atoms[k]
                r_jk = mol.bond_graph[j][k]
                a_ijk = geomcalc.GetAijk(at1.coords, at2.coords, at3.coords,
                                         r_ij, r_jk)
                k_a, a_eq = param.GetAngleParam(at1.type_, at2.type_,
                                                at3.type_)
                if k_a > 0.0:
                    mol.angles.append(molecule.Angle(i, j, k, a_ijk, a_eq,
                                                     k_a))
    mol.angles = sorted(mol.angles, key=lambda a: a.at3)
    mol.angles = sorted(mol.angles, key=lambda a: a.at2)
    mol.angles = sorted(mol.angles, key=lambda a: a.at1)
    mol.n_angles = len(mol.angles)
def GetAngles(atoms, bond_graph):
    """Determine bond angle atom triplets from bond graph and get parameters.
  
  Search bond graph for bond angle triplets, and parameter tables for mm
  parameters. Use to create a new Angle object and append to Molecule.
  Count as angle if ij and jk are bonded in triplet ijk.
  
  Args:
    atoms (mmlib.molecule.Atom*): Array of molecule's Atom objects.
    bond_graph (int:(int:float)): Dictionary of bond connectivity.

  Returns:
    angles (mmlib.molecule.Angle*): Array of molecule's Angle objects.
  """
    angles = []
    for j, at2 in enumerate(atoms):
        for i, k in itertools.combinations(bond_graph[j], 2):
            if i > k:
                continue
            at1, at3 = atoms[i], atoms[k]
            a_ijk = geomcalc.GetAijk(at1.coords, at2.coords, at3.coords)
            k_a, a_eq = param.GetAngleParam(at1.type_, at2.type_, at3.type_)
            if k_a:
                angles.append(molecule.Angle(i, j, k, k_a, a_eq, a_ijk))
    angles.sort(key=lambda a: (a.at1, a.at2, a.at3))
    return angles
def GetAngleFromPrm(row):
  """Parses angle row into an Angle object.

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

  Returns:
    angle (mmlib.molecule.Angle): Angle object with attributes from row.

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

  at1, at2, at3, k_a, a_eq = row[1:6]

  if not _IsType(int, at1) or not int(at1) > 0:
    raise ValueError('Angle atom1 index must be positive integer: %s' % at1)
  if not _IsType(int, at2) or not int(at2) > 0:
    raise ValueError('Angle atom2 index must be positive integer: %s' % at2)
  if not _IsType(int, at3) or not int(at3) > 0:
    raise ValueError('Angle atom3 index must be positive integer: %s' % at3)
  if not _IsType(float, k_a) or not float(k_a) > 0.0:
    raise ValueError(
        'Angle spring constant must be positive numeric value: %s' % k_a)
  if not _IsType(float, a_eq) or not 0.0 <= float(a_eq) <= 180.0:
    raise ValueError(
        'Equilibrium bond angle must be between 0.0 and 180.0: %s' % a_eq)

  return molecule.Angle(
      int(at1)-1, int(at2)-1, int(at3)-1, float(k_a), float(a_eq))
def GetAngleFromPrm(record, atoms):
    """Parses angle record into an Angle object.

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

  Returns:
    angle (mmlib.molecule.Angle): Angle object with attributes from record.
  """
    at1, at2, at3 = (x - 1 for x in (map(int, record[1:4])))
    k_a, a_eq = tuple(map(float, record[4:6]))
    c1, c2, c3 = (atoms[i].coords for i in (at1, at2, at3))
    a_ijk = geomcalc.GetAijk(c1, c2, c3)
    return molecule.Angle(at1, at2, at3, a_ijk, a_eq, k_a)
def _GetAngle(mol, record):
  """Parse angle record into an angle object and append to molecule.
  
  Appends mmlib.molecule.Angle object to mmlib.molecule.Molecule object.
  Contents of angle object include (int) 3 atomic indices, (float) spring
  constant [kcal/(mol*radian^2)], (float) equilibrium bond angle [degrees], and
  (float) bond angle [degrees].
  
  Args:
    mol (mmlib.molecule.Molecule): Molecule to append angle.
    record (str*): Array of strings from line of prm file.
  """
  at1, at2, at3 = [x-1 for x in list(map(int, record[1:4]))]
  k_a, a_eq = list(map(float, record[4:6]))
  c1, c2, c3 = [mol.atoms[i].coords for i in [at1, at2, at3]]

  a_ijk = geomcalc.GetAijk(c1, c2, c3)
  angle = molecule.Angle(at1, at2, at3, a_ijk, a_eq, k_a)
  mol.angles.append(angle)
def get_angle(mol, record):
    """Parse angle record into an angle object and append to molecule.
    
    Appends mmlib.molecule.Angle object to mmlib.molecule.Molecule
    object. Contents of angle object include (int) 3 atomic indices,
    (float) spring constant [kcal/(mol*radian^2)], (float) equilibrium
    bond angle [degrees], and (float) bond angle [degrees].
    
    Args:
        mol (mmlib.molecule.Molecule): Molecule to append angle.
        record (str*): Array of strings from line of prm file.
    """
    at1, at2, at3 = int(record[1])-1, int(record[2])-1, int(record[3])-1
    k_a, a_eq = float(record[4]), float(record[5])
    c1, c2, c3 = (mol.atoms[at1].coords, mol.atoms[at2].coords,
        mol.atoms[at3].coords)
    a_ijk = geomcalc.get_a_ijk(c1, c2, c3)
    angle = molecule.Angle(at1, at2, at3, a_ijk, a_eq, k_a)
    mol.angles.append(angle)
def GetAngles(records, atoms):
    """Parses angle records into an array of Angle objects.
  
  Args:
    records (str**): 2d array of strings from lines of prm file.
    atom (mmlib.molecule.Atom*): Array of molecule's Atom objects.

  Returns:
    angles (mmlib.molecule.Angle): Array of Angle objects with parameters from
        records.
  """
    angles = []
    for record in records:
        if not record[0].upper() == 'ANGLE':
            continue
        at1, at2, at3 = [x - 1 for x in list(map(int, record[1:4]))]
        k_a, a_eq = list(map(float, record[4:6]))
        c1, c2, c3 = [atoms[i].coords for i in [at1, at2, at3]]
        a_ijk = geomcalc.GetAijk(c1, c2, c3)
        angles.append(molecule.Angle(at1, at2, at3, a_ijk, a_eq, k_a))
    return angles
Exemple #8
0
 def testArbitrary(self):
     """Asserts correct Angle object for arbitrary input parameters."""
     param = ['ANGLE', '62', '64', '67', '179.838', '17.76']
     test.assertObjectEqual(self, fileio.GetAngleFromPrm(param),
                            molecule.Angle(61, 63, 66, 179.838, 17.76))
Exemple #9
0
 def testSmallestValues(self):
     """Asserts correct Angle object for smallest allowed values."""
     param = ['ANGLE', '1', '2', '3', '0.000001', '0.000001']
     test.assertObjectEqual(self, fileio.GetAngleFromPrm(param),
                            molecule.Angle(0, 1, 2, 0.000001, 0.000001))