Example #1
0
//        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);
        }
Example #2
0
        public static double atomdist(OBAtom a0, OBAtom a1)
        {
            OBVector3 disp = OBVector3.Sub(a0.GetVector(), a1.GetVector());
            double    x    = disp.GetX();
            double    y    = disp.GetY();
            double    z    = disp.GetZ();
            double    dist = Math.Sqrt(x * x + y * y + z * z);

            return(dist);
        }
Example #3
0
        public static double pairwiseangle(OBAtom carbon1, OBAtom a1, OBAtom carbon2, OBAtom a2)
        {
            //carbon1 and carbon2 are carbon atoms connected to oxygen
            //a1 and a2 connect to carbon1 and carbon2 respectively

            OBVector3 vec1  = OBVector3.Sub(carbon1.GetVector(), a1.GetVector());
            OBVector3 vec2  = OBVector3.Sub(carbon2.GetVector(), a2.GetVector());
            double    angle = angle_between_vectors(vec1, vec2);

            return(angle);
        }
 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 merge_atoms_at_same_location(OBMol mol)
        {
            double radius = 0.1;
            //when we make a unit_cell by copy and pasting base cases we end up with atoms at the same location that need to be merged
            //assumes only two atoms overlap at a time
            Dictionary <int, int> tomerge = new Dictionary <int, int>();

            foreach (OBAtom a in mol.Atoms())
            {
                if (!tomerge.ContainsKey((int)a.GetIdx()))
                {
                    foreach (OBAtom b in mol.Atoms())
                    {
                        if (a.GetIdx() == b.GetIdx())
                        {
                            continue;
                        }
                        else
                        {
                            double len =
                                Math.Round(StarMath.norm2(obvec2dubs(OBVector3.Sub(a.GetVector(), b.GetVector()))),
                                           7); //gets length
                            if (len <= radius)
                            {
                                tomerge.Add((int)b.GetIdx(), (int)a.GetIdx());
                            }
                        }
                    }
                }
            }
            int atomsdeleted = 0;

            foreach (int key in tomerge.Keys)
            {
                mol = molecule_merge(mol, mol.GetAtom(key - atomsdeleted), mol.GetAtom(tomerge[key] - atomsdeleted));
                atomsdeleted++;
            }
            return(mol);
        }
Example #6
0
        public static double greatest_axial_distance(OBMol mol, OBAtom carbon1, OBAtom a1)
        {
            //finds the distance of the most distant atom along the axis defined by the carboxyl defined by carbon 1 and a1
            double[] vec = obvec2dubs(OBVector3.Sub(carbon1.GetVector(), a1.GetVector()));
            vec = StarMath.normalize(vec);
            double maxd = 0;

            foreach (OBAtom a in mol.Atoms())
            {
                if (a == carbon1)
                {
                    continue;
                }
                double d = StarMath.dotProduct(vec,
                                               obvec2dubs(OBVector3.Sub(carbon1.GetVector(),
                                                                        a.GetVector()))); // get pairwise axial distance by taking the scalar projection of the carbon's position to atom A
                if (d > maxd)
                {
                    maxd = d;
                }
            }
            return(maxd);
        }