コード例 #1
0
  def test_compute_charges(self):
    current_dir = os.path.dirname(os.path.realpath(__file__))
    ligand_file = os.path.join(current_dir, "../../dock/tests/1jld_ligand.sdf")
    xyz, mol = rdkit_utils.load_molecule(
        ligand_file, calc_charges=False, add_hydrogens=True)
    rdkit_utils.compute_charges(mol)

    has_a_charge = False
    for atom_idx in range(mol.GetNumAtoms()):
      atom = mol.GetAtoms()[atom_idx]
      value = atom.GetProp(str("_GasteigerCharge"))
      if value != 0:
        has_a_charge = True
    assert has_a_charge
コード例 #2
0
def get_mol_subset(
        coords: np.ndarray, mol: Union[RDKitMol, MolecularFragment],
        atom_indices_to_keep: List[int]
) -> Tuple[np.ndarray, MolecularFragment]:
    """Strip a subset of the atoms in this molecule

  Parameters
  ----------
  coords: np.ndarray
    Must be of shape (N, 3) and correspond to coordinates of mol.
  mol: RDKit Mol or MolecularFragment
    The molecule to strip
  atom_indices_to_keep: list
    List of the indices of the atoms to keep. Each index is a unique
    number between `[0, N)`.

  Returns
  -------
  Tuple[np.ndarray, MolecularFragment]
    A tuple of `(coords, mol_frag)` where `coords` is a numpy array of
    coordinates with hydrogen coordinates. `mol_frag` is a `MolecularFragment`.

  Note
  ----
  This function requires RDKit to be installed.
  """
    try:
        from rdkit import Chem
    except ModuleNotFoundError:
        raise ValueError("This function requires RDKit to be installed.")

    indexes_to_keep = []
    atoms_to_keep = []
    # Compute partial charges on molecule if RDKit Mol
    if isinstance(mol, Chem.Mol):
        compute_charges(mol)
    atoms = list(mol.GetAtoms())
    for index in atom_indices_to_keep:
        indexes_to_keep.append(index)
        atoms_to_keep.append(atoms[index])
    coords = coords[indexes_to_keep]
    mol_frag = MolecularFragment(atoms_to_keep, coords)
    return coords, mol_frag