Beispiel #1
0
        /// <summary>
        /// Matrices to generate PISA Assembly given an assemblySeqID
        /// </summary>
        /// <param name="pdbId"></param>
        /// <returns></returns>
        public Dictionary <string, List <SymOpMatrix> > GetPisaBuMatrices(string pdbId, string assemblySeqId, DataTable buMatrixTable)
        {
            DataRow[] buMatrixRows = buMatrixTable.Select(string.Format("PdbID = '{0}' AND AssemblySeqID = '{1}'",
                                                                        pdbId, assemblySeqId));
            Dictionary <string, List <SymOpMatrix> > assemblyMatricesHash = new Dictionary <string, List <SymOpMatrix> >();

            string      asymChain    = "";
            string      matrixString = "";
            SymOpMatrix symOpMatrix  = null;

            foreach (DataRow dRow in buMatrixRows)
            {
                asymChain    = dRow["AsymChain"].ToString().Trim();
                matrixString = dRow["Matrix"].ToString().Trim();
                symOpMatrix  = GetCoordSymOpMatrix(matrixString);
                symOpMatrix.symmetryString = dRow["SymmetryString"].ToString().TrimEnd();
                symOpMatrix.symmetryOpNum  = dRow["SymOpSeqID"].ToString().TrimEnd();

                if (assemblyMatricesHash.ContainsKey(asymChain))
                {
                    assemblyMatricesHash[asymChain].Add(symOpMatrix);
                }
                else
                {
                    List <SymOpMatrix> matrixList = new List <SymOpMatrix>  ();
                    matrixList.Add(symOpMatrix);
                    assemblyMatricesHash.Add(asymChain, matrixList);
                }
            }
            return(assemblyMatricesHash);
        }
