def setUp(self): self.cistrans = CisTrans(index=1, atom_indices=[1, 2, 3], dihedral=60.0, reaction_center=True, stero='str', mask=[True, True, True])
def get_cistrans(self): """ A method for identifying all possible cistrans bonds in a molecule """ torsion_list = [] cistrans_list = [] for bond1 in self.rdkit_molecule.GetBonds(): atom1 = bond1.GetBeginAtom() atom2 = bond1.GetEndAtom() if atom1.IsInRing() or atom2.IsInRing(): # Making sure that bond1 we're looking at are not in a ring continue bond_list1 = list(atom1.GetBonds()) bond_list2 = list(atom2.GetBonds()) if not len(bond_list1) > 1 and not len(bond_list2) > 1: # Making sure that there are more than one bond attached to # the atoms we're looking at continue # Getting the 0th and 3rd atom and insuring that atoms # attached to the 1st and 2nd atom are not terminal hydrogens # We also make sure that all of the atoms are properly bound # together # If the above are satisfied, we append a tuple of the torsion our # torsion_list got_atom0 = False got_atom3 = False for bond0 in bond_list1: atomX = bond0.GetOtherAtom(atom1) # if atomX.GetAtomicNum() == 1 and len(atomX.GetBonds()) == 1: # This means that we have a terminal hydrogen, skip this # NOTE: for H_abstraction TSs, a non teminal H should exist # continue if atomX.GetIdx() != atom2.GetIdx(): got_atom0 = True atom0 = atomX for bond2 in bond_list2: atomY = bond2.GetOtherAtom(atom2) # if atomY.GetAtomicNum() == 1 and len(atomY.GetBonds()) == 1: # This means that we have a terminal hydrogen, skip this # continue if atomY.GetIdx() != atom1.GetIdx(): got_atom3 = True atom3 = atomY if not (got_atom0 and got_atom3): # Making sure atom0 and atom3 were not found continue # Looking to make sure that all of the atoms are properly bonded to # eached if ( "DOUBLE" in str( self.rdkit_molecule.GetBondBetweenAtoms( atom1.GetIdx(), atom2.GetIdx()).GetBondType()) and self.rdkit_molecule.GetBondBetweenAtoms( atom0.GetIdx(), atom1.GetIdx()) and self.rdkit_molecule.GetBondBetweenAtoms( atom1.GetIdx(), atom2.GetIdx()) and self.rdkit_molecule.GetBondBetweenAtoms( atom2.GetIdx(), atom3.GetIdx())): torsion_tup = (atom0.GetIdx(), atom1.GetIdx(), atom2.GetIdx(), atom3.GetIdx()) already_in_list = False for torsion_entry in torsion_list: a, b, c, d = torsion_entry e, f, g, h = torsion_tup if (b, c) == (f, g) or (b, c) == (g, f): already_in_list = True if not already_in_list: cistrans_list.append(torsion_tup) cistrans = [] for ct_index, indices in enumerate(cistrans_list): i, j, k, l = indices b0 = self.rdkit_molecule.GetBondBetweenAtoms(i, j) b1 = self.rdkit_molecule.GetBondBetweenAtoms(j, k) b2 = self.rdkit_molecule.GetBondBetweenAtoms(k, l) b0.SetBondDir(Chem.BondDir.ENDUPRIGHT) b2.SetBondDir(Chem.BondDir.ENDDOWNRIGHT) Chem.AssignStereochemistry(self.rdkit_molecule, force=True) if "STEREOZ" in str(b1.GetStereo()): if round(self.ase_molecule.get_dihedral(i, j, k, l), -1) == 0: atom = self.rdkit_molecule.GetAtomWithIdx(k) bonds = atom.GetBonds() for bond in bonds: indexes = [ bond.GetBeginAtomIdx(), bond.GetEndAtomIdx()] if not ((sorted([j, k]) == sorted(indexes)) or ( sorted([k, l]) == sorted(indexes))): break for index in indexes: if not (index in indices): l = index break indices = [i, j, k, l] stero = "Z" else: if round( self.ase_molecule.get_dihedral( i, j, k, l), -1) == 180: atom = self.rdkit_molecule.GetAtomWithIdx(k) bonds = atom.GetBonds() for bond in bonds: indexes = [ bond.GetBeginAtomIdx(), bond.GetEndAtomIdx()] if not ((sorted([j, k]) == sorted(indexes)) or ( sorted([k, l]) == sorted(indexes))): break for index in indexes: if not (index in indices): l = index break indices = [i, j, k, l] stero = "E" dihedral = self.ase_molecule.get_dihedral(i, j, k, l) tor = CisTrans(index=ct_index, atom_indices=indices, dihedral=dihedral, mask=[], stero=stero) mask = self.get_mask(tor) reaction_center = False cistrans.append(CisTrans(index=ct_index, atom_indices=indices, dihedral=dihedral, mask=mask, stero=stero ) ) self.cistrans = cistrans return self.cistrans
def get_torsions(self): rdmol_copy = self.rdkit_molecule torsion_list = [] cistrans_list = [] for bond1 in rdmol_copy.GetBonds(): atom1 = bond1.GetBeginAtom() atom2 = bond1.GetEndAtom() if atom1.IsInRing() or atom2.IsInRing(): # Making sure that bond1 we're looking at are not in a ring continue bond_list1 = list(atom1.GetBonds()) bond_list2 = list(atom2.GetBonds()) if not len(bond_list1) > 1 and not len(bond_list2) > 1: # Making sure that there are more than one bond attached to # the atoms we're looking at continue # Getting the 0th and 3rd atom and insuring that atoms # attached to the 1st and 2nd atom are not terminal hydrogens # We also make sure that all of the atoms are properly bound together # If the above are satisfied, we append a tuple of the torsion our torsion_list got_atom0 = False got_atom3 = False for bond0 in bond_list1: atomX = bond0.GetOtherAtom(atom1) # if atomX.GetAtomicNum() == 1 and len(atomX.GetBonds()) == 1: # This means that we have a terminal hydrogen, skip this # NOTE: for H_abstraction TSs, a non teminal H should exist # continue if atomX.GetIdx() != atom2.GetIdx(): got_atom0 = True atom0 = atomX for bond2 in bond_list2: atomY = bond2.GetOtherAtom(atom2) # if atomY.GetAtomicNum() == 1 and len(atomY.GetBonds()) == 1: # This means that we have a terminal hydrogen, skip this # continue if atomY.GetIdx() != atom1.GetIdx(): got_atom3 = True atom3 = atomY if not (got_atom0 and got_atom3): # Making sure atom0 and atom3 were not found continue # Looking to make sure that all of the atoms are properly bonded to eached if ("SINGLE" in str( rdmol_copy.GetBondBetweenAtoms( atom1.GetIdx(), atom2.GetIdx()).GetBondType()) and rdmol_copy.GetBondBetweenAtoms(atom0.GetIdx(), atom1.GetIdx()) and rdmol_copy.GetBondBetweenAtoms(atom1.GetIdx(), atom2.GetIdx()) and rdmol_copy.GetBondBetweenAtoms(atom2.GetIdx(), atom3.GetIdx())): torsion_tup = (atom0.GetIdx(), atom1.GetIdx(), atom2.GetIdx(), atom3.GetIdx()) already_in_list = False for torsion_entry in torsion_list: a, b, c, d = torsion_entry e, f, g, h = torsion_tup if (b, c) == (f, g) or (b, c) == (g, f): already_in_list = True if not already_in_list: torsion_list.append(torsion_tup) if ("DOUBLE" in str( rdmol_copy.GetBondBetweenAtoms( atom1.GetIdx(), atom2.GetIdx()).GetBondType()) and rdmol_copy.GetBondBetweenAtoms(atom0.GetIdx(), atom1.GetIdx()) and rdmol_copy.GetBondBetweenAtoms(atom1.GetIdx(), atom2.GetIdx()) and rdmol_copy.GetBondBetweenAtoms(atom2.GetIdx(), atom3.GetIdx())): torsion_tup = (atom0.GetIdx(), atom1.GetIdx(), atom2.GetIdx(), atom3.GetIdx()) already_in_list = False for torsion_entry in torsion_list: a, b, c, d = torsion_entry e, f, g, h = torsion_tup if (b, c) == (f, g) or (b, c) == (g, f): already_in_list = True if not already_in_list: cistrans_list.append(torsion_tup) torsions = [] cistrans = [] for indices in torsion_list: i, j, k, l = indices dihedral = self.ase_molecule.get_dihedral(i, j, k, l) tor = Torsion(indices=indices, dihedral=dihedral, left_mask=[], right_mask=[]) left_mask = self.get_left_mask(tor) right_mask = self.get_right_mask(tor) reaction_center = "No" torsions.append( Torsion(indices, dihedral, left_mask, right_mask, reaction_center)) for indices in cistrans_list: i, j, k, l = indices dihedral = self.ase_molecule.get_dihedral(i, j, k, l) tor = CisTrans(indices=indices, dihedral=dihedral, left_mask=[], right_mask=[]) left_mask = self.get_left_mask(tor) right_mask = self.get_right_mask(tor) reaction_center = "No" cistrans.append( CisTrans(indices, dihedral, left_mask, right_mask, reaction_center)) self.torsions = torsions self.cistrans = cistrans return self.torsions