Esempio n. 1
0
def GetBondFromPrm(row):
  """Parses bond row into a Bond object.

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

  Returns:
    bond (mmlib.molecule.Bond): Bond object with attributes from row.

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

  at1, at2, k_b, r_eq = row[1:5]

  if not _IsType(int, at1) or not int(at1) > 0:
    raise ValueError('Bond atom1 index must be positive integer: %s' % at1)
  if not _IsType(int, at2) or not int(at2) > 0:
    raise ValueError('Bond atom2 index must be positive integer: %s' % at2)
  if not _IsType(float, k_b) or not float(k_b) > 0.0:
    raise ValueError(
        'Bond spring constant must be positive numeric value: %s' % k_b)
  if not _IsType(float, r_eq) or not float(r_eq) > 0.0:
    raise ValueError(
        'Equilibrium bond length must be positive numeric value: %s' % r_eq)

  return molecule.Bond(int(at1)-1, int(at2)-1, float(k_b), float(r_eq))
def GetBonds(atoms, bond_graph):
    """Determine covalently bonded atoms from bond graph and get parameters.
  
  Search bond graph for bonded atom pairs, and parameter tables for mm
  parameters. Use to create a new Bond object and append to Molecule.
  
  Args:
    atoms (mmlib.molecule.Atom*): Array of molecule's Atom objects.
    bond_graph (int:(int: float)): Dictionary of bond connectivity.

  Returns:
    bonds (mmlib.molecule.Bond*): Array of molecule's Bond objects.
  """
    bonds = []
    for i, at1 in enumerate(atoms):
        for j in bond_graph[i]:
            if i > j:
                continue
            at2 = atoms[j]
            r_ij = bond_graph[i][j]
            k_b, r_eq = param.GetBondParam(at1.type_, at2.type_)
            if k_b:
                bonds.append(molecule.Bond(i, j, k_b, r_eq, r_ij))
    bonds.sort(key=lambda b: (b.at1, b.at2))
    return bonds
def GetBondFromPrm(record, atoms):
    """Parses bond record into a Bond object.

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

  Returns:
    bond (mmlib.molecule.Bond): Bond object with attributes from record.
  """
    at1, at2 = (x - 1 for x in map(int, record[1:3]))
    k_b, r_eq = tuple(map(float, record[3:5]))
    c1, c2 = (atoms[i].coords for i in (at1, at2))
    r_ij = geomcalc.GetRij(c1, c2)
    return molecule.Bond(at1, at2, r_ij, r_eq, k_b)
def get_bond(mol, record):
    """Parse bond record into a bond object and append to molecule.
    
    Appends mmlib.molecule.Bond object to mmlib.molecule.Molecule
    object. Contents of bond object include (int) 2 atomic indices,
    (float) spring constant [kcal/(mol*A^2)], (float) equilibrium bond
    length [Angstrom], (float) bond length [Angstrom].
    
    Args:
        mol (mmlib.molecule.Molecule): Molecule to append bond.
        record (str*): Array of strings from line of prm file.
    """
    at1, at2 = int(record[1])-1, int(record[2])-1
    k_b, r_eq = float(record[3]), float(record[4])
    c1, c2 = mol.atoms[at1].coords, mol.atoms[at2].coords
    r_ij = geomcalc.get_r_ij(c1, c2)
    bond = molecule.Bond(at1, at2, r_ij, r_eq, k_b)
    mol.bonds.append(bond)
    mol.bond_graph[at1][at2] = r_ij
    mol.bond_graph[at2][at1] = r_ij
def _GetBond(mol, record):
  """Parse bond record into a bond object and append to molecule.
  
  Appends mmlib.molecule.Bond object to mmlib.molecule.Molecule object. Contents
  of bond object include (int) 2 atomic indices, (float) spring constant
  [kcal/(mol*A^2)], (float) equilibrium bond length [Angstrom], (float) bond
  length [Angstrom].
  
  Args:
    mol (mmlib.molecule.Molecule): Molecule to append bond.
    record (str*): Array of strings from line of prm file.
  """
  at1, at2 = [x-1 for x in list(map(int, record[1:3]))]
  k_b, r_eq = list(map(float, record[3:5]))
  c1, c2 = [mol.atoms[i].coords for i in [at1, at2]]

  r_ij = geomcalc.GetRij(c1, c2)
  bond = molecule.Bond(at1, at2, r_ij, r_eq, k_b)
  mol.bonds.append(bond)
  mol.bond_graph[at1][at2] = r_ij
  mol.bond_graph[at2][at1] = r_ij
def GetBonds(records, atoms):
    """Parses bond records into an array of Bond objects.
  
  Args:
    records (str**): 2d array of strings from lines of prm file.
    atoms (mmlib.molecule.Atom*): Array of molecule's Atom objects.

  Returns:
    bonds (mmlib.molecule.Bond*): Array of Bond objects with parameters from
        records.
  """
    bonds = []
    for record in records:
        if not record[0].upper() == 'BOND':
            continue
        at1, at2 = [x - 1 for x in list(map(int, record[1:3]))]
        k_b, r_eq = list(map(float, record[3:5]))
        c1, c2 = [atoms[i].coords for i in [at1, at2]]
        r_ij = geomcalc.GetRij(c1, c2)
        bonds.append(molecule.Bond(at1, at2, r_ij, r_eq, k_b))
    return bonds
def GetBonds(mol):
    """Determine covalently bonded atoms from bond graph and get parameters.
  
  Search bond graph for bonded atom pairs, and parameter tables for mm
  parameters. Use to create a new Bond object and append to Molecule.
  
  Args:
    mol (mmlib.molecule.Molecule): Molecule object with bond graph of atom pairs
        within covalent radius cutoff threshold.
  """
    for i in range(mol.n_atoms):
        at1 = mol.atoms[i]
        for j in mol.bond_graph[i].keys():
            at2 = mol.atoms[j]
            if i >= j:
                r_ij = mol.bond_graph[i][j]
                k_b, r_eq = param.GetBondParam(at1.type_, at2.type_)
                if k_b > 0.0:
                    mol.bonds.append(molecule.Bond(i, j, r_ij, r_eq, k_b))
    mol.bonds = sorted(mol.bonds, key=lambda b: b.at2)
    mol.bonds = sorted(mol.bonds, key=lambda b: b.at1)
    mol.n_bonds = len(mol.bonds)
Esempio n. 8
0
 def testArbitrary(self):
     """Asserts correct Bond object for arbitrary input parameters."""
     param = ['BOND', '455', '27', '8.484', '6.63']
     test.assertObjectEqual(self, fileio.GetBondFromPrm(param),
                            molecule.Bond(454, 26, 8.484, 6.63))
Esempio n. 9
0
 def testSmallestValues(self):
     """Asserts correct Bond object for smallest allowed values."""
     param = ['BOND', '1', '2', '0.000001', '0.000001']
     test.assertObjectEqual(self, fileio.GetBondFromPrm(param),
                            molecule.Bond(0, 1, 0.000001, 0.000001))