Beispiel #2
0
        /// <summary>
        /// convert a symmetry operator to a full symmetry string
        /// 1_656 to 1+X,Y,1+Z based on the symmetry matrices
        /// </summary>
        /// <param name="symOpMatrices"></param>
        /// <param name="symOpString"></param>
        /// <returns></returns>
        public string ConvertSymOpStringToFull(SymOpMatrix[] symOpMatrices, string symOpString)
        {
            SymOpMatrix fullSymOpMatrix = GetSymmetryMatrixFromSymmetryString(symOpMatrices, symOpString);
            string      fullSymString   = fullSymOpMatrix.ToFullSymString();

            return(FormatFullSymString(fullSymString));
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="asuTable"></param>
        /// <returns></returns>
        private Dictionary <string, Dictionary <string, List <SymOpMatrix> > > GetEntryAsuComponentInfoHash(DataTable asuTable)
        {
            Dictionary <string, Dictionary <string, List <SymOpMatrix> > > asuInfoHash = new Dictionary <string, Dictionary <string, List <SymOpMatrix> > > ();
            Dictionary <string, List <SymOpMatrix> > chainMatrixHash = new Dictionary <string, List <SymOpMatrix> > ();
            string      buId        = "1";
            string      asymChain   = "";
            SymOpMatrix symOpMatrix = null;

            foreach (DataRow asuRow in asuTable.Rows)
            {
                asymChain   = asuRow["AsymID"].ToString().TrimEnd();
                symOpMatrix = GetOrigCoordSymOpMatrix();
                symOpMatrix.symmetryString = "1_555";
                symOpMatrix.symmetryOpNum  = "1";

                if (chainMatrixHash.ContainsKey(asymChain))
                {
                    chainMatrixHash[asymChain].Add(symOpMatrix);
                }
                else
                {
                    List <SymOpMatrix> matrixList = new List <SymOpMatrix> ();
                    matrixList.Add(symOpMatrix);
                    chainMatrixHash.Add(asymChain, matrixList);
                }
            }
            asuInfoHash.Add(buId, chainMatrixHash);
            return(asuInfoHash);
        }
Beispiel #4
0
        /// <summary>
        /// apply cartesian symmetry operators on cartesian coordinates
        /// directly to provide transformed cartesian coordinate
        /// </summary>
        /// <param name="symOpMatrix"></param>
        /// <param name="fractTransMatrix"></param>
        /// <param name="cartnInverseMatrix"></param>
        /// <returns></returns>
        public AtomInfo TransformAtom(SymOpMatrix symOpMatrix)
        {
            AtomInfo transformedAtom = (AtomInfo)this.Clone();;

            transformedAtom.xyz = symOpMatrix * this.xyz;
            return(transformedAtom);
        }
Beispiel #5
0
        /// <summary>
        /// Matrices to generate PISA Assembly given an assemblySeqID
        /// </summary>
        /// <param name="pdbId"></param>
        /// <returns></returns>
        public Dictionary <string, List <SymOpMatrix> > GetPisaBuMatrices(string pdbId, string assemblySeqId)
        {
            string queryString = string.Format("Select * From PisaBuMatrix " +
                                               " Where PdbID = '{0}' AND AssemblySeqID = {1};", pdbId, assemblySeqId);
            DataTable pisaBusTable = ProtCidSettings.pdbfamQuery.Query(queryString);
            Dictionary <string, List <SymOpMatrix> > assemblyMatricesHash = new Dictionary <string, List <SymOpMatrix> >  ();

            string      asymChain    = "";
            string      matrixString = "";
            SymOpMatrix symOpMatrix  = null;

            foreach (DataRow dRow in pisaBusTable.Rows)
            {
                asymChain    = dRow["AsymChain"].ToString().Trim();
                matrixString = dRow["Matrix"].ToString().Trim();
                symOpMatrix  = GetCoordSymOpMatrix(matrixString);
                symOpMatrix.symmetryString = dRow["SymmetryString"].ToString().TrimEnd();
                symOpMatrix.symmetryOpNum  = dRow["SymOpSeqId"].ToString().TrimEnd();

                if (assemblyMatricesHash.ContainsKey(asymChain))
                {
                    assemblyMatricesHash[asymChain].Add(symOpMatrix);
                }
                else
                {
                    List <SymOpMatrix> matrixList = new List <SymOpMatrix> ();
                    matrixList.Add(symOpMatrix);
                    assemblyMatricesHash.Add(asymChain, matrixList);
                }
            }
            return(assemblyMatricesHash);
        }
Beispiel #6
0
        /// <summary>
        /// get symmetry matrix for a specific symmetry operation string
        /// may need translation
        /// linear search
        /// </summary>
        /// <param name="symOpMatrices"></param>
        /// <param name="symOpString"></param>
        /// <returns></returns>
        public SymOpMatrix GetSymmetryMatrixFromSymmetryString(SymOpMatrix[] symOpMatrices, string symOpString)
        {
            int    index1    = symOpString.IndexOf("_");
            int    index2    = symOpString.LastIndexOf("_");
            string symOpNum  = "";
            string symString = "";

            if (index1 == index2)
            {
                symOpNum  = symOpString.Substring(0, index1);
                symString = symOpString.Substring(index1 + 1, symOpString.Length - index1 - 1);
            }
            else
            {
                symOpNum  = symOpString.Substring(index1 + 1, index2 - index1 - 1);
                symString = symOpString.Substring(index2 + 1, symOpString.Length - index2 - 1);
            }
            SymOpMatrix convertedSymOpMatrix = null;

            foreach (SymOpMatrix symOpMatrix in symOpMatrices)
            {
                if (symOpMatrix.symmetryOpNum == symOpNum)
                {
                    convertedSymOpMatrix = (SymOpMatrix)symOpMatrix.Clone();
                    break;
                }
            }
            if (convertedSymOpMatrix != null)
            {
                if (symString.Length == 3)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (symString[i] == '5')
                        {
                            continue;
                        }
                        convertedSymOpMatrix.Add(i, 3, convertedSymOpMatrix.Value(i, 3) + (double)(Convert.ToInt32(symString[i].ToString()) - 5));
                    }
                }

                /* should deal with a symmetry string with translate vectors > 5
                 * format of this type of symmetry string: 1_+10-1+6
                 * translate vector (+5, -6, +1)
                 */
                else if (symString.Length > 3)
                {
                    string[] vectStrings = SeparateSymmetryString(symString);
                    convertedSymOpMatrix.Add(0, 3, convertedSymOpMatrix.Value(0, 3) +
                                             (double)(Convert.ToInt32(vectStrings[0]) - 5));
                    convertedSymOpMatrix.Add(1, 3, convertedSymOpMatrix.Value(1, 3) +
                                             (double)(Convert.ToInt32(vectStrings[1]) - 5));
                    convertedSymOpMatrix.Add(2, 3, convertedSymOpMatrix.Value(2, 3) +
                                             (double)(Convert.ToInt32(vectStrings[2]) - 5));
                }
            }
            return(convertedSymOpMatrix);
        }
