Exemplo n.º 1
0
 public override int GetDistance(string refStructure, string modelStructure)
 {
     if (!pdbs.molDic.ContainsKey(refStructure) || !pdbs.molDic.ContainsKey(modelStructure))
     {
         return(errorValue);
     }
     if (pdbPos == null)
     {
         posMOL locPosMol = Optimization.PrepareData(pdbs.molDic[refStructure], pdbs.molDic[modelStructure]);
         return((int)(Optimization.Rmsd(locPosMol.posmol1, locPosMol.posmol2, false) * 100));
     }
     else
     {
         return((int)(Optimization.Rmsd(pdbPos[hashIndex[refStructure]], pdbPos[hashIndex[modelStructure]], false) * 100));
     }
 }
Exemplo n.º 2
0
        //Warning MaxSub has been reversed 0 is the best one, 1 is the worst

        /*public override int GetDistance(string refStructure, string modelStructure)
         * {
         *  int seedL = 4;
         *  int maxS = 0;
         *  float maxDist = 3.5f;
         *  //float maxDist = 1.5f;
         *  List<int> pList = new List<int>();
         *  List<int> cList = null;
         *  float[,] remMol = null;
         *  float[,] remTransMol = null;
         *  float[,] copyMol2 = null;
         *  List<int> bestList = null;
         *
         * //   TestRmsd(refStructure, modelStructure);
         *  if (!pdbs.molDic.ContainsKey(refStructure) || !pdbs.molDic.ContainsKey(modelStructure))
         *      return int.MaxValue;
         *
         *  posMOL locPosMol=Optimization.PrepareData(pdbs.molDic[refStructure], pdbs.molDic[modelStructure]);
         *  copyMol2 = new float[locPosMol.posmol2.GetLength(0), locPosMol.posmol2.GetLength(1)];
         *
         *  remMol = new float[locPosMol.posmol1.GetLength(0), locPosMol.posmol1.GetLength(1)];
         *  remTransMol = new float[locPosMol.posmol1.GetLength(0), locPosMol.posmol1.GetLength(1)];
         *
         *  //opt.CenterMols(opt.posMol1, opt.posMol2);
         *  if (bestList != null)
         *      bestList.Clear();
         *  for (int i = 0; i < locPosMol.posmol1.GetLength(0) - seedL; i++)
         *  {
         *      pList.Clear();
         *      for (int j = 0; j < seedL; j++)
         *          pList.Add(i + j);
         *
         *      KeyValuePair<List<int>, float[,]> extRes = Extend(pList, bestList,locPosMol.posmol1, locPosMol.posmol2, copyMol2, maxDist);
         *      cList = extRes.Key;
         *
         *      if (cList == null)
         *          continue;
         *
         *      if (cList.Count > maxS)
         *      {
         *          bestList = new List<int>(cList);
         *          maxS = cList.Count;
         *   //       Buffer.BlockCopy(copyMol1, 0, remMol, 0, copyMol2.Length * sizeof(float));
         *          Buffer.BlockCopy(extRes.Value, 0, remTransMol, 0, copyMol2.Length * sizeof(float));
         *      }
         *      if (cList.Count == locPosMol.posmol1.GetLength(0))
         *          break;
         *
         *
         *  }
         *  if (remTransMol == null || bestList==null || bestList.Count==0)
         *      return int.MaxValue;
         *
         *
         *
         *  float sum = 0;
         *  float mDist = maxDist * maxDist;
         *              float rmsd=0;
         *  foreach (var item in bestList)
         *  {
         *      float dist = 0;
         *      dist = calcDist(locPosMol.posmol1, remTransMol, item);
         *                      rmsd+=dist;
         *      dist *= dist;
         *      sum += 100/(1 + dist/ mDist);
         *  }
         *              rmsd/=bestList.Count;
         *  return 100 - (int)((sum / locPosMol.posmol1.GetLength(0)));
         * }*/
        private float [,] Rotate(List <int> indexList, float[,] pMol1, float[,] pMol2, float [,] copyMol)
        {
            float[,] indexMol1;
            float[,] indexMol2;
            float[,] transMatrix = null;
            float[,] rotMol      = null;



            if (indexList.Count <= 2)
            {
                return(null);
            }


            indexMol1 = new float[indexList.Count, 3];
            indexMol2 = new float[indexList.Count, 3];
            for (int j = 0; j < indexList.Count; j++)
            {
                for (int l = 0; l < 3; l++)
                {
                    indexMol1[j, l] = pMol1[indexList[j], l];
                    indexMol2[j, l] = pMol2[indexList[j], l];
                }
            }
            float[] center1 = new float[3];
            float[] center2 = new float[3];
            //opt.CenterMols(indexMol1, indexMol2);
            Optimization.CenterMol(indexMol1, center1);
            Optimization.TransVec(indexMol1, center1);
            Optimization.CenterMol(indexMol2, center2);
            Optimization.TransVec(indexMol2, center2);

            transMatrix = Optimization.TransMatrix(indexMol1, indexMol2);
            if (transMatrix == null)
            {
                return(null);
            }

            Buffer.BlockCopy(pMol2, 0, copyMol, 0, pMol2.Length * sizeof(float));
            Optimization.TransVec(copyMol, center2);
            Optimization.TransVec(pMol1, center1);

            rotMol = Optimization.MultMatrixTrans(copyMol, transMatrix);

            return(rotMol);
        }
