// public static bool isInCone(OBVector3 x, OBVector3 apex, OBVector3 axis, double aperture ) // { // //got it from here:http://stackoverflow.com/questions/10768142/verify-if-point-is-inside-a-cone-in-3d-space // //test if point x is inside an infinite cone defined by apex point with normal vector axis and aperture angle(in radians) // double halfAperture=aperture/2; // OBVector3 apexToXVect = OBVector3(apex,x); // OBVector3. // bool insideCone = StarMath.dotProduct(apex,axis)/StarMath.norm2(apexToXVect)/StarMath.norm2(axis) > Math.Cos(aperture); // return insideCone; // } public static bool atomsInCarboxylateCone(OBAtom a, OBAtom carba, OBMol mol) { //angle should probably not be hardcoded double aperture = 120 * Math.PI / 180; double[] axis = obvec2dubs(OBVector3.Sub(carba.GetVector(), a.GetVector())); //axis = StarMath.divide (axis, StarMath.norm2 (axis)); double[] apex = obvec2dubs(carba.GetVector()); List <uint> exclude = new List <uint>(); exclude.Add(carba.GetIdx()); foreach (OBBond b in carba.Bonds()) { OBAtom other = b.GetNbrAtom(carba); if (other != a) { exclude.Add(other.GetIdx()); } } foreach (OBAtom n in mol.Atoms()) { if (!exclude.Contains(n.GetIdx())) { double[] x = obvec2dubs(n.GetVector()); //if any point is found to be in the carboxylate's cone, return true if (isInCone(x, apex, axis, aperture)) { return(true); } } } return(false); }
public static void writeatominfotoscreen(OBAtom a) { Console.WriteLine("atomtype: " + a.GetAtomType() + " id " + a.GetIdx() + " index " + a.GetIndex() + " CIdx" + a.GetCIdx() + " title" + a.GetTitle() + " hash" + a.GetHashCode()); var ddd = OpenBabel.OBBuilder.GetNewBondVector(a); string foobar = ddd.GetX() + " " + ddd.GetY() + " " + ddd.GetZ(); Console.WriteLine(foobar); }
public static OBMol connect_within_radius(OBMol mol, OBAtom n, double radius) { foreach (OBAtom a in mol.Atoms()) { if (a.GetIdx() == n.GetIdx()) { continue; } else { double len = Math.Round(StarMath.norm2(obvec2dubs(OBVector3.Sub(a.GetVector(), n.GetVector()))), 7); //gets length if (len <= radius) { mol.AddBond((int)a.GetIdx(), (int)n.GetIdx(), 1); } } } return(mol); }
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); }
public static OBMol addmol(OBMol source, OBMol dest) { //combines two OBMols into one molecule // this is designed to do the same thing as the += operator in mol.cpp, in other words this implements functionality present in openbabel, but not in the C# api dest.BeginModify(); uint prevatms = dest.NumAtoms(); uint nextatms = source.NumAtoms(); // First, handle atoms and bonds foreach (OBAtom atom in source.Atoms()) { atom.SetId(0); ////Need to remove ID which relates to source mol rather than this mol// But in the C++ it had a NoId thing I couldn't figure out dest.AddAtom(atom); //var foooo = dest.Atoms (); } //writeatominfotoscreen (dest); foreach (OBBond bond in source.Bonds()) { bond.SetId(0); dest.AddBond((int)(bond.GetBeginAtomIdx() + prevatms), (int)(bond.GetEndAtomIdx() + prevatms), (int)bond.GetBO(), (int)bond.GetFlags()); } //don't really understand what they mean by residues //I think it's an amino acid or nucleotide so you can build up proteins and stuff? //don't think I'm going to use them either, but it might be useful foreach (OBResidue residue in source.Residues()) { OBResidue newres = new OBResidue(); dest.AddResidue(newres); OBResidueAtomIter ai = new OBResidueAtomIter(residue); //dammit why didn't they implement a residue.atoms sort of thing? I don't want to play with enumerators ////#define FOR_ATOMS_OF_RESIDUE(a,r) for( OBResidueAtomIter a(r); a; ++a ) while (ai.MoveNext()) { OBAtom resatom = new OBAtom(); resatom = ai.Current; // This is the equivalent atom in our combined molecule OBAtom atom = dest.GetAtom((int)(resatom.GetIdx() + prevatms)); // So we add this to the last-added residue // (i.e., what we just copied) //[dest.NumResidues () - 1] var res = dest.Residues().GetEnumerator(); while (!res.MoveNext()) { } //move to the last residue res.Current.AddAtom(atom); //var item = dest.Cast<RMSRequestProcessor.RMSMedia> ().ElementAt (1); } //for(OBAtom resatom in ) } dest.EndModify(); return(dest); }