Beispiel #7
0
        /// <summary>
        /// build a PDB biological unit
        /// by applying the symmetry operations provided in XML
        /// </summary>
        /// <param name="chainAtomsList">chains in XML</param>
        /// <param name="buGenStructList">symmetry operations</param>
        /// <param name="buSymmetryMatrixList">symmetry matrix</param>
        /// <returns>biological units with corresponding chains</returns>
        /// </summary>
        private Dictionary <string, AtomInfo[]> BuildFullPdbBuByPdbSymOps(string pdbId, string biolUnitId, EntryCrystal thisEntryCrystal)
        {
            Dictionary <string, AtomInfo[]> buHash = null;

            ChainAtoms[]  chainAtomsList  = thisEntryCrystal.atomCat.ChainAtomList;
            BuGenStruct[] buGenStructList = thisEntryCrystal.buGenCat.BuGenStructList;

            List <string>      symOpStrList     = new List <string> ();
            List <string>      fullSymOpStrList = new List <string> ();
            List <SymOpMatrix> symOpMatrixList  = new List <SymOpMatrix> ();

            for (int asymCount = 0; asymCount < buGenStructList.Length; asymCount++)
            {
                if (biolUnitId != buGenStructList[asymCount].biolUnitId)
                {
                    continue;
                }
                string asymId = buGenStructList[asymCount].asymId;
                foreach (ChainAtoms chain in chainAtomsList)
                {
                    if (chain.AsymChain == asymId)
                    {
                        SymOpMatrix symOpMatrix =
                            thisEntryCrystal.buGenCat.FindSymOpMatrix(buGenStructList[asymCount].symOperId);
                        if (symOpMatrix == null)
                        {
                            fullSymOpStrList.Add(buGenStructList[asymCount].symmetryMatrix);
                            symOpStrList.Add(asymId + "_" + buGenStructList[asymCount].symmetryString);
                        }
                        else
                        {
                            if (symOpMatrix.symmetryString == "" || symOpMatrix.symmetryString == "-")
                            {
                                // put the symmetry operator id if the symmetry string is empty
                                symOpStrList.Add(asymId + "_" + buGenStructList[asymCount].symOperId);
                            }
                            else
                            {
                                symOpStrList.Add(asymId + "_" + symOpMatrix.symmetryString);
                            }
                            symOpMatrixList.Add(symOpMatrix);
                        }
                    }
                }
            }

            string[] symOpStrings = symOpStrList.ToArray();
            if (symOpMatrixList.Count > 0)
            {
                buHash = BuildPdbBu(thisEntryCrystal, symOpStrings, symOpMatrixList.ToArray());
            }
            else if (fullSymOpStrList.Count > 0)
            {
                buHash = BuildPdbBu(thisEntryCrystal, symOpStrings, fullSymOpStrList.ToArray());
            }
            return(buHash);
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fullSymOpString">X-1,Y,Z+1</param>
        /// <param name="spaceGroup"></param>
        /// <returns>e.g. 1_456</returns>
        public string ConvertFullSymOpStringToShort(string fullSymOpString, string spaceGroup)
        {
            SymOpMatrix symOpMatrix = new SymOpMatrix();

            symOpMatrix.fullSymmetryString = fullSymOpString;
            SetSymOpMatrix(fullSymOpString, ref symOpMatrix);
            string symString = ConvertMatrixToSymString(symOpMatrix, 1);

            return(symString);
        }
Beispiel #9
0
        /// <summary>
        /// are these two symmetry operator matrices same
        /// </summary>
        /// <param name="symOp1"></param>
        /// <param name="symOp2"></param>
        /// <returns></returns>
        private bool AreSymOpMatricesSame(SymOpMatrix symOp1, SymOpMatrix symOp2)
        {
            int compResult = string.Compare(symOp1.fullSymmetryString, symOp2.fullSymmetryString, true);

            if (compResult == 0)
            {
                return(true);
            }
            return(false);
        }
Beispiel #10
0
 /// <summary>
 /// transform a protein chain by applying a specific symmetry operation
 /// either from PDB xml or from a user-defined
 /// </summary>
 /// <param name="chainCoordList"></param>
 /// <param name="symMatrix"></param>
 /// <returns></returns>
 public AtomInfo[] TransformChainBySpecificSymOp(AtomInfo[] chainAtomList, SymOpMatrix symMatrix)
 {
     AtomInfo[] transformedAtomList = new AtomInfo [chainAtomList.Length];
     for (int atomI = 0; atomI < chainAtomList.Length; atomI++)
     {
         AtomInfo thisAtomInfo = chainAtomList[atomI].TransformAtom(symMatrix, cartn2fractMatrix, fract2cartnMatrix);
         transformedAtomList[atomI] = thisAtomInfo;
     }
     return(transformedAtomList);
 }
Beispiel #11
0
        public new Object Clone()
        {
            SymOpMatrix newMatrix = new SymOpMatrix();

            newMatrix.MatrixElements     = ((Matrix)(base.Clone())).MatrixElements;
            newMatrix.symmetryOpNum      = this.symmetryOpNum;
            newMatrix.symmetryString     = this.symmetryString;
            newMatrix.fullSymmetryString = this.fullSymmetryString;
            return(newMatrix);
        }
Beispiel #12
0
 /// <summary>
 /// transform a protein chain by applying a specific symmetry operation
 /// either from PDB xml or from a user-defined
 /// </summary>
 /// <param name="chainCoordList"></param>
 /// <param name="symMatrix"></param>
 /// <returns></returns>
 private AtomInfo[] TransformChainByCartesianSymOp(AtomInfo[] chainAtomList, SymOpMatrix symMatrix)
 {
     AtomInfo[] transformedAtomList = new AtomInfo[chainAtomList.Length];
     for (int atomI = 0; atomI < chainAtomList.Length; atomI++)
     {
         AtomInfo thisAtomInfo = chainAtomList[atomI].TransformAtom(symMatrix);
         transformedAtomList[atomI] = thisAtomInfo;
     }
     return(transformedAtomList);
 }
Beispiel #13
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);
        }
