示例#1
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);
        }
示例#2
0
        /// <summary>
        /// convert a symmetry matrix into a full symmetry string
        /// </summary>
        /// <param name="symOpMatrix">symmetry matrix</param>
        /// <returns>full symmetry string</returns>
        public string ConvertMatrixToSymString(SymOpMatrix symOpMatrix, int precision)
        {
            string symOpString      = "";
            string thisDimSymString = "";

            for (int dimNo = 0; dimNo < 3; dimNo++)
            {
                thisDimSymString = "";
                // X value
                int elemVal = (int)symOpMatrix.Value(dimNo, 0);
                if (elemVal > 0)
                {
                    if (thisDimSymString != "")
                    {
                        thisDimSymString += "+X";
                    }
                    else
                    {
                        thisDimSymString += "X";
                    }
                }
                else if (elemVal < 0)
                {
                    thisDimSymString += "-X";
                }

                // Y value
                elemVal = (int)symOpMatrix.Value(dimNo, 1);
                if (elemVal > 0)
                {
                    if (thisDimSymString != "")
                    {
                        thisDimSymString += "+Y";
                    }
                    else
                    {
                        thisDimSymString += "Y";
                    }
                }
                else if (elemVal < 0)
                {
                    thisDimSymString += "-Y";
                }
                // Z value
                elemVal = (int)symOpMatrix.Value(dimNo, 2);
                if (elemVal > 0)
                {
                    if (thisDimSymString != "")
                    {
                        thisDimSymString += "+Z";
                    }
                    else
                    {
                        thisDimSymString += "Z";
                    }
                }
                else if (elemVal < 0)
                {
                    thisDimSymString += "-Z";
                }
                // for the translation vector
                double vectVal = symOpMatrix.Value(dimNo, 3);
                if (vectVal != 0.0)
                {
                    int    i            = 0;
                    string stringFormat = "0.";
                    while (i < precision)
                    {
                        stringFormat += "0";
                        i++;
                    }
                    thisDimSymString += vectVal.ToString(stringFormat);
                }
                symOpString += thisDimSymString;
                symOpString += ",";
            }
            return(symOpString.TrimEnd(','));
        }