// ############################## START FUNC ############################################ // This function check all atoms in possiblechirlist. The main loop walk through all atom-ID and // tests them in possiblechirlist, else continue. If // it will be sorted correctly in JavaScript function dim3mak(dump, possiblechirlist, atom_sorts, mconn, x, y, z, allcarbon) { // All sequences which do not equal another from the same start atom in priority // is now (better) listed in dump. var number_of_atoms = atom_sorts.length; var thjalp=0; var comb1=new Array(0); var n=0; var q=0; var m=0; // thjalp1 can eventually be erased and replaced with n var thjalp1=0; var saml2 = ""; var tempx = new Array(0); var tempy = new Array(0); var tempz = new Array(0); var distance=0; var vinkel=0; var vinkel2=0; var quote1=0; var quote2=0; var collect=""; var chirallistS = new List("empty", 0, atom_sorts); // the last to make it simple var chirallistR = new List("empty", 0, atom_sorts); for(n=0;n-1){ comb1[thjalp]=mconn[thjalp1][q]+" "; } else{ // If one branch consists of hydrogen, it is not listed as a branch, but the main // atom can still be chiral. Therefore comb1[0] is set to the atom-ID for the // hydrogen. Lower ranked branches is always put in lower vector variables. Then // all vector variables are joined to a string so that empty varables disappear. if(atom_sorts[mconn[thjalp1][q]]==1) comb1[0]=mconn[thjalp1][q]+" "; } } saml2=comb1.join(""); // The last " " from branch 4 is chopped off. saml2=saml2.substring(0,saml2.length-1); comb1=saml2.split(" "); // In the following part of the loop configuration is determined by a template. // Note that this continue line just quit the calculation for that n, just like // the earlier continue line. The required number 4 INCLUDES eventually one // hydrogen. Read the comment above. // -------------- Continue command ------------------- if(comb1.length<4) continue; // --------------------------------------------------- tempx=new Array(4); tempy=new Array(4); tempz=new Array(4); for(m=0;m<4;m++){ // Instead of calculating the distance again, it could be captured from the distance matrix, // like this: distance = connetion_matrix[thjalp1][comb1[m]]; // However, with this approach, that matrix can be deleted before and memory saved distance = Math.sqrt(Math.pow(x[thjalp1]-x[comb1[m]],2)+Math.pow(y[thjalp1]-y[comb1[m]],2)+Math.pow(z[thjalp1]-z[comb1[m]],2)); tempx[m]=(x[comb1[m]]-x[thjalp1])/distance tempy[m]=(y[comb1[m]]-y[thjalp1])/distance tempz[m]=(z[comb1[m]]-z[thjalp1])/distance } // By the subtraction of each x, y, z above, the already known chiral atom has been set as origo // with its closest neighbours around in space. tempx[0] is for instance the x value for the // lowest ranked neighbours branch, tempx[3] is the x value for the highest ranked. All bond distances // have been set to 1, so there are only directions left. To compare the configuration with a template // it will be rotated, FIRST around the z-axis in the first loop m=0-3, THEN around the y-axis, // so that the lowest ranked branch is pointing along the z-axis, and then it take a THIRD loop // (thus [z axis, first loop 0-3;] [y axis, second loop 0-3;] [x axis, third loop 0-3;]) // m=0-3 to get the the second lowest neighbour atom fairly pointing along the y-axis. Then it // is determined which of the remaining branches that is closest to which atom in the template. // There are not even any distance range needed. Bigger and smaller is enough. // r is the length of each vector in the xy-plane r=Math.sqrt(Math.pow(tempx[0],2)+Math.pow(tempy[0],2)); // The angle for the lowest ranked branch in the xy-plane is set to 0 and // the first loop for rotating bond angle 0-3 begins. vinkel=Math.acos(tempx[0]/r)*sign(tempy[0]); for(m=0;m<4;m++){ // There is a common technuiqe for rotation which looks something like this // x-after = x-before * cos(rotation_angle) - y-before * sin(rotation_angle) // y-after = x-before * sin(rotation_angle) - y-before * cos(rotation_angle) // which would look something like: // tempx[m]=tempx[m]*Math.cos(-vinkel)-tempy[m]*Math.sin(-vinkel); and so on // At least the second action look a bit suspicious, and has not worked here. // To ensure that all signs occurs correctly even for big rotation angles // I make the angle of each bond 0-3 explicit and adds the rotation angle. // From there, I get the new x, y, z in each case. r=Math.sqrt(Math.pow(tempx[m],2)+Math.pow(tempy[m],2)); vinkel2=Math.acos(tempx[m]/r)*sign(tempy[m]); vinkel2=vinkel2-vinkel; tempx[m]=Math.cos(vinkel2)*r; tempy[m]=Math.sin(vinkel2)*r; } // r is the length of each vector in (OBS!) the xz-plane r=Math.sqrt(Math.pow(tempx[0],2)+Math.pow(tempz[0],2)); // The angle for the lowest branch in the xz-plane is set to 0 // and next rotation is completed for all bonds 0-3 vinkel=Math.acos(tempx[0]/r)*sign(tempz[0]); for(m=0;m<4;m++){ r=Math.sqrt(Math.pow(tempx[m],2)+Math.pow(tempz[m],2)); vinkel2=Math.acos(tempx[m]/r)*sign(tempz[m]); vinkel2=vinkel2-vinkel; tempx[m]=Math.cos(vinkel2)*r; tempz[m]=Math.sin(vinkel2)*r; } // r is the length of each vector in the (OBS!) yz-plane r=Math.sqrt(Math.pow(tempy[1],2)+Math.pow(tempz[1],2)); // Branch 2 is set to zero in the yz-plane vinkel=Math.acos(tempy[1]/r)*sign(tempz[1]); for(m=0;m<4;m++){ r=Math.sqrt(Math.pow(tempy[m],2)+Math.pow(tempz[m],2)); vinkel2=Math.acos(tempy[m]/r)*sign(tempz[m]); vinkel2=vinkel2-vinkel; tempy[m]=Math.cos(vinkel2)*r; tempz[m]=Math.sin(vinkel2)*r; } // Now, the configuration can be compared with the template. For S-configuration, tempz[2] // must be closer to 0.81 then to -0.81, and tempz[3] must be closer to -0.81 then to 0.81 quote1 = Math.abs(tempz[2]-(-0.81))/(Math.abs(tempz[2]-0.81)+0.000000001); quote2 = Math.abs(tempz[3]-0.81)/(Math.abs(tempz[3]-(-0.81))+0.000000001); // So the first quote must be as big as possible and the second as small as possible for S-configuration // else we are dealing with a R-configuration if(quote1>quote2){ chirallistS.Add(n) } else{ chirallistR.Add(n) } } // The big chirtest-loop ends above // The last "#" in the string collect is chopped off. // In order to get all allcarbons and chiral atoms right all atoms are scanned for(n=0;n