def test_compute_charge_dictionary(self): for fname in (self.ligand_file, self.protein_file): _, mol = rgf.load_molecule(fname) ComputeGasteigerCharges(mol) charge_dict = rgf.compute_charge_dictionary(mol) self.assertEqual(len(charge_dict), mol.GetNumAtoms()) for i in range(mol.GetNumAtoms()): self.assertIn(i, charge_dict) self.assertIsInstance(charge_dict[i], (float, int))
def partialcharge(self): if self.Atom.HasProp('_TriposPartialCharge'): return float(self.Atom.GetProp('_TriposPartialCharge')) if not self.Atom.HasProp('_GasteigerCharge'): ComputeGasteigerCharges(self.Atom.GetOwningMol()) return float(self.Atom.GetProp('_GasteigerCharge').replace(',','.'))
def MolToMol2Block(mol, confId=-1, addHs=False, addCharges=False): """Returns a Mol2 string block for a molecule ARGUMENTS: - mol: the molecule - confId: (optional) selects which conformation to output (-1 = default) if set to None will return all conformers RETURNS: a string """ # # References # - Format specs http://www.tripos.com/data/support/mol2.pdf # - Atom typing http://www.sdsc.edu/CCMS/Packages/cambridge/pluto/atom_types.html # confIds = (confId, ) if confId == None: confIds = Chem.Mol.GetNumConformers() blocks = [] # add explicit hydrogens (since mol2 reader requires them) if addHs: h_coords = mol.GetNumConformers() > 0 and mol.GetConformer(-1).Is3D() try: mol = AddHs(mol, addCoords=h_coords) except RuntimeError: mol = AddHs(mol, addCoords=False) # compute charges if addCharges: ComputeGasteigerCharges(mol) for confId in confIds: molecule = """@<TRIPOS>MOLECULE {} {} {} 0 0 0 SMALL GASTEIGER\n\n""".format( mol.GetProp("_Name") if mol.HasProp("_Name") else "UNK", mol.GetNumAtoms(), mol.GetNumBonds()) # FIXME "USER_CHARGES" could become 'Gasteiger charges' # FIXME "SMALL" means small molecule but could become "PROTEIN" pos = _get_positions(mol, confId) atom_lines = [ "{:>4} {:>4} {:>13.4f} {:>9.4f} {:>9.4f} {:<5} {} {} {:>7.4f}". format(a.GetIdx() + 1, a.GetSymbol(), float(pos[a.GetIdx()][0]), float(pos[a.GetIdx()][1]), float(pos[a.GetIdx()][2]), _sybyl_atom_type(a), 1, "UNL", float(a.GetProp('_GasteigerCharge').replace(',', '.')) if a.HasProp('_GasteigerCharge') else 0.0) for a in mol.GetAtoms() ] atom_lines = ["@<TRIPOS>ATOM"] + atom_lines atom_lines = "\n".join(atom_lines) + "\n" bond_lines = [ "{:>5} {:>5} {:>5} {:>2}".format( bid + 1, b.GetBeginAtomIdx() + 1, b.GetEndAtomIdx() + 1, "ar" if b.GetBondTypeAsDouble() == 1.5 else "am" if _amide_bond(b) else str(int(b.GetBondTypeAsDouble()))) for bid, (b) in enumerate(mol.GetBonds()) ] bond_lines = ["@<TRIPOS>BOND"] + bond_lines + ["\n"] bond_lines = "\n".join(bond_lines) block = molecule + atom_lines + bond_lines blocks.append(block) return "".join(blocks)