Exemplo n.º 3
0
        private returnV GetStructAfterRotation(string refStructure, string modelStructure)
        {
            float[,] transMatrix = null;
            float [] cent1 = new float [3];
            float [] cent2 = new float [3];

            if (!pdbs.molDic.ContainsKey(refStructure) || !pdbs.molDic.ContainsKey(modelStructure))
            {
                return(null);
            }
            posMOL locPosMol = Optimization.PrepareData(pdbs.molDic[refStructure], pdbs.molDic[modelStructure], true);

            //opt.Rmsd(locPosMol.posmol1, locPosMol.posmol2, cent1, cent2, true);

            /* float [,]mm=new float [3,3];
             *
             * mm[0, 0] = 0; mm[0, 1] = 0; mm[0, 2] = 1;
             * mm[1, 0] = 1; mm[1, 1] = 0; mm[1, 2] = 0;
             * mm[2, 0] = 0; mm[2, 1] = 1; mm[2, 2] = 0;
             *
             * float [,]test=Optimization.MultMatrixTrans(locPosMol.posmol1, mm);*/

            transMatrix = Optimization.TransMatrix(locPosMol.posmol2, locPosMol.posmol1);
            //transMatrix = opt.TransMatrix(locPosMol.posmol1, test);
            if (transMatrix == null)
            {
                return(null);
            }

//            float[,] akk = Optimization.MultMatrixTrans(test, transMatrix);
            transMatrix = Optimization.MultMatrixTrans(locPosMol.posmol2, transMatrix);
            returnV r = new returnV();

            r.x = transMatrix;
            r.y = locPosMol.atoms;
            return(r);
            //return Optimization.MultMatrixTrans(test, transMatrix);
            //return akk;
            //return opt.posMolRot;
            //return opt.TransMatrix(opt.posMol1, opt.posMol2);
        }
Exemplo n.º 4
0
        public static float [,] TransMatrix(float [,] mol1, float [,] mol2)
        {
            MultRes res = Optimization.TransMultMatrix(mol1, mol2);
            Qcp     qcp = new Qcp(res.mult, res.val, mol1.GetLength(0));

            if (!qcp.CalcRotMatrix())
            {
                return(null);
            }

            float[,] rot = new float[3, 3];
            rot[0, 0]    = (float)qcp.rot00; rot[0, 1] = (float)qcp.rot01; rot[0, 2] = (float)qcp.rot02;
            rot[1, 0]    = (float)qcp.rot10; rot[1, 1] = (float)qcp.rot11; rot[1, 2] = (float)qcp.rot12;
            rot[2, 0]    = (float)qcp.rot20; rot[2, 1] = (float)qcp.rot21; rot[2, 2] = (float)qcp.rot22;

            /*for (int i = 0; i < 3; i++)
             *  for (int j = 0; j < 3; j++)
             *      rot[i,j] = (float)qcp.rot[i,j];*/

            return(rot);
        }
Exemplo n.º 5
0
        public override int GetDistance(string refStructure, string modelStructure)
        {
            KeyValuePair <List <int>, float[, ]> bestpair = default(KeyValuePair <List <int>, float[, ]>);

            if (!pdbs.molDic.ContainsKey(refStructure) || !pdbs.molDic.ContainsKey(modelStructure))
            {
                return(errorValue);
            }

            posMOL locPosMol = Optimization.PrepareData(pdbs.molDic[refStructure], pdbs.molDic[modelStructure]);

            foreach (var item in segments)
            {
                if (locPosMol.posmol1.GetLength(0) < item)
                {
                    continue;
                }
                KeyValuePair <List <int>, float[, ]> seg = FindLongestSegment(item, Threshold, locPosMol.posmol1, locPosMol.posmol2);
                if (seg.Key != null && (bestpair.Equals(default(KeyValuePair <List <int>, float[, ]>)) || bestpair.Key.Count < seg.Key.Count))
                {
                    bestpair = seg;
                }
            }

            if (!bestpair.Equals(default(KeyValuePair <List <int>, float[, ]>)))
            {
                if (bestpair.Key == null)
                {
                    return(0);
                }
                else
                {
                    return(bestpair.Key.Count * 100 / pdbs.molDic[refStructure].molLength);
                }
            }


            return(0);
        }