Beispiel #14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="matrixList"></param>
 /// <param name="symMatrix"></param>
 /// <returns></returns>
 private bool IsSymMatrixExist(List <SymOpMatrix> matrixList, SymOpMatrix symMatrix)
 {
     foreach (SymOpMatrix symOpMatrix in matrixList)
     {
         if (symOpMatrix.symmetryString == symMatrix.symmetryString)
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #15
0
        /// <summary>
        /// a. change a cartesian coordinate to fractional coordinate
        /// b. transform the fractional coordinate
        /// c. compute the cartesian coordinate
        /// for the transformed fractional coordinate
        /// </summary>
        /// <param name="symOpMatrix"></param>
        /// <param name="fractTransMatrix"></param>
        /// <param name="cartnInverseMatrix"></param>
        /// <returns></returns>
        public AtomInfo TransformAtom(SymOpMatrix symOpMatrix, Matrix fractTransMatrix, Matrix cartnInverseMatrix)
        {
            AtomInfo transformedAtom = (AtomInfo)this.Clone();;

            if (this.fractCoord == null)
            {
                this.fractCoord = fractTransMatrix * this.xyz;
            }
            transformedAtom.fractCoord = symOpMatrix * this.fractCoord;
            transformedAtom.xyz        = cartnInverseMatrix * (symOpMatrix * this.fractCoord);
            return(transformedAtom);
        }
Beispiel #16
0
        /// <summary>
        /// get the symmetry matrix from full symmetry string
        /// </summary>
        /// <param name="fullSymOpString"></param>
        /// <returns></returns>
        public SymOpMatrix GetSymMatrix(string fullSymOpString, string symOpString)
        {
            SymOpMatrix symOpMatrix = new SymOpMatrix();

            symOpMatrix.fullSymmetryString = fullSymOpString;
            symOpMatrix.symmetryOpNum      = symOpString.Substring
                                                 (symOpString.IndexOf("_") + 1, symOpString.LastIndexOf("_") - symOpString.IndexOf("_") - 1);
            symOpMatrix.symmetryString = symOpString;
            //SetSymOpMatrix (fullSymOpString, symOpString.Substring (symOpString.Length - 3, 3), ref symOpMatrix);
            SetSymOpMatrix(fullSymOpString, ref symOpMatrix);
            return(symOpMatrix);
        }
Beispiel #17
0
 /// <summary>
 /// transform a protein chain by applying a specific symmetry operation
 /// either from PDB xml or from a user-defined
 /// </summary>
 /// <param name="chainCoordList"></param>
 /// <param name="symMatrix"></param>
 /// <returns></returns>
 private AtomInfo[] TransformChainBySymOpAndTrans(AtomInfo[] chainAtomList, SymOpMatrix symMatrix, double[] transVector)
 {
     AtomInfo[] transformedAtomList = new AtomInfo [chainAtomList.Length];
     for (int atomI = 0; atomI < chainAtomList.Length; atomI++)
     {
         AtomInfo thisAtomInfo = chainAtomList[atomI].TransformAtom(symMatrix, cartn2fractMatrix, fract2cartnMatrix);
         thisAtomInfo.xyz.X        += transVector[0];
         thisAtomInfo.xyz.Y        += transVector[1];
         thisAtomInfo.xyz.Z        += transVector[2];
         transformedAtomList[atomI] = thisAtomInfo;
     }
     return(transformedAtomList);
 }
Beispiel #18
0
 /// <summary>
 /// get matrix from a symmetry operation string
 /// </summary>
 /// <param name="symOpStr"></param>
 /// <param name="symOpMatrix"></param>
 public void SetSymOpMatrix(string fullSymOpStr, /*string symOpString,*/ ref SymOpMatrix symOpMatrix)
 {
     double[]  indexValues = new double [3];
     string [] symOpRows   = fullSymOpStr.ToUpper().Split(',');
     for (int dimNo = 0; dimNo < 3; dimNo++)
     {
         string symOpRow = symOpRows[dimNo];
         symOpMatrix.Add(dimNo, 0, GetDimIndex(symOpRow, "X"));
         symOpMatrix.Add(dimNo, 1, GetDimIndex(symOpRow, "Y"));
         symOpMatrix.Add(dimNo, 2, GetDimIndex(symOpRow, "Z"));
         //int transVector = Convert.ToInt32 (symOpString[dimNo].ToString ()) - 5;
         //symOpMatrix.Add (dimNo, 3, GetVectorValue(symOpRow) - transVector);
         symOpMatrix.Add(dimNo, 3, GetVectorValue(symOpRow));
     }
 }
Beispiel #19
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);
        }
