public static float Rmsd(float[,] mol1, float[,] mol2, bool flag) { float rmsd; MultRes res = Optimization.TransMultMatrix(mol1, mol2); Qcp qcp = new Qcp(res.mult, res.val, mol1.GetLength(0)); rmsd = (float)qcp.CalcRmsd(); if (flag) { qcp.CalcRotMatrix(); float[,] rot = new float[3, 3]; /*for (int i = 0; i < 3; i++) * for (int j = 0; j < 3; j++) * rot[i, j] = (float)qcp.rot[i, j];*/ 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; float [,] posMolRot = Optimization.MultMatrixTrans(mol2, rot); // posMolRot = TransMultMatrix(rot,mol2); } return(rmsd); //return MultMatrixTrans(tmp, U); }
//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); }
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); }