示例#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);
        }
示例#2
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[]> 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);
        }
示例#3
0
        public void SetCartn2fractMatrix(string xmlFile)
        {
            // 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);
            crystal1         = thisEntryCrystal.crystal1;
            xmlFileStream.Close();

            cartn2fractMatrix = thisEntryCrystal.scaleCat.ScaleMatrix;
            fract2cartnMatrix = cartn2fractMatrix.Inverse();
        }
示例#4
0
        /// <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);
        }
示例#5
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 int[] BuildCrystal(string crystalXmlFile, ref Dictionary <string, AtomInfo[]> crystalChainsHash)
        {
            // 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 (thisEntryCrystal.atomCat.IsOnlyCalphaChains())
             *   {
             *       throw new Exception("The crystal structure " + thisEntryCrystal.PdbId + " contains only Calpha atoms for at least of one chain. Skip it.");
             *   }*/
            int[] maxSteps = BuildCrystal(thisEntryCrystal, ref crystalChainsHash);
            return(maxSteps);
        }
示例#6
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);
        }
示例#7
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);
        }