Beispiel #20
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;
 }
Beispiel #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pdbId"></param>
        /// <param name="assemblyComponentHash"></param>
        public void GetPisaBuLigandsMatrices(string pdbId, ref Dictionary <string, Dictionary <string, List <SymOpMatrix> > > assemblyComponentHash)
        {
            string      queryString   = string.Format("Select * From PisaBuLigand WHere PdbID = '{0}';", pdbId);
            DataTable   ligandTable   = ProtCidSettings.pdbfamQuery.Query(queryString);
            string      assemblySeqId = "";
            string      asymChain     = "";
            string      matrixString  = "";
            SymOpMatrix symOpMatrix   = null;

            foreach (DataRow dRow in ligandTable.Rows)
            {
                assemblySeqId = dRow["AssemblySeqID"].ToString();
                asymChain     = dRow["AsymChain"].ToString().Trim();
                matrixString  = dRow["Matrix"].ToString().Trim();
                symOpMatrix   = GetCoordSymOpMatrix(matrixString);
                symOpMatrix.symmetryString = dRow["SymmetryString"].ToString().TrimEnd();

                if (assemblyComponentHash.ContainsKey(assemblySeqId))
                {
                    Dictionary <string, List <SymOpMatrix> > chainMatrixHash = assemblyComponentHash[assemblySeqId];
                    if (chainMatrixHash.ContainsKey(asymChain))
                    {
                        if (!IsSymMatrixExist(chainMatrixHash[asymChain], symOpMatrix))
                        {
                            chainMatrixHash[asymChain].Add(symOpMatrix);
                        }
                    }
                    else
                    {
                        List <SymOpMatrix> matrixList = new List <SymOpMatrix> ();
                        matrixList.Add(symOpMatrix);
                        chainMatrixHash.Add(asymChain, matrixList);
                    }
                }
                else
                {
                    Dictionary <string, List <SymOpMatrix> > chainMatrixHash = new Dictionary <string, List <SymOpMatrix> > ();
                    List <SymOpMatrix> matrixList = new List <SymOpMatrix> ();
                    matrixList.Add(symOpMatrix);
                    chainMatrixHash.Add(asymChain, matrixList);
                    assemblyComponentHash.Add(assemblySeqId, chainMatrixHash);
                }
            }
        }
