public static OBMol molecule_merge(OBMol mol1, OBAtom a, OBMol mol2, OBAtom b) { //takes two molecules and two atoms in each molecule and //assuming atoms are in the same place, delete one atom and copy bond to the other //a //foreach(OBBond bond in b.Bonds()) //{ //} int keepid = Convert.ToInt32(a.GetIdx()); int todeleteid = Convert.ToInt32(b.GetIdx()); //var bonds = b.Bonds(); List <OBBond> bondlist = new List <OBBond>(); foreach (OBBond bon in b.Bonds()) { bondlist.Add(bon); } OBBond bond = bondlist[0]; int connectid = (int)bond.GetNbrAtomIdx(b); int prevatms = (int)mol1.NumAtoms(); //number of atoms before we combine things //OBMol mol3 = new OBMol (); mol1 = addmol(mol2, mol1); mol1.BeginModify(); OBAtom keep = mol1.GetAtom(keepid); OBAtom todelete = mol1.GetAtom(todeleteid + prevatms); OBAtom toconnect = mol1.GetAtom(connectid + prevatms); OBBond newbond = new OBBond(); newbond.SetBegin(keep); newbond.SetEnd(toconnect); newbond.SetBO(1); mol1.AddBond(newbond); mol1.DeleteAtom(todelete); //OBAtom= atom1 //var a = map2[0]; //int c1 = (int)(map1[1]); //int c2 = (int)(map2[1] + prevatms); //int h1 = (int)(map1[0]); ///int h2 = (int)(map2[0] + prevatms); //OBAtom carbon1 = mol1.GetAtom(c1); //OBAtom carbon2 = mol1.GetAtom(c2); //OBAtom hydrogen1 = mol1.GetAtom(h1); ///OBAtom hydrogen2 = mol1.GetAtom(h2); //OBBuilder.Connect(mol1, c1, c2);//connect fragments //mol1.DeleteAtom(hydrogen1); //mol1.DeleteAtom(hydrogen2); mol1.EndModify(); return(mol1); }
public static OBMol molecule_merge(OBMol mol1, OBAtom tokeep, OBAtom todelete) { //takes a molecule and two atoms in the molecule and //assuming atoms are in the same place, delete one atom and copy bond to the other mol1.BeginModify(); uint todeleteid = todelete.GetIdx(); //var bonds = b.Bonds(); List <OBBond> bondlist = new List <OBBond>(); foreach (OBBond bon in todelete.Bonds()) { bondlist.Add(bon); } foreach (OBBond bon in bondlist) { mol1.AddBond((int)tokeep.GetIdx(), (int)bon.GetNbrAtomIdx(todelete), (int)bon.GetBondOrder()); } //writeatominfotoscreen(mol1); //int connectid = (int)bond.GetNbrAtomIdx(b); //todelete = mol1.GetAtomById(todeleteid); ///OBAtom toconnect = mol1.GetAtom(connectid); //OBBond newbond = new OBBond(); //newbond.SetBegin(keep); //newbond.SetEnd(toconnect); //newbond.SetBO(1); //mol1.AddBond(newbond); mol1.DeleteAtom(todelete); mol1.EndModify(); return(mol1); }