Exemplo n.º 1
0
        /// <summary>
        /// build base unit cell of a crystal from atom coordinates from XML file,
        /// symmetry operators for the space group
        /// </summary>
        /// <param name="crystalXmlFile">our own crystal XML file</param>
        public Dictionary <string, AtomInfo[]> BuildCrystal(string crystalXmlFile)
        {
            // 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();

            if (AppSettings.symOps == null)
            {
                AppSettings.LoadSymOps();
            }
            if (crystal1.spaceGroup == "-")
            {
                crystal1.spaceGroup = "P 1";
            }
            SymOpMatrix[] symOpMatrices = AppSettings.symOps.FindSpaceGroup(crystal1.spaceGroup);
            if (symOpMatrices == 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.ToUpper())
            {
            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;
            }
            Dictionary <string, AtomInfo[]> crystalChainsHash = BuildCrystalBySymOps(chainAtomsList, symOpMatrices);

            return(crystalChainsHash);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xmlFile"></param>
        /// <param name="chainMatrixHash"></param>
        /// <returns></returns>
        public Dictionary<string, AtomInfo[]> BuildOneBuAssembly(string xmlFile, Dictionary<string, List<SymOpMatrix>> chainMatrixHash, string type)
        {
            Dictionary<string, AtomInfo[]> chainCoordHash = new Dictionary<string, AtomInfo[]>();

            // read data from crystal xml file
            EntryCrystal thisEntryCrystal;
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(EntryCrystal));
            FileStream xmlFileStream = new FileStream(xmlFile, FileMode.Open);
            thisEntryCrystal = (EntryCrystal)xmlSerializer.Deserialize(xmlFileStream);
            xmlFileStream.Close();

            ChainAtoms[] chainAtomsList = thisEntryCrystal.atomCat.ChainAtomList;
            ChainAtoms thisChain = null;

            foreach (string asymChain in chainMatrixHash.Keys)
            {
                thisChain = null; // fixed on June 30, 2010
                foreach (ChainAtoms chain in chainAtomsList)
                {
                    if (chain.AsymChain == asymChain)
                    {
                        thisChain = chain;
                        break;
                    }
                }
                if (thisChain == null)
                {
                    continue;
                }
    
                string chainSymOpString = "";
                foreach (SymOpMatrix symMatrix in chainMatrixHash[asymChain])
                {
                    if (symMatrix.symmetryString == "-" || symMatrix.symmetryString == "")
                    {
                        chainSymOpString = asymChain + "_" + symMatrix.symmetryOpNum + "_-";
                    }
                    else
                    {
                        chainSymOpString = asymChain + "_" + symMatrix.symmetryString;

                        if (type == "pisa")
                        {
                            if (symMatrix.symmetryOpNum != "" && symMatrix.symmetryOpNum != "0")
                            {
                                chainSymOpString += ("(" + symMatrix.symmetryOpNum + ")"); // those non-ncs operator (same symmetry string)
                            }
                        }
                    }
                    if (! chainCoordHash.ContainsKey(chainSymOpString))
                    {
                        AtomInfo[] atoms = BuildOneChain(thisChain, symMatrix);
                        chainCoordHash.Add(chainSymOpString, atoms);
                    }
                }
            }
            return chainCoordHash;
        }
Exemplo n.º 3
0
 public ChainAtoms(ChainAtoms extChain)
 {
     this.asymChain   = extChain.AsymChain;
     this.entityId    = extChain.entityId;
     this.polymerType = extChain.PolymerType;
     this.cartnAtoms  = new List <AtomInfo> ();
     foreach (AtomInfo atom in extChain.CartnAtoms)
     {
         this.cartnAtoms.Add((AtomInfo)atom.Clone());
     }
 }