Beispiel #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="buGenTable"></param>
        /// <returns></returns>
        private Dictionary <string, Dictionary <string, List <SymOpMatrix> > > GetEntryBuComponentInfoHash(DataTable buGenTable)
        {
            Dictionary <string, Dictionary <string, List <SymOpMatrix> > > pdbBuComponentInfoHash = new Dictionary <string, Dictionary <string, List <SymOpMatrix> > >();
            string      buId         = "";
            string      asymChain    = "";
            string      matrixString = "";
            SymOpMatrix symOpMatrix  = null;

            foreach (DataRow buGenRow in buGenTable.Rows)
            {
                buId         = buGenRow["BiolUnitID"].ToString().TrimEnd();
                asymChain    = buGenRow["AsymID"].ToString().Trim();
                matrixString = buGenRow["SymmetryMatrix"].ToString().Trim();
                symOpMatrix  = GetCoordSymOpMatrix(matrixString);
                symOpMatrix.symmetryString = buGenRow["SymmetryString"].ToString().TrimEnd();
                symOpMatrix.symmetryOpNum  = buGenRow["SymOpNum"].ToString().TrimEnd();

                if (pdbBuComponentInfoHash.ContainsKey(buId))
                {
                    Dictionary <string, List <SymOpMatrix> > chainMatrixHash = pdbBuComponentInfoHash[buId];
                    if (chainMatrixHash.ContainsKey(asymChain))
                    {
                        chainMatrixHash[asymChain].Add(symOpMatrix);
                    }
                    else
                    {
                        List <SymOpMatrix> matrixList = new List <SymOpMatrix> ();
                        matrixList.Add(symOpMatrix);
                        chainMatrixHash.Add(asymChain, matrixList);
                    }
                }
                else
                {
                    Dictionary <string, List <SymOpMatrix> > chainMatrixHash = new Dictionary <string, List <SymOpMatrix> >();
                    List <SymOpMatrix> matrixList = new List <SymOpMatrix> ();
                    matrixList.Add(symOpMatrix);
                    chainMatrixHash.Add(asymChain, matrixList);
                    pdbBuComponentInfoHash.Add(buId, chainMatrixHash);
                }
            }
            return(pdbBuComponentInfoHash);
        }
