Пример #1
0
        private static string F_ANGLE_FORMAT(double angle) => angle.ToString("F3", NumberFormatInfo.InvariantInfo).PadLeft(7);    //"%3.3f";

        public void WriteCrystal(ICrystal crystal)
        {
            try
            {
                WriteHeader();
                Vector3  a        = crystal.A;
                Vector3  b        = crystal.B;
                Vector3  c        = crystal.C;
                double[] ucParams = CrystalGeometryTools.CartesianToNotional(a, b, c);
                writer.Write("CRYST1 " + F_LENGTH_FORMAT(ucParams[0]));
                writer.Write(F_LENGTH_FORMAT(ucParams[1]));
                writer.Write(F_LENGTH_FORMAT(ucParams[2]));
                writer.Write(F_ANGLE_FORMAT(ucParams[3]));
                writer.Write(F_ANGLE_FORMAT(ucParams[4]));
                writer.Write('\n');

                // before saving the atoms, we need to create cartesian coordinates
                foreach (var atom in crystal.Atoms)
                {
                    //                Debug.WriteLine($"PDBWriter: atom -> {atom}");
                    // if it got 3D coordinates, use that. If not, try fractional coordinates
                    if (atom.Point3D == null && atom.FractionalPoint3D != null)
                    {
                        Vector3 frac = atom.FractionalPoint3D.Value;
                        Vector3 cart = CrystalGeometryTools.FractionalToCartesian(a, b, c, frac);
                        atom.Point3D = cart;
                    }
                }
                WriteMolecule(crystal.Builder.NewAtomContainer(crystal));
            }
            catch (IOException exception)
            {
                throw new CDKException("Error while writing file: " + exception.Message, exception);
            }
        }
Пример #2
0
        public void TestReading()
        {
            var filename = "NCDK.Data.ShelX.frame_1.res";

            Trace.TraceInformation("Testing: " + filename);
            var         ins     = ResourceLoader.GetAsStream(filename);
            ShelXReader reader  = new ShelXReader(ins);
            Crystal     crystal = (Crystal)reader.Read(new Crystal());

            reader.Close();
            Assert.IsNotNull(crystal);
            Assert.AreEqual(42, crystal.Atoms.Count);
            var notional = CrystalGeometryTools.CartesianToNotional(crystal.A, crystal.B, crystal.C);

            Assert.AreEqual(7.97103, notional[0], 0.001);
            Assert.AreEqual(18.77220, notional[1], 0.001);
            Assert.AreEqual(10.26222, notional[2], 0.001);
            Assert.AreEqual(90.0000, notional[3], 0.001);
            Assert.AreEqual(90.0000, notional[4], 0.001);
            Assert.AreEqual(90.0000, notional[5], 0.001);
        }
Пример #3
0
        private CMLMolecule CDKCrystalToCMLMolecule(ICrystal crystal, bool setIDs)
        {
            var molecule   = CDKAtomContainerToCMLMolecule(crystal, false, false);
            var cmlCrystal = new CMLCrystal();

            if (useCMLIDs && setIDs)
            {
                IDCreator.CreateIDs(crystal);
            }
            if (!string.IsNullOrEmpty(crystal.Id))
            {
                cmlCrystal.Id = crystal.Id;
            }

            this.CheckPrefix(cmlCrystal);
            cmlCrystal.Z = crystal.Z.Value;
            var params_ = CrystalGeometryTools.CartesianToNotional(crystal.A, crystal.B, crystal.C);

            Debug.WriteLine($"Number of cell params: {params_.Length}");
            cmlCrystal.SetCellParameters(params_);
            molecule.Add(cmlCrystal);
            return(molecule);
        }