Exemplo n.º 6
0
        public override int GetDistance(string refStructure, string modelStructure)
        {
            int seedL = 4;
            //float maxDist = 3.5f;
            float maxDist = 5.0f;

            if (!pdbs.molDic.ContainsKey(refStructure) || !pdbs.molDic.ContainsKey(modelStructure))
            {
                return(errorValue);
            }


            posMOL locPosMol = Optimization.PrepareData(pdbs.molDic[refStructure], pdbs.molDic[modelStructure]);

            KeyValuePair <List <int>, float[, ]> seg = FindLongestSegment(seedL, maxDist, locPosMol.posmol1, locPosMol.posmol2);

            if (seg.Key == null)
            {
                return(0);
            }

            float sum   = 0;
            float mDist = maxDist * maxDist;
            float rmsd  = 0;

            foreach (var item in seg.Key)
            {
                float dist = 0;
                dist  = calcDist(locPosMol.posmol1, seg.Value, item);
                rmsd += dist;
                dist *= dist;
                sum  += 100 / (1 + dist / mDist);
            }
            rmsd /= seg.Key.Count;
            return(100 - (int)((sum / pdbs.molDic[refStructure].molLength)));//locPosMol.posmol1.GetLength(0)));
        }
Exemplo n.º 7
0
        private void PreparePDBPos()
        {
            //Check if all alignm have the same length
            foreach (var item in pdbs.molDic)
            {
                foreach (var itemIndex in item.Value.indexMol)
                {
                    if (itemIndex == -1)
                    {
                        return;
                    }
                }
            }
            pdbPos = new float[structures.Count][, ];
            for (int i = 0; i < structures.Count; i++)
            {
                pdbPos[i] = new float[pdbs.molDic[structures[0]].indexMol.Length, 3];
            }
            float [] center = new float [3];
            for (int i = 0; i < structures.Count; i++)
            {
                int count = 0;

                for (int j = 0; j < pdbs.molDic[structures[i]].mol.Residues.Count; j++)
                {
                    for (int n = 0; n < pdbs.molDic[structures[i]].mol.Residues[j].Atoms.Count; n++)
                    {
                        pdbPos[i][count, 0]   = pdbs.molDic[structures[i]].mol.Residues[j].Atoms[n].Position.X;
                        pdbPos[i][count, 1]   = pdbs.molDic[structures[i]].mol.Residues[j].Atoms[n].Position.Y;
                        pdbPos[i][count++, 2] = pdbs.molDic[structures[i]].mol.Residues[j].Atoms[n].Position.Z;
                    }
                }

                Optimization.CenterMol(pdbPos[i], center);
            }
        }
Exemplo n.º 8
0
        KeyValuePair <List <int>, float[, ]> Extend(List <int> cList, List <int> bestList, float[,] pMol1, float[,] pMol2, float [,] copyMol, float maxDist)
        {
            int loopK = 3;

            float[,] transMol = null;
            float[,] cMol1    = new float[pMol1.GetLength(0), pMol1.GetLength(1)];
            float[,] cMol2    = new float[pMol2.GetLength(0), pMol2.GetLength(1)];
            List <int> locList = new List <int>(cList);

            for (int i = 0; i < loopK; i++)
            {
                Buffer.BlockCopy(pMol2, 0, cMol2, 0, pMol2.Length * sizeof(float));
                Buffer.BlockCopy(pMol1, 0, cMol1, 0, pMol1.Length * sizeof(float));
                transMol = Rotate(locList, cMol1, cMol2, copyMol);

                if (transMol == null)
                {
                    return(new KeyValuePair <List <int>, float[, ]>(null, null));
                }

                locList.Clear();
                float val = (i + 1) * maxDist / loopK;
                for (int j = 0; j < cMol1.GetLength(0); j++)
                {
                    if (calcDist(transMol, cMol1, j) < val)
                    {
                        locList.Add(j);
                    }
                }
                if (locList.Count <= 1)
                {
                    break;
                }
            }
            if (bestList != null && bestList.Count > locList.Count || locList.Count < 2)
            {
                return(new KeyValuePair <List <int>, float[, ]>(locList, transMol));
            }

            float[,] indexMol1;
            float[,] indexMol2;
            indexMol1 = new float[locList.Count, 3];
            indexMol2 = new float[locList.Count, 3];
            for (int j = 0; j < locList.Count; j++)
            {
                for (int l = 0; l < 3; l++)
                {
                    indexMol1[j, l] = pMol1[locList[j], l];
                    indexMol2[j, l] = pMol2[locList[j], l];
                }
            }
            float[] center = new float[3];

            //opt.CenterMols(indexMol1, indexMol2);
            Optimization.CenterMol(indexMol1, center);
            Optimization.TransVec(pMol1, center);
            Optimization.CenterMol(indexMol2, center);
            Optimization.TransVec(pMol2, center);

            transMol = Rotate(locList, pMol1, pMol2, copyMol);
            if (transMol == null)
            {
                return(new KeyValuePair <List <int>, float[, ]>(null, null));
            }

            for (int j = locList.Count - 1; j >= 0; j--)
            {
                float ww = calcDist(transMol, pMol1, locList[j]);
                if (ww > maxDist)
                {
                    locList.RemoveAt(j);
                }
            }


            return(new KeyValuePair <List <int>, float[, ]>(locList, transMol));
        }
Exemplo n.º 9
0
 static public void CenterMol(float[,] mol1, float [] cent1)
 {
     Optimization.FindCenter(mol1, cent1);
     Optimization.TransVec(mol1, cent1);
 }