Beispiel #23
0
        /// <summary>
        /// the symmetry matrix from matrix string
        /// s00, s01, s02, v0, s10, s11, s12, v1, s20, s21, s22, v2
        /// </summary>
        /// <param name="matrixString"></param>
        /// <returns></returns>
        private SymOpMatrix GetSymMatrixFromMatrixString(string matrixString)
        {
            string[]    fields      = matrixString.Split(',');
            SymOpMatrix symOpMatrix = new SymOpMatrix();
            int         numOfCol    = 4;
            int         colNum      = -1;
            int         rowNum      = -1;

            for (int i = 0; i < fields.Length; i++)
            {
                colNum++;
                if (i % numOfCol == 0)
                {
                    rowNum++;
                    colNum = 0;
                }
                symOpMatrix.Add(rowNum, colNum, Convert.ToDouble(fields[i]));
            }
            return(symOpMatrix);
        }
Beispiel #24
0
        /// <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);
        }
Beispiel #25
0
 /// <summary>
 /// the symmetry operator string
 /// </summary>
 /// <param name="infoNode"></param>
 /// <returns></returns>
 public SymOpMatrix GetOrigCoordSymOpMatrix()
 {
     SymOpMatrix symOpMatrix = new SymOpMatrix();
     List<double> itemList = new List<double> ();
     itemList.Add(1.0);
     itemList.Add(0.0);
     itemList.Add(0.0);
     itemList.Add(0.0);
     symOpMatrix.Add(0, itemList.ToArray ());
     itemList.Clear();
     itemList.Add(0.0);
     itemList.Add(1.0);
     itemList.Add(0.0);
     itemList.Add(0.0);
     symOpMatrix.Add(1, itemList.ToArray ());
     itemList.Clear();
     itemList.Add(0.0);
     itemList.Add(0.0);
     itemList.Add(1.0);
     itemList.Add(0.0);
     symOpMatrix.Add(2, itemList.ToArray ());
     return symOpMatrix;
 }
Beispiel #26
0
 /// <summary>
 /// the symmetry operator string
 /// </summary>
 /// <param name="infoNode"></param>
 /// <returns></returns>
 public SymOpMatrix GetCoordSymOpMatrix(string matrixString)
 {
     string[] fields = matrixString.Split(',');
     SymOpMatrix symOpMatrix = new SymOpMatrix();
     List<double> itemList = new List<double> ();
     itemList.Add(Convert.ToDouble(fields[0]));
     itemList.Add(Convert.ToDouble(fields[1]));
     itemList.Add(Convert.ToDouble(fields[2]));
     itemList.Add(Convert.ToDouble(fields[3]));
     symOpMatrix.Add(0, itemList.ToArray ());
     itemList.Clear();
     itemList.Add(Convert.ToDouble(fields[4]));
     itemList.Add(Convert.ToDouble(fields[5]));
     itemList.Add(Convert.ToDouble(fields[6]));
     itemList.Add(Convert.ToDouble(fields[7]));
     symOpMatrix.Add(1, itemList.ToArray ());
     itemList.Clear();
     itemList.Add(Convert.ToDouble(fields[8]));
     itemList.Add(Convert.ToDouble(fields[9]));
     itemList.Add(Convert.ToDouble(fields[10]));
     itemList.Add(Convert.ToDouble(fields[11]));
     symOpMatrix.Add(2, itemList.ToArray ());
     return symOpMatrix;
 }
