public void clearSelection() { foreach (BallUpdate comp in selections) { // comp.independant = false; comp.SetRayonFactor(UI.GUIMoleculeController.globalRadius); comp.AtomColor = MoleculeModel.GetAtomColor(MoleculeModel.atomsTypelist[(int)comp.number].type); } selections.Clear(); }
/* * private string GetClosest(Vector3 pos) { * float minDist = float.MaxValue; * float dist; * string type = ""; * for(int i=0; i<locations.Count; i++) { * dist = Vector3.SqrMagnitude(pos - locations[i]); * if (dist < minDist) { * minDist = dist; * type = types[i]; * } * } * return type; * } * * private void ColorVerticesWithLists(Mesh mesh) { * int nbVertices = mesh.vertices.Length; * Vector3[] vertices = mesh.vertices; * Color32[] meshColors = new Color32[nbVertices]; * string type; * * for(int i=0; i<nbVertices; i++) { * type = GetClosest(vertices[i]); * meshColors[i] = AtomModel.GetAtomColor(type); * } * mesh.colors32 = meshColors; * } */ private void ColorVertices(Mesh mesh) { int nbVertices = mesh.vertices.Length; float valtype; List <float> BFactorList = MoleculeModel.BFactorList; Vector3[] vertices = mesh.vertices; Color32[] meshColors = new Color32[nbVertices]; if (slowColoring) { List <float[]> atomLocs = MoleculeModel.atomsLocationlist; atomLocations = new List <Vector3>(); for (int i = 0; i < atomLocs.Count; i++) { atomLocations.Add(new Vector3(atomLocs[i][0], atomLocs[i][1], atomLocs[i][2])); } atomColors = MoleculeModel.atomsColorList; } string type; for (int i = 0; i < nbVertices; i++) { //if(UI.UIData.atomtype == UI.UIData.AtomType.particleball){ type = atomTree.GetClosestAtomType(vertices[i]); if (UI.UIData.surfColChain) { Ribbons.InitCol(); meshColors[i] = Ribbons.GetColorChain(type); } else if (UI.UIData.surfColHydroKD) { HydrophobicScales.InitKyteDoo(); meshColors[i] = HydrophobicScales.GetColorHydro(type); } else if (UI.UIData.surfColHydroEng) { HydrophobicScales.InitEngleman(); meshColors[i] = HydrophobicScales.GetColorHydro(type); } else if (UI.UIData.surfColHydroEis) { HydrophobicScales.InitEisenberg(); meshColors[i] = HydrophobicScales.GetColorHydro(type); } else if (UI.UIData.surfColPChim) { HydrophobicScales.InitPhysChim(); meshColors[i] = HydrophobicScales.GetColorHydro(type); } else if (UI.UIData.surfColHydroWO) { HydrophobicScales.InitWhiteOct(); meshColors[i] = HydrophobicScales.GetColorHydro(type); } else if (UI.UIData.surfColBF) { valtype = float.Parse(type); if (valmax == 0) { valmin = BFactorRep.GetMin(BFactorList); valmax = BFactorRep.GetMax(BFactorList); } valtype = (valtype - valmin) / (valmax - valmin); bftype = BFactorRep.GetBFStyle(valtype); meshColors[i] = AtomModel.GetModel(bftype).baseColor; } else { meshColors[i] = MoleculeModel.GetAtomColor(type); } //This part of the code wasn't working //Anyway i dunno why we want to use another way to color surfaces when not in particles mode //} /*else * if(slowColoring){ * meshColors[i] = GetClosestAtomColor(vertices[i]); * }else{ * type = atomTree.GetClosestAtomType(vertices[i]); * meshColors[i] = MoleculeModel.GetAtomColor(type); * //meshColors[i] = atomTree.GetClosestAtomColor(vertices[i]); * }*/ } mesh.colors32 = meshColors; }
// Regex RE = new Regex("\n", RegexOptions.Multiline); // MatchCollection theMatches = RE.Matches(text); // int matchescount=theMatches.Count; public static void ReadPDB(TextReader sr, List <float[]> alist, List <float[]> calist, List <float> BFactorList, List <string> resnamelist, List <string> atomsNameList, List <string> caChainlist, List <AtomModel> typelist, List <string> chainList, List <Color> colorList, List <float[]> sshelixlist, List <float[]> sssheetlist) { string[] dnaBackboneAtoms = new string[] { "C5'" }; List <int> residueIds = new List <int>(); List <int> splits = new List <int>(); List <int> atomsNumberList = new List <int>(); int resNb = 0; int prevRes = int.MinValue; int currentRes = int.MinValue + 1; int nowline = 0; int nbAtoms = 0; int nbTers = 0; string s; int prevresnb = 0; while ((s = sr.ReadLine()) != null) { if (s.StartsWith("ENDMDL")) { break; } if (s.Length > 4) { bool isAtomLine = s.StartsWith("ATOM"); bool isHetAtm = s.StartsWith("HETATM"); bool isHelixLine = s.StartsWith("HELIX"); bool isSheetLine = s.StartsWith("SHEET"); bool isConnectLine = s.StartsWith("CONECT"); if (s.StartsWith("TER")) { splits.Add(resNb); nbTers++; } if (isHelixLine) { string chainh = s.Substring(19, 2).Trim(); string initr = s.Substring(22, 4); string termr = s.Substring(34, 4); string classH = s.Substring(39, 2); string len = s.Substring(72, 5); float[] vect = new float[4]; float initres = float.Parse(initr); float termres = float.Parse(termr); float length = float.Parse(len); float classhelix = 1f; try{ classhelix = float.Parse(classH); }catch { classhelix = float.Parse(s.Substring(38, 2)); } vect[0] = initres; vect[1] = termres; vect[2] = length; vect[3] = classhelix; sshelixlist.Add(vect); MoleculeModel.helixChainList.Add(chainh); } if (isSheetLine) { string chainS = s.Substring(21, 2).Trim(); string initr = s.Substring(23, 4); string termr = s.Substring(34, 4); float[] vect = new float[2]; vect[0] = float.Parse(initr); vect[1] = float.Parse(termr); sssheetlist.Add(vect); MoleculeModel.strandChainList.Add(chainS); } if (UIData.readHetAtom) { isAtomLine = isAtomLine || s.StartsWith("HETATM"); } if (!UIData.readWater) { try{ if ((string)s.Substring(17, 3).Trim() == "HOH") { isAtomLine = false; } }catch { isAtomLine = false; } } if (isAtomLine) { float[] vect = new float[3]; MoleculeModel.atomHetTypeList.Add(s.Split(' ')[0]); string sx = s.Substring(30, 8); string sy = s.Substring(38, 8); string sz = s.Substring(46, 8); string sbfactor = null; bool parseBFactor = false; if (s.Length > 60) { sbfactor = s.Substring(60, 6); parseBFactor = true; } string atomsNumber = s.Substring(6, 5); string typestring = s.Substring(12, 4).Trim(); atomsNameList.Add(typestring); int bout; bool b = int.TryParse(typestring[0].ToString(), out bout); string type; if (b) { type = typestring[1].ToString(); } else { type = typestring[0].ToString(); } string resname = s.Substring(17, 3).Trim(); int resid = int.Parse(s.Substring(22, 4)); residueIds.Add(resid); currentRes = resid; atomsNumberList.Add(int.Parse(atomsNumber)); //Unity has a left-handed coordinates system while PDBs are right-handed //So we have to reverse the X coordinates float x = -float.Parse(sx); float y = float.Parse(sy); float z = float.Parse(sz); float bfactor = 0.0f; if (parseBFactor == true) { bfactor = float.Parse(sbfactor); } vect[0] = x; vect[1] = y; vect[2] = z; //CA case if (typestring[0].ToString() == "C" && typestring.Length > 1) { if (typestring[1].ToString() == "A") { string chaintype = s.Substring(21, 1); calist.Add(vect); caChainlist.Add(chaintype); } } //?? if (dnaBackboneAtoms.Contains(typestring)) { string chaintype = s.Substring(21, 1); calist.Add(vect); caChainlist.Add(chaintype); } if (s.Substring(21, 1) != " ") { string chain = s.Substring(21, 1); chainList.Add(chain); } if (parseBFactor == true) { BFactorList.Add(bfactor); } alist.Add(vect); AtomModel aModel; if (UIData.ffType == UIData.FFType.atomic) { aModel = AtomModel.GetModel(type); } else { aModel = AtomModel.GetModel(typestring); } if (aModel == null) { aModel = AtomModel.GetModel("X"); } typelist.Add(aModel); if (MoleculeModel.sugarResname.Contains(resname)) { MoleculeModel.atomsSugarTypelist.Add(aModel); } if (UIData.ffType == UIData.FFType.atomic) { colorList.Add(MoleculeModel.GetAtomColor(type)); } else { colorList.Add(aModel.baseColor); } resnamelist.Add(resname); if (MoleculeModel.residues.ContainsKey(resid) == false) { MoleculeModel.residues.Add(resid, new ArrayList()); //add the chain name for each residu MoleculeModel.resChainList.Add(s.Substring(21, 1)); //If we have a sugar, we add theses informations in some special list if (MoleculeModel.sugarResname.Contains(resname)) { MoleculeModel.resSugarChainList.Add(s.Substring(21, 1)); } } int curresnb = int.Parse(s.Substring(22, 4)); if (prevresnb == 0 && curresnb != 0) { MoleculeModel.firstresnb = curresnb; } if (curresnb != prevresnb) { MoleculeModel.resChainList2.Add(s.Substring(21, 1)); prevresnb = curresnb; } MoleculeModel.residues[resid].Add(nbAtoms); if (prevRes != currentRes) { resNb++; } prevRes = currentRes; nbAtoms++; //If we have a sugar, we add theses informations in some special list if (MoleculeModel.sugarResname.Contains(resname)) { MoleculeModel.atomsSugarLocationlist.Add(vect); MoleculeModel.atomsSugarResnamelist.Add(resname); MoleculeModel.atomsSugarNamelist.Add(typestring); } } if (isConnectLine) { if (UIData.connectivity_PDB) { string[] splitedStringTemp = s.Split(' '); //0 is Connect, 1 is the atom, 2,3..... is the bounded atoms List <string> splitedString = new List <string>(); for (int j = 0; j < splitedStringTemp.Length; j++) { if (splitedStringTemp[j] != "") { splitedString.Add(splitedStringTemp[j]); } } for (int j = 2; j < splitedString.Count; j++) { MoleculeModel.BondListFromPDB.Add(new int[2] { int.Parse(splitedString[1]) - 1, int.Parse(splitedString[j]) - 1 }); } } } nowline++; } } isDone = true; Ribbons.mustSplitDictList = (nbTers > 1); for (int i = 0; i < typelist.Count; i++) { MoleculeModel.atomsLocalScaleList.Add(100.0f); } foreach (string name in atomsNameList) { if (!MoleculeModel.existingName.Contains(name)) { MoleculeModel.existingName.Add(name); } } // existingRes is created in DisplayMolecule.CheckResidues after looking for protonated HIS foreach (string chain in chainList) { if (!MoleculeModel.existingChain.Contains(chain)) { MoleculeModel.existingChain.Add(chain); } } MoleculeModel.existingName.Sort(); MoleculeModel.existingChain.Sort(); sr.Close(); Debug.Log("typelist:" + typelist.Count); Debug.Log("resnameList:" + resnamelist.Count); Debug.Log("caChainlist:" + caChainlist.Count); Debug.Log("chainlist:" + chainList.Count); Debug.Log("colorList:" + colorList.Count); Debug.Log("atomsLocalScaleList:" + MoleculeModel.atomsLocalScaleList.Count); Debug.Log("BfactorList: " + BFactorList.Count); if (resnamelist.Count == typelist.Count) { UIData.hasResidues = true; } if (chainList.Count == typelist.Count) { UIData.hasChains = true; } MoleculeModel.atomsLocationlist = alist; MoleculeModel.CatomsLocationlist = calist; MoleculeModel.CaSplineChainList = caChainlist; MoleculeModel.atomsTypelist = typelist; MoleculeModel.atomsNamelist = atomsNameList; MoleculeModel.atomsNumberList = atomsNumberList; MoleculeModel.BFactorList = BFactorList; MoleculeModel.atomsResnamelist = resnamelist; MoleculeModel.residueIds = residueIds; MoleculeModel.splits = splits; MoleculeModel.atomsChainList = chainList; MoleculeModel.atomsColorList = colorList; MoleculeModel.ssHelixList = sshelixlist; MoleculeModel.ssStrandList = sssheetlist; //MoleculeModel.residueDictionaries = residueDictList; //Here we will fill the sortedIndex residue by the Chain ID MoleculeModel.sortedResIndexByList = sortResIndex(MoleculeModel.resChainList); MoleculeModel.sortedResIndexByListSugar = sortResIndex(MoleculeModel.resSugarChainList); }