Exemplo n.º 4
0
        public int[] BuildCrystal(EntryCrystal thisEntryCrystal, ref Dictionary <string, AtomInfo[]> crystalChainsHash)
        {
            if (AppSettings.symOps == null)
            {
                AppSettings.LoadSymOps();
            }
            if (crystal1.spaceGroup == "-")
            {
                crystal1.spaceGroup = "P 1";
            }
            SymOpMatrix[] symOpMatrices = AppSettings.symOps.FindSpaceGroup(crystal1.spaceGroup);
            if (symOpMatrices == null)
            {
                throw new Exception("No symmetry operators provided for this entry " + thisEntryCrystal.PdbId);
            }
            cartn2fractMatrix = thisEntryCrystal.scaleCat.ScaleMatrix;
            fract2cartnMatrix = cartn2fractMatrix.Inverse();

            //ChainAtoms[] chainAtomsList = thisEntryCrystal.atomCat.ChainAtomList;
            ChainAtoms[] chainAtomsList = new ChainAtoms [thisEntryCrystal.atomCat.ChainAtomList.Length];
            switch (atomType.ToUpper())
            {
            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;
            }
            crystalChainsHash = BuildCrystalBySymOps(chainAtomsList, symOpMatrices);
            int[] maxSteps = TranslateUnitCell(ref crystalChainsHash);
            return(maxSteps);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xmlFile"></param>
        /// <param name="chainMatrixHash"></param>
        /// <returns></returns>
        public Dictionary<string, AtomInfo[]> BuildOneBuAssembly(EntryCrystal thisEntryCrystal, Dictionary<string, List<SymOpMatrix>> chainMatrixHash, string type)
        {
            Dictionary<string, AtomInfo[]> chainCoordHash = new Dictionary<string,AtomInfo[]> ();

            ChainAtoms[] chainAtomsList = thisEntryCrystal.atomCat.ChainAtomList;
            ChainAtoms thisChain = null;

            foreach (string asymChain in chainMatrixHash.Keys)
            {
                thisChain = null; // fixed on June 30, 2010
                foreach (ChainAtoms chain in chainAtomsList)
                {
                    if (chain.AsymChain == asymChain)
                    {
                        thisChain = chain;
                        break;
                    }
                }
                if (thisChain == null)
                {
                    continue;
                }

                string chainSymOpString = "";
                foreach (SymOpMatrix symMatrix in chainMatrixHash[asymChain])
                {
                    if (symMatrix.symmetryString == "-" || symMatrix.symmetryString == "")
                    {
                        chainSymOpString = asymChain + "_" + symMatrix.symmetryOpNum + "_-";
                    }
                    else
                    {
                        chainSymOpString = asymChain + "_" + symMatrix.symmetryString;
                        if (type == "pisa")
                        {
                            if (symMatrix.symmetryOpNum != "" && symMatrix.symmetryOpNum != "0")
                            {
                                chainSymOpString += ("(" + symMatrix.symmetryOpNum + ")"); // for those non-NCS operator (same symmetry string)
                            }
                        }
                    }
                    if (!chainCoordHash.ContainsKey(chainSymOpString))
                    {
                        AtomInfo[] atoms = BuildOneChain(thisChain, symMatrix);
                        chainCoordHash.Add(chainSymOpString, atoms);
                    }
                }
            }
            return chainCoordHash;
        }
Exemplo n.º 6
0
 /// <summary>
 /// chains and their backbone atoms
 /// </summary>
 public ChainAtoms[] BackboneAtomList()
 {
     ChainAtoms[] backboneChainList = new ChainAtoms [chainAtomsList.Count];
     for (int i = 0; i < chainAtomsList.Count; i++)
     {
         ChainAtoms backboneChainAtoms = new ChainAtoms();
         backboneChainAtoms.CartnAtoms  = ((ChainAtoms)chainAtomsList[i]).BackboneAtoms();
         backboneChainAtoms.AsymChain   = ((ChainAtoms)chainAtomsList[i]).AsymChain;
         backboneChainAtoms.EntityID    = ((ChainAtoms)chainAtomsList[i]).EntityID;
         backboneChainAtoms.PolymerType = ((ChainAtoms)chainAtomsList[i]).PolymerType;
         backboneChainList[i]           = backboneChainAtoms;
     }
     return(backboneChainList);
 }
Exemplo n.º 7
0
 /// <summary>
 /// chains and their Calpha and Cbeta atoms
 /// </summary>
 /// <returns></returns>
 public ChainAtoms[] CalphaCbetaAtomList()
 {
     ChainAtoms[] calphaCbetaChainList = new ChainAtoms [chainAtomsList.Count];
     for (int i = 0; i < chainAtomsList.Count; i++)
     {
         ChainAtoms chainCalphaCbetaAtoms = new ChainAtoms();
         chainCalphaCbetaAtoms.CartnAtoms  = ((ChainAtoms)chainAtomsList[i]).CalphaCbetaAtoms();
         chainCalphaCbetaAtoms.AsymChain   = ((ChainAtoms)chainAtomsList[i]).AsymChain;
         chainCalphaCbetaAtoms.EntityID    = ((ChainAtoms)chainAtomsList[i]).EntityID;
         chainCalphaCbetaAtoms.PolymerType = ((ChainAtoms)chainAtomsList[i]).PolymerType;
         calphaCbetaChainList[i]           = chainCalphaCbetaAtoms;
     }
     return(calphaCbetaChainList);
 }
Exemplo n.º 8
0
 /// <summary>
 /// transform one chain 
 /// </summary>
 /// <param name="chain"></param>
 /// <param name="symMatrix"></param>
 /// <returns></returns>
 public AtomInfo[] BuildOneChain(ChainAtoms chain, SymOpMatrix symMatrix)
 {
     if (symMatrix.symmetryString == "1_555")
     {
         return chain.CartnAtoms;
     }
     AtomInfo[] transformedAtoms = new AtomInfo[chain.CartnAtoms.Length];
     int i = 0;
     foreach (AtomInfo atom in chain.CartnAtoms)
     {
         AtomInfo transformedAtom = atom.TransformAtom(symMatrix);
         transformedAtoms[i] = transformedAtom;
         i++;
     }
     return transformedAtoms;
 }
Exemplo n.º 9
0
        /// <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);
        }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 11