Beispiel #27
0
 public void Add(SymOpMatrix symOpMatrix)
 {
     symmetryOpList.Add(symOpMatrix);
 }
Beispiel #28
0
        /// <summary>
        /// build a PDB biological unit
        /// by applying the symmetry operations provided in XML
        /// </summary>
        /// <param name="chainAtomsList">chains in XML</param>
        /// <param name="buGenStructList">symmetry operations</param>
        /// <param name="buSymmetryMatrixList">symmetry matrix</param>
        /// <returns>biological units with corresponding chains</returns>
        /// </summary>
        private Dictionary <string, AtomInfo[]> BuildPdbBuByPdbSymOps(string pdbId, string biolUnitId, EntryCrystal thisEntryCrystal)
        {
            ChainAtoms[]  chainAtomsList  = thisEntryCrystal.atomCat.ChainAtomList;
            BuGenStruct[] buGenStructList = thisEntryCrystal.buGenCat.BuGenStructList;

            List <string>      symOpStrList     = new List <string> ();
            List <string>      fullSymOpStrList = new List <string> ();
            List <SymOpMatrix> symOpMatrixList  = new List <SymOpMatrix> ();

            for (int asymCount = 0; asymCount < buGenStructList.Length; asymCount++)
            {
                if (biolUnitId != buGenStructList[asymCount].biolUnitId)
                {
                    continue;
                }
                string asymId = buGenStructList[asymCount].asymId;
                foreach (ChainAtoms chain in chainAtomsList)
                {
                    if (chain.AsymChain == asymId)
                    {
                        // at this step, only consider polypeptide chains
                        if (chain.PolymerType == "polypeptide")
                        {
                            SymOpMatrix symOpMatrix =
                                thisEntryCrystal.buGenCat.FindSymOpMatrix(buGenStructList[asymCount].symOperId);
                            if (symOpMatrix == null)
                            {
                                fullSymOpStrList.Add(buGenStructList[asymCount].symmetryMatrix);
                                symOpStrList.Add(asymId + "_" + buGenStructList[asymCount].symmetryString);
                            }
                            else
                            {
                                if (symOpMatrix.symmetryString == "")
                                {
                                    // put the symmetry operator id if the symmetry string is empty
                                    symOpStrList.Add(asymId + "_" + buGenStructList[asymCount].symOperId);
                                }
                                else
                                {
                                    symOpStrList.Add(asymId + "_" + symOpMatrix.symmetryString);
                                }
                                symOpMatrixList.Add(symOpMatrix);
                            }
                            break;
                        }
                    }
                }
            }
            Dictionary <string, AtomInfo[]> buHash = null;

            string[] symOpStrings = new string[symOpStrList.Count];
            symOpStrList.CopyTo(symOpStrings);
            if (symOpMatrixList.Count > 0)
            {
                SymOpMatrix[] symOpMatrices = new SymOpMatrix[symOpMatrixList.Count];
                symOpMatrixList.CopyTo(symOpMatrices);
                buHash = BuildPdbBu(thisEntryCrystal, symOpStrings, symOpMatrices);
            }
            else if (fullSymOpStrList.Count > 0)
            {
                string[] fullSymmetryStrings = new string[fullSymOpStrList.Count];
                fullSymOpStrList.CopyTo(fullSymmetryStrings);
                buHash = BuildPdbBu(thisEntryCrystal, symOpStrings, fullSymmetryStrings);
            }
            return(buHash);
        }
Beispiel #29
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);
        }
Beispiel #30
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);
        }