/// <summary> /// Carrega em memória os valores da "Matriz energética" /// </summary> public static void LoadEnergeticMatrix(Param param) { int N = GCPS.chain.r.Count; //número de residuos GCPS.energeticMatrix = new double[N, N]; //Matriz M quadrada (NxN) for (int i = 0; i < (N - 1); i++) { for (int j = i + 1; j < N; j++) { if (i == j) { GCPS.energeticMatrix[i, j] = 0; } else { double r = 0; if (GCPS.modelType == 0) { //0-Randon //Sorteio randomico Randomic.Random(); r = (Randomic.randu * 2) - 1; //R´=(R*2)-1 } else if (GCPS.modelType == 1) { //1-H (Hidrofobico) r = -1; } else if (GCPS.modelType == 2) { //2-P (Polar) r = 1; } else //if (GCPS.modelType == 2) { //3-HP;4-estero-quimico,5-GO //O AJUSTE SOMENTE É VALIDO PARA MODELO HP //Onde: H=-, P=+ //Sendo: Eij(H,H) = -1, Eij(H,P)=0, Eij(P,P)= +1 if (param.model[i].value == -1 && param.model[j].value == -1) { r = -1; } else if (param.model[i].value == 1 && param.model[j].value == 1) { r = 1; } } GCPS.energeticMatrix[i, j] = r; GCPS.energeticMatrix[j, i] = r; } } } }
/// <summary> /// Sorteia o Monomero o qual ocorreá a tentiva de movimento /// </summary> /// <returns>Retorna a posição do Monomero</returns> public static void SortMoviment() { Randomic.Random(); int selectNode = (int)(Randomic.randu * GCPS.chain.r.Count); GCPS.chain.selectNode = GCPS.tempChain.selectNode = selectNode; }
/// <summary> /// Prepara aplicação para gerar uma nova ISEM /// </summary> public static void ClearAppToGenNewIsem() { GCPS.chain.r.Clear(); Randomic.Random(); GCPS.initialIsem = AppConfigClient.Param.dataToProcess.isem < 0 ? (AppConfigClient.Param.dataToProcess.isem * -1) : AppConfigClient.Param.dataToProcess.isem; GCPS.chain.isem = GCPS.initialIsem; GCPS.chain.chainTypes = null; }
/// <summary> /// Rotina o qual costroi a cadeia de monomeros /// </summary> /// <param name="lastValed">posição do último monomero válido</param> public static void CreateStruct(ref int lastValed) { while (GCPS.chain.r.Count < AppConfigClient.Param.dataToProcess.totalSitio) { BasicStructs.Point tempCoord = new BasicStructs.Point(); //Crio uma coordenada temporária lastValed = GCPS.chain.r.Count - 1; tempCoord.x = GCPS.chain.r[lastValed].x; //Copia o último ponto válido para a coordenada temporária tempCoord.y = GCPS.chain.r[lastValed].y; tempCoord.z = GCPS.chain.r[lastValed].z; tempCoord.deadEndPoints = string.Empty; tempCoord.deadEnd = 0; //Sorteira X,Y ou Z Randomic.Random(); if (Randomic.randu < Consts.rXYZ) //X { Randomic.Random(); tempCoord.x = Randomic.randu < 0.5 ? tempCoord.x - 1 : tempCoord.x + 1; //escolhe +/- 1 } else if (Randomic.randu < (Consts.rXYZ * 2)) //Y { Randomic.Random(); tempCoord.y = Randomic.randu < 0.5 ? tempCoord.y - 1 : tempCoord.y + 1; //escolhe +/- 1 } else { //Z Randomic.Random(); tempCoord.z = Randomic.randu < 0.5 ? tempCoord.z - 1 : tempCoord.z + 1; //escolhe +/- 1 } //aidiconar valor de enegia inicial tempCoord.e = new List <TypeE>(); //adiciona o novo ponto GCPS.chain.r.Add(tempCoord); } }
/// <summary> /// Cria um Monometro /// </summary> /// <param name="tempCoord"></param> public static void CreateMono(ref BasicStructs.Point tempCoord) { tempCoord = GCPS.chain.r[GCPS.chain.r.Count - 1]; //Copia o último ponto válido para a coordenada temporária //Sorteira X,Y ou Z Randomic.Random(); if (Randomic.randu < Consts.rXYZ) //X { Randomic.Random(); tempCoord.x = Randomic.randu < 0.5 ? tempCoord.x - 1 : tempCoord.x + 1; //escolhe +/- 1 } else if (Randomic.randu < (Consts.rXYZ * 2)) //Y { Randomic.Random(); tempCoord.y = Randomic.randu < 0.5 ? tempCoord.y - 1 : tempCoord.y + 1; //escolhe +/- 1 } else { //Z Randomic.Random(); tempCoord.z = Randomic.randu < 0.5 ? tempCoord.z - 1 : tempCoord.z + 1; //escolhe +/- 1 } }
/// <summary> /// Sortei qual a posibilidade de moviment entre 1 e lenght /// </summary> /// <returns></returns> internal static int SortPossibilities(int lenght) { Randomic.Random(); int ret = (int)(Randomic.randu * lenght); //Caso ocorra algum erro no sorteio o algoritmo finaliza a execução if (ret < 0 || ret > lenght) { new GridProteinFolding.Middle.Helpers.LoggingHelpers.Log().ErroParseMoves(new Middle.Helpers.LoggingHelpers.User_Defined_Exceptions.ErroParseMovesException("SortCrankShaftMove"), Types.ErrorLevel.None); throw new System.Exception(); //CustomMessage customMessage = new CustomMessage(); //throw new CustomException(SeverityLevel.Critical, // LogLevel.Event, // new ErroParseMoves("SortCrankShaftMove Exception"), // customMessage.GetString("SortCrankShaftMove")); } else { return(ret); } }
/// <summary> /// Este Metodo executa o movimento de End. /// </summary> /// <returns>Return TRUE se o movimento ocorreu</returns> public bool Do() { Structs.BasicStructs.Point r1; Structs.BasicStructs.Point r2; if (GCPS.chain.selectNode == 0) { //r1 = Members.monomero.r[Members.monomero.selectNode]; //r2 = Members.monomero.r[Members.monomero.selectNode + 1]; //copia dos dados do monomero para movimento r1 = new Structs.BasicStructs.Point() { x = GCPS.chain.r[GCPS.chain.selectNode].x, y = GCPS.chain.r[GCPS.chain.selectNode].y, z = GCPS.chain.r[GCPS.chain.selectNode].z }; r1.e = new List <TypeE>(); r1.e.AddRange(GCPS.chain.r[GCPS.chain.selectNode].e); //copia dos dados do monomero para movimento r2 = new Structs.BasicStructs.Point() { x = GCPS.chain.r[GCPS.chain.selectNode + 1].x, y = GCPS.chain.r[GCPS.chain.selectNode + 1].y, z = GCPS.chain.r[GCPS.chain.selectNode + 1].z }; r2.e = new List <TypeE>(); r2.e.AddRange(GCPS.chain.r[GCPS.chain.selectNode + 1].e); } else { //r1 = Members.monomero.r[Members.monomero.selectNode]; //r2 = Members.monomero.r[Members.monomero.selectNode - 1]; //copia dos dados do monomero para movimento r1 = new Structs.BasicStructs.Point() { x = GCPS.chain.r[GCPS.chain.selectNode].x, y = GCPS.chain.r[GCPS.chain.selectNode].y, z = GCPS.chain.r[GCPS.chain.selectNode].z }; r1.e = new List <TypeE>(); r1.e.AddRange(GCPS.chain.r[GCPS.chain.selectNode].e); //copia dos dados do monomero para movimento r2 = new Structs.BasicStructs.Point() { x = GCPS.chain.r[GCPS.chain.selectNode - 1].x, y = GCPS.chain.r[GCPS.chain.selectNode - 1].y, z = GCPS.chain.r[GCPS.chain.selectNode - 1].z }; r2.e = new List <TypeE>(); r2.e.AddRange(GCPS.chain.r[GCPS.chain.selectNode - 1].e); } //Vetor p, como sendo a difereça entre os vetores posuicao do residuo "2" e do residuo "1", isto é: p=r1-r1 Structs.BasicStructs.Point p = new Structs.BasicStructs.Point() { x = r2.x - r1.x, y = r2.y - r1.y, z = r2.z - r1.z }; //Definicao dos dois vetores v e w Structs.BasicStructs.Point v; Structs.BasicStructs.Point w; //cria as 3 possibilidades para v e w if (p.x != 0) { v = new Structs.BasicStructs.Point() { x = 0, y = p.x, z = 0 }; w = new Structs.BasicStructs.Point() { x = 0, y = 0, z = p.x }; } else if (p.y != 0) { v = new Structs.BasicStructs.Point() { x = 0, y = 0, z = p.y }; w = new Structs.BasicStructs.Point() { x = p.y, y = 0, z = 0 }; } else //if (p.z != 0) { v = new Structs.BasicStructs.Point() { x = p.z, y = 0, z = 0 }; w = new Structs.BasicStructs.Point() { x = 0, y = p.z, z = 0 }; } //Sorteio do movimento para 4 possibilidades (de 0 à 3) Randomic.Random(); int i = (int)(Randomic.randu * 4); end type = end.none; switch (i) { case 0: //Primeira possibilidade: r1=r2+vi r1.x = r2.x + v.x; r1.y = r2.y + v.y; r1.z = r2.z + v.z; type = end.one; break; case 1: //Segunda possibilidade: r1=r2-vi r1.x = r2.x - v.x; r1.y = r2.y - v.y; r1.z = r2.z - v.z; type = end.two; break; case 2: //Terceira possibilidade: r1=r2+wi r1.x = r2.x + w.x; r1.y = r2.y + w.y; r1.z = r2.z + w.z; type = end.three; break; case 3: //Quarta possibilidade: r1=r2-wi r1.x = r2.x - w.x; r1.y = r2.y - w.y; r1.z = r2.z - w.z; type = end.four; break; default: new GridProteinFolding.Middle.Helpers.LoggingHelpers.Log().Exception(new System.Exception("Error ends.."), Types.ErrorLevel.Warning); break; } //GICO.WriteLine("{0} {1} {2}", r1.x, r1.y, r1.z); //Verifica a aceitação do movimento if (TryMove(ref r1)) // && TryMovePeerDPP(ref pointSorted, (Structs.Point)Members.monomero.r[neighborNode])) { GCPS.tempChain.r[GCPS.chain.selectNode] = r1; GCPS.tempChain.contMoves.endsAccept++; switch (type) { case end.one: GCPS.tempChain.contMoves.moveSetEnd.endAccept_1++; break; case end.two: GCPS.tempChain.contMoves.moveSetEnd.endAccept_2++; break; case end.three: GCPS.tempChain.contMoves.moveSetEnd.endAccept_3++; break; case end.four: GCPS.tempChain.contMoves.moveSetEnd.endAccept_4++; break; } GCPS.tempChain.typeOfLattice = BasicEnums.Lattices.End; return(true); } else { GCPS.chain.contMoves.endsReject++; switch (type) { case end.one: GCPS.chain.contMoves.moveSetEnd.endReject_1++; break; case end.two: GCPS.chain.contMoves.moveSetEnd.endReject_2++; break; case end.three: GCPS.chain.contMoves.moveSetEnd.endReject_3++; break; case end.four: GCPS.chain.contMoves.moveSetEnd.endReject_4++; break; } return(false); } }
/// <summary> /// Sorteia o randomico para R /// </summary> /// <returns>Retorna a posição do Monomero</returns> private static double RandomR() { Randomic.Random(); return(Randomizer.Randomic.randu * 1); }
/// <summary> /// Executa teste de validação de MONOMERO seleciona é um crankShaft /// </summary> /// <returns></returns> public bool Do() { int internalSelectNode = GCPS.chain.selectNode; //Movimento de crankShaft é sempre em função de R1 //Abaixo efetuaremos o ajustes do Ri if (GCPS.chain.r[internalSelectNode].classificationMotion.crankShaft__R0) { internalSelectNode++; } else if (GCPS.chain.r[internalSelectNode].classificationMotion.crankShaft__R2) { internalSelectNode--; } else if (GCPS.chain.r[internalSelectNode].classificationMotion.crankShaft__R3) { internalSelectNode = internalSelectNode - 2; } // |P = |v3 - |v0 int Px = GCPS.chain.r[internalSelectNode + 1].x - GCPS.chain.r[internalSelectNode - 1].x; int Py = GCPS.chain.r[internalSelectNode + 1].y - GCPS.chain.r[internalSelectNode - 1].y; int Pz = GCPS.chain.r[internalSelectNode + 1].z - GCPS.chain.r[internalSelectNode - 1].z; // |Q = |v1 - |v0 int Qx = GCPS.chain.r[internalSelectNode].x - GCPS.chain.r[internalSelectNode - 1].x; int Qy = GCPS.chain.r[internalSelectNode].y - GCPS.chain.r[internalSelectNode - 1].y; int Qz = GCPS.chain.r[internalSelectNode].z - GCPS.chain.r[internalSelectNode - 1].z; //O vetor |V é perpendicular a |P e a |Q simultaneamente int Vx = (Py * Qz) - (Qy * Pz); //em direção de X int Vy = (Pz * Qx) - (Qz * Px); //em direção de Y int Vz = (Px * Qy) - (Qx * Py); //em direção de Z //Tres possibilidades de movimento (3) int R_x = 0; int R_y = 0; int R_z = 0; int R_x_1 = 0; int R_y_1 = 0; int R_z_1 = 0; //Sorteio do movimento Randomic.Random(); int sort = (int)(Randomic.randu * 3); crankshaft type = crankshaft.none; switch (sort) { case 0: //Primeira possibilidade (1) //onde |r´i = |ri-1 + |V R_x = GCPS.chain.r[internalSelectNode - 1].x + Vx; R_y = GCPS.chain.r[internalSelectNode - 1].y + Vy; R_z = GCPS.chain.r[internalSelectNode - 1].z + Vz; //onde |r´i+1 = |ri+2 + |V R_x_1 = GCPS.chain.r[internalSelectNode + 2].x + Vx; R_y_1 = GCPS.chain.r[internalSelectNode + 2].y + Vy; R_z_1 = GCPS.chain.r[internalSelectNode + 2].z + Vz; type = crankshaft.one; break; case 1: //Segunda possibilidade (2) //onde |r´i = |ri-1 - |V R_x = GCPS.chain.r[internalSelectNode - 1].x - Vx; R_y = GCPS.chain.r[internalSelectNode - 1].y - Vy; R_z = GCPS.chain.r[internalSelectNode - 1].z - Vz; //onde |r´i+1 = |ri+2 - |V R_x_1 = GCPS.chain.r[internalSelectNode + 2].x - Vx; R_y_1 = GCPS.chain.r[internalSelectNode + 2].y - Vy; R_z_1 = GCPS.chain.r[internalSelectNode + 2].z - Vz; type = crankshaft.two; break; case 2: //Terceira possibilidade (3) //onde |r´i = |ri-1 - |Q R_x = GCPS.chain.r[internalSelectNode - 1].x - Qx; R_y = GCPS.chain.r[internalSelectNode - 1].y - Qy; R_z = GCPS.chain.r[internalSelectNode - 1].z - Qz; //onde |r´i+1 = |ri+2 - |Q R_x_1 = GCPS.chain.r[internalSelectNode + 2].x - Qx; R_y_1 = GCPS.chain.r[internalSelectNode + 2].y - Qy; R_z_1 = GCPS.chain.r[internalSelectNode + 2].z - Qz; type = crankshaft.three; break; default: new GridProteinFolding.Middle.Helpers.LoggingHelpers.Log().Exception(new System.Exception("Error Sort"), Types.ErrorLevel.Warning); break; } Structs.BasicStructs.Point temp01 = new Structs.BasicStructs.Point() { x = R_x, y = R_y, z = R_z }; temp01.e = new List <TypeE>(); temp01.e.AddRange(GCPS.chain.r[internalSelectNode].e); Structs.BasicStructs.Point temp02 = new Structs.BasicStructs.Point() { x = R_x_1, y = R_y_1, z = R_z_1 }; temp02.e = new List <TypeE>(); temp02.e.AddRange(GCPS.chain.r[internalSelectNode + 1].e); if (TryMove(ref temp01) && TryMove(ref temp02)) { GCPS.tempChain.r[internalSelectNode] = temp01; GCPS.tempChain.r[internalSelectNode + 1] = temp02; GCPS.tempChain.contMoves.crankshaftAccept++; switch (type) { case crankshaft.one: GCPS.tempChain.contMoves.moveSetCrankshaft.crankshaftAccept_1++; break; case crankshaft.two: GCPS.tempChain.contMoves.moveSetCrankshaft.crankshaftAccept_2++; break; case crankshaft.three: GCPS.tempChain.contMoves.moveSetCrankshaft.crankshaftAccept_3++; break; } GCPS.tempChain.typeOfLattice = BasicEnums.Lattices.Crank; return(true); } else { GCPS.chain.contMoves.crankshaftReject++; switch (type) { case crankshaft.one: GCPS.chain.contMoves.moveSetCrankshaft.crankshaftReject_1++; break; case crankshaft.two: GCPS.chain.contMoves.moveSetCrankshaft.crankshaftReject_2++; break; case crankshaft.three: GCPS.chain.contMoves.moveSetCrankshaft.crankshaftReject_3++; break; } return(false); } }