Beispiel #1
0
        public void ParseSymOpsFile(string fileName)
        {
            SymOps symOpList = new SymOps();

            string line     = "";
            int    symOpNum = 0;
            int    dimNum   = 3;
            int    vectNum  = 2;

            SpaceGroupSymmetryMatrices sgSymMatrices = null;

            StreamReader fileReader = new StreamReader(fileName);

            string preSg     = "";
            string currentSg = "";

            while ((line = fileReader.ReadLine()) != null)
            {
                // skip notation
                line = line.Trim();
                if (line == "" ||
                    line.ToLower().IndexOf("space_group") > -1 ||
                    line.ToLower().IndexOf("loop") > -1)
                {
                    continue;
                }
                // skip comments
                if (line[0] == '#')
                {
                    continue;
                }
                // remove space
                currentSg = line.Substring(line.IndexOf("'") + 1, line.LastIndexOf("'") - line.IndexOf("'") - 1);
                line      = line.Substring(line.LastIndexOf("'") + 1, line.Length - line.LastIndexOf("'") - 1).Trim();
                // start new space group,
                // add previous one
                if (currentSg != preSg)
                {
                    // add symmetry operations of a space group
                    if (sgSymMatrices != null)
                    {
                        symOpList.Add(sgSymMatrices);
                    }
                    sgSymMatrices            = new SpaceGroupSymmetryMatrices();
                    sgSymMatrices.spaceGroup = currentSg;
                }

                SymOpMatrix symOpMatrix = new SymOpMatrix();
                string[]    fields      = ParseHelper.SplitPlus(line, ' ');
                symOpMatrix.symmetryOpNum = fields[0];

                symOpNum = Convert.ToInt32(fields[0]);
                symOpMatrix.symmetryString = symOpNum.ToString() + "_555";
                // set 3*3 matrix
                int i = 1;
                for (; i < 10; i++)
                {
                    symOpMatrix.Add((int)Math.Floor((double)(i - 1) / (double)dimNum), (i - 1) % dimNum, Convert.ToDouble(fields[i]));
                }
                // set matrix vector
                string denominator = "";
                string nominator   = "";
                int    dim         = 0;
                for (; i < fields.Length; i += vectNum)
                {
                    denominator = fields[i];
                    nominator   = fields[i + 1];
                    if (nominator == "0")
                    {
                        symOpMatrix.Add(dim, 3, 0);
                    }
                    else
                    {
                        symOpMatrix.Add(dim, 3, Convert.ToDouble(denominator) / Convert.ToDouble(nominator));
                    }
                    dim++;
                }
                // format full symmetry string from symmetry matrix
                symOpMatrix.fullSymmetryString = symOpMatrix.ToFullSymString();
                sgSymMatrices.Add(symOpMatrix);
                symOpMatrix = new SymOpMatrix();
                preSg       = currentSg;
            }
            if (sgSymMatrices != null)
            {
                // add the last space group
                symOpList.Add(sgSymMatrices);
            }
            FindDuplicateSpaceGroups(ref symOpList);
            XmlSerializer xmlSerializer = new XmlSerializer(symOpList.GetType());
            TextWriter    symOpWriter   = new StreamWriter("symOps.xml", false);

            xmlSerializer.Serialize(symOpWriter, symOpList);
            symOpWriter.Close();
        }