0
        /// <summary>
        /// build asymmetric unit from NCS
        /// </summary>
        /// <param name="thisEntryCrystal"></param>
        /// <returns></returns>
        //	public void BuildAsymUnitFromNcs (ref EntryCrystal thisEntryCrystal, string[] origAsymChains, out bool asuChanged)
        public void BuildAsymUnitFromNcs(ref EntryCrystal thisEntryCrystal, out bool asuChanged)
        {
            asuChanged = false;
            //		chainLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            //		ChainAtoms[] chainAtomsList = new ChainAtoms [thisEntryCrystal.atomCat.ChainAtomList.Length];

            int genNcsNum = 0;

            foreach (NcsOperator ncsOp in thisEntryCrystal.ncsCat.NcsOperatorList)
            {
                if (ncsOp.code == "generate")
                {
                    genNcsNum++;
                }
            }
            if (genNcsNum == 0)
            {
                return;
            }
            else if (genNcsNum * thisEntryCrystal.atomCat.ChainAtomList.Length > chainLetters.Length)
            /*   else if (genNcsNum > chainLetters.Length) */
            {
                return;
            }

            List <ChainAtoms> asuChainList = new List <ChainAtoms>();

            //	RemoveOrigAsuChainNames (thisEntryCrystal.atomCat.ChainAtomList, ref chainLetters);
            //	int ncsChainCount = 1;
            foreach (ChainAtoms chain in thisEntryCrystal.atomCat.ChainAtomList)
            {
                /*	if (chain.PolymerType != "polypeptide")
                 *      {
                 *              continue;
                 *      }*/
                asuChainList.Add(chain);
                //	ncsChainCount = 1;
                foreach (NcsOperator ncsOp in thisEntryCrystal.ncsCat.NcsOperatorList)
                {
                    if (ncsOp.code == "given")
                    {
                        continue;
                    }

                    AtomInfo[] ncsAtoms = ApplyNcsMatrix(chain.CartnAtoms, ncsOp.ncsMatrix);
                    if (DoesChainExist(ncsAtoms, thisEntryCrystal.atomCat.ChainAtomList))
                    {
                        continue;
                    }
                    asuChanged = true;
                    ChainAtoms newChain = new ChainAtoms(chain);
                    newChain.CartnAtoms = ncsAtoms;
                    //	newChain.AsymChain = chain.AsymChain + chainLetters[ncsChainCount].ToString ();
                    //	newChain.AsymChain =GetAsymChainNameForNcsChain (ref ncsChainCount, chain.AsymChain, origAsymChains);
                    // name the new chain with original asymmetric chain + a number,
                    // this should distinguish the original asymmetri chains with these regenerated chains
                    //      newChain.AsymChain = chain.AsymChain + ncsChainCount.ToString();
                    newChain.AsymChain = chain.AsymChain + ncsOp.ncsId.ToString();
                    //       ncsChainCount ++;
                    asuChainList.Add(newChain);
                }
            }
            thisEntryCrystal.atomCat.ChainAtomList = asuChainList.ToArray();
        }
Exemplo n.º 12
0
 /// <summary>
 /// add asymmetry chain
 /// </summary>
 /// <param name="chainAtoms"></param>
 public void AddChainAtoms(ChainAtoms chainAtoms)
 {
     chainAtomsList.Add(chainAtoms);
 }