/// <summary> /// build crystal from the xml serialization object and full symmetry operators /// </summary> /// <param name="thisEntryCrystal"></param> /// <param name="symOpStrings"></param> /// <param name="fullSymOpStrings"></param> /// <returns></returns> public Dictionary <string, AtomInfo[]> BuildPdbBu(EntryCrystal thisEntryCrystal, string[] symOpStrings, string[] fullSymOpStrings) { SymOperator symOp = new SymOperator(); CrystalInfo crystal1 = thisEntryCrystal.crystal1; Dictionary <string, AtomInfo[]> crystalChainsHash = new Dictionary <string, AtomInfo[]>(); base.cartn2fractMatrix = thisEntryCrystal.scaleCat.ScaleMatrix; base.fract2cartnMatrix = cartn2fractMatrix.Inverse(); AtomInfo[] transformedAtoms = null; SymOpMatrix symOpMatrix = null; //ChainAtoms[] chainAtomsList = thisEntryCrystal.atomCat.ChainAtomList; ChainAtoms[] chainAtomsList = thisEntryCrystal.atomCat.ChainAtomList; for (int i = 0; i < symOpStrings.Length; i++) { if (crystalChainsHash.ContainsKey(symOpStrings[i])) { continue; } string chainId = symOpStrings[i].Substring(0, symOpStrings[i].IndexOf("_")); string symOpString = symOpStrings[i].Substring(symOpStrings[i].IndexOf("_") + 1, symOpStrings[i].Length - symOpStrings[i].IndexOf("_") - 1); int asymCount = 0; for (asymCount = 0; asymCount < chainAtomsList.Length; asymCount++) { string asymChain = chainAtomsList[asymCount].AsymChain; if (asymChain == chainId) { break; } } if (symOpString == origSymOpString) { crystalChainsHash.Add(symOpStrings[i], chainAtomsList[asymCount].CartnAtoms); continue; } // get the symmetry operator matrix if (IsFullSymOpStringAMatrix(fullSymOpStrings[i])) { symOpMatrix = GetSymMatrixFromMatrixString(fullSymOpStrings[i]); transformedAtoms = TransformChainByCartesianSymOp (chainAtomsList[asymCount].CartnAtoms, symOpMatrix); } else { symOpMatrix = symOp.GetSymMatrix(fullSymOpStrings[i], symOpStrings[i]); transformedAtoms = TransformChainBySpecificSymOp(chainAtomsList[asymCount].CartnAtoms, symOpMatrix); } crystalChainsHash.Add(symOpStrings[i], transformedAtoms); } return(crystalChainsHash); }
/// <summary> /// calculate and transfer all chains based on the input symmetry strings /// </summary> /// <param name="thisEntryCrystal"></param> /// <param name="symmetryStrings">digits: 2_565</param> /// <returns></returns> public Dictionary <string, AtomInfo[]> BuildCrystalWithAllChains(EntryCrystal thisEntryCrystal, string[] symmetryStrings) { SymOperator symOp = new SymOperator(); crystal1 = thisEntryCrystal.crystal1; if (AppSettings.symOps == null) { AppSettings.LoadSymOps(); } if (crystal1.spaceGroup == "-") { crystal1.spaceGroup = "P 1"; } SymOpMatrix[] sgSymOpMatrices = AppSettings.symOps.FindSpaceGroup(crystal1.spaceGroup); Dictionary <string, AtomInfo[]> crystalChainsHash = new Dictionary <string, AtomInfo[]>(); cartn2fractMatrix = thisEntryCrystal.scaleCat.ScaleMatrix; fract2cartnMatrix = cartn2fractMatrix.Inverse(); ChainAtoms[] chainAtomsList = thisEntryCrystal.atomCat.ChainAtomList; string symOpString = ""; for (int i = 0; i < symmetryStrings.Length; i++) { for (int asymCount = 0; asymCount < chainAtomsList.Length; asymCount++) { string asymChain = chainAtomsList[asymCount].AsymChain; symOpString = asymChain + "_" + symmetryStrings[i]; if (crystalChainsHash.ContainsKey(symOpString)) { continue; } if (symmetryStrings[i] == origSymOpString) { crystalChainsHash.Add(symOpString, chainAtomsList[asymCount].CartnAtoms); continue; } SymOpMatrix symOpMatrix = symOp.GetSymmetryMatrixFromSymmetryString(sgSymOpMatrices, symmetryStrings[i]); AtomInfo[] transformedAtoms = TransformChainBySpecificSymOp(chainAtomsList[asymCount].CartnAtoms, symOpMatrix); crystalChainsHash.Add(symOpString, transformedAtoms); } } return(crystalChainsHash); }
/// <summary> /// convert a full symmetry string into a regular symmetry string /// e.g. -X+1, -Y+X+1, -Z+2/3 to 3_665 /// here, 3 is the symmetry operator number in the space group /// 665 is the translation vector in 3D /// </summary> /// <param name="fullSymString"></param> /// <param name="sgSymOpMatrices"></param> /// <returns></returns> private string ConvertFullToSymString(string fullSymString, SymOpMatrix[] sgSymOpMatrices) { SymOperator symOp = new SymOperator(); string symOpString = ""; string translateVector = ""; string formattedFullSymString = RetrieveSymStringNoTranslation(fullSymString, ref translateVector); foreach (SymOpMatrix symOpMatrix in sgSymOpMatrices) { symOpString = symOp.ConvertMatrixToSymString(symOpMatrix, 1); int strCompIndex = string.Compare(formattedFullSymString, symOpString); if (strCompIndex == 0) { return(symOpMatrix.symmetryOpNum.ToString() + "_" + translateVector); } } return(""); }
/// <summary> /// /// </summary> /// <param name="atoms"></param> /// <param name="spaceGroup"></param> /// <param name="symOpString"></param> /// <returns></returns> public AtomInfo[] TransformChainBySpecificSymOp(AtomInfo[] atoms, string spaceGroup, string symOpString) { if (symOpString == origSymOpString) { return(atoms); } if (AppSettings.symOps == null) { AppSettings.LoadSymOps(); } SymOperator symOp = new SymOperator(); SymOpMatrix[] sgSymOpMatrices = AppSettings.symOps.FindSpaceGroup(spaceGroup); SymOpMatrix symOpMatrix = symOp.GetSymmetryMatrixFromSymmetryString(sgSymOpMatrices, symOpString); AtomInfo[] transformedAtoms = TransformChainBySpecificSymOp(atoms, symOpMatrix); return(transformedAtoms); }
/// <summary> /// build crystal from the xml serialization object and full symmetry operators /// </summary> /// <param name="thisEntryCrystal"></param> /// <param name="symOpStrings"></param> /// <param name="fullSymOpStrings"></param> /// <returns></returns> public Dictionary <string, AtomInfo[]> BuildCrystal(EntryCrystal thisEntryCrystal, string[] symOpStrings, string[] fullSymOpStrings) { SymOperator symOp = new SymOperator(); crystal1 = thisEntryCrystal.crystal1; Dictionary <string, AtomInfo[]> crystalChainsHash = new Dictionary <string, AtomInfo[]>(); cartn2fractMatrix = thisEntryCrystal.scaleCat.ScaleMatrix; fract2cartnMatrix = cartn2fractMatrix.Inverse(); //ChainAtoms[] chainAtomsList = thisEntryCrystal.atomCat.ChainAtomList; ChainAtoms[] chainAtomsList = new ChainAtoms [thisEntryCrystal.atomCat.ChainAtomList.Length]; switch (atomType) { case "CA": chainAtomsList = thisEntryCrystal.atomCat.CalphaAtomList(); // clear the whole atom list,free memory thisEntryCrystal.atomCat.ChainAtomList = null; break; case "CB": chainAtomsList = thisEntryCrystal.atomCat.CbetaAtomList(); // clear the whole atom list, free memory thisEntryCrystal.atomCat.ChainAtomList = null; break; case "CA_CB": chainAtomsList = thisEntryCrystal.atomCat.CalphaCbetaAtomList(); // clear the whole atom list, free memory thisEntryCrystal.atomCat.ChainAtomList = null; break; case "ALL": chainAtomsList = thisEntryCrystal.atomCat.ChainAtomList; break; default: break; } for (int i = 0; i < symOpStrings.Length; i++) { if (crystalChainsHash.ContainsKey(symOpStrings[i])) { continue; } string chainId = symOpStrings[i].Substring(0, symOpStrings[i].IndexOf("_")); string symOpString = symOpStrings[i].Substring(symOpStrings[i].IndexOf("_") + 1, symOpStrings[i].Length - symOpStrings[i].IndexOf("_") - 1); int asymCount = 0; for (asymCount = 0; asymCount < chainAtomsList.Length; asymCount++) { string asymChain = chainAtomsList[asymCount].AsymChain; if (asymChain == chainId) { break; } } if (symOpString == origSymOpString) { crystalChainsHash.Add(symOpStrings[i], chainAtomsList[asymCount].CartnAtoms); continue; } SymOpMatrix symOpMatrix = symOp.GetSymMatrix(fullSymOpStrings[i], symOpStrings[i]); AtomInfo[] transformedAtoms = TransformChainBySpecificSymOp(chainAtomsList[asymCount].CartnAtoms, symOpMatrix); crystalChainsHash.Add(symOpStrings[i], transformedAtoms); } return(crystalChainsHash); }
/// <summary> /// build base unit cell of a crystal from atom coordinates from XML file, /// using symmetry operations provided as parameters /// </summary> /// <param name="crystalXmlFile">our own crystal XML file</param> /// <param name="symOpStrings">specified symmetry operators</param> public Dictionary <string, AtomInfo[]> BuildCrystal(string crystalXmlFile, string[] symOpStrings) { SymOperator symOp = new SymOperator(); // read data from crystal xml file EntryCrystal thisEntryCrystal; XmlSerializer xmlSerializer = new XmlSerializer(typeof(EntryCrystal)); FileStream xmlFileStream = new FileStream(crystalXmlFile, FileMode.Open); thisEntryCrystal = (EntryCrystal)xmlSerializer.Deserialize(xmlFileStream); crystal1 = thisEntryCrystal.crystal1; xmlFileStream.Close(); Dictionary <string, AtomInfo[]> crystalChainsHash = new Dictionary <string, AtomInfo[]>(); if (AppSettings.symOps == null) { AppSettings.LoadSymOps(); } if (crystal1.spaceGroup == "-" || crystal1.spaceGroup == "") { crystal1.spaceGroup = "P 1"; } SymOpMatrix[] sgSymOpMatrices = AppSettings.symOps.FindSpaceGroup(crystal1.spaceGroup); if (sgSymOpMatrices == null) { throw new Exception("No symmetry operators provided for this entry " + crystalXmlFile); } cartn2fractMatrix = thisEntryCrystal.scaleCat.ScaleMatrix; fract2cartnMatrix = cartn2fractMatrix.Inverse(); // ChainAtoms[] chainAtomsList = thisEntryCrystal.atomCat.ChainAtomList; ChainAtoms[] chainAtomsList = new ChainAtoms [thisEntryCrystal.atomCat.ChainAtomList.Length]; switch (atomType) { case "CA": chainAtomsList = thisEntryCrystal.atomCat.CalphaAtomList(); // clear the whole atom list,free memory thisEntryCrystal.atomCat.ChainAtomList = null; break; case "CB": chainAtomsList = thisEntryCrystal.atomCat.CbetaAtomList(); // clear the whole atom list, free memory thisEntryCrystal.atomCat.ChainAtomList = null; break; case "CA_CB": chainAtomsList = thisEntryCrystal.atomCat.CalphaCbetaAtomList(); // clear the whole atom list, free memory thisEntryCrystal.atomCat.ChainAtomList = null; break; case "ALL": chainAtomsList = thisEntryCrystal.atomCat.ChainAtomList; break; default: break; } // just in case, something is messed up. It should not happen often. // may hide some bugs // add on Feb. 20, 2009 bool chainFound = false; for (int i = 0; i < symOpStrings.Length; i++) { string chainId = symOpStrings[i].Substring(0, symOpStrings[i].IndexOf("_")); string symOpString = symOpStrings[i].Substring(symOpStrings[i].IndexOf("_") + 1, symOpStrings[i].Length - symOpStrings[i].IndexOf("_") - 1); int asymCount = 0; chainFound = false; for (asymCount = 0; asymCount < chainAtomsList.Length; asymCount++) { string asymChain = chainAtomsList[asymCount].AsymChain; if (asymChain == chainId) { chainFound = true; break; } } if (!chainFound) { continue; } if (symOpString == origSymOpString) { crystalChainsHash.Add(symOpStrings[i], chainAtomsList[asymCount].CartnAtoms); continue; } try { SymOpMatrix symOpMatrix = symOp.GetSymmetryMatrixFromSymmetryString(sgSymOpMatrices, symOpString); AtomInfo[] transformedAtoms = TransformChainBySpecificSymOp(chainAtomsList[asymCount].CartnAtoms, symOpMatrix); crystalChainsHash.Add(symOpStrings[i], transformedAtoms); } catch { continue; } } return(crystalChainsHash); }