コード例 #1
0
ファイル: XYZWriter.cs プロジェクト: carlhuth/GenXSource
        /// <summary> writes a single frame in XYZ format to the Writer.</summary>
        /// <param name="mol">the Molecule to write
        /// </param>
        public virtual void writeMolecule(IMolecule mol)
        {
            System.String st          = "";
            bool          writecharge = true;

            try
            {
                System.String s1 = ((System.Int32)mol.AtomCount).ToString();
                //UPGRADE_NOTE: Exceptions thrown by the equivalent in .NET of method 'java.io.BufferedWriter.write' may be different. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1099'"
                writer.Write(s1.ToCharArray(), 0, s1.Length);
                //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                writer.WriteLine();

                System.String s2 = null; // FIXME: add some interesting comment
                if (s2 != null)
                {
                    //UPGRADE_NOTE: Exceptions thrown by the equivalent in .NET of method 'java.io.BufferedWriter.write' may be different. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1099'"
                    writer.Write(s2.ToCharArray(), 0, s2.Length);
                }
                //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                writer.WriteLine();

                // Loop through the atoms and write them out:
                IAtom[] atoms = mol.Atoms;
                for (int i = 0; i < atoms.Length; i++)
                {
                    IAtom a = atoms[i];
                    st = a.Symbol;

                    Point3d p3 = a.getPoint3d();
                    if (p3 != null)
                    {
                        st = st + "\t" + p3.x.ToString() + "\t" + p3.y.ToString() + "\t" + p3.z.ToString();
                    }

                    if (writecharge)
                    {
                        double ct = a.getCharge();
                        st = st + "\t" + ct;
                    }

                    //UPGRADE_NOTE: Exceptions thrown by the equivalent in .NET of method 'java.io.BufferedWriter.write' may be different. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1099'"
                    writer.Write(st.ToCharArray(), 0, st.Length);
                    //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                    writer.WriteLine();
                }
            }
            catch (System.IO.IOException e)
            {
                //            throw e;
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //logger.error("Error while writing file: ", e.Message);
                //logger.debug(e);
            }
        }
コード例 #2
0
        /// <summary> Writes a single frame to the Writer.
        ///
        /// <p>Format:
        /// <pre>
        /// line      data
        /// -------    --------------------------
        /// 1       spacegroup
        /// 2,3,4     cell parameter: a
        /// 5,6,7                     b
        /// 8,9,10                    c
        /// 11       number of atoms
        /// 12       number of asym. units
        /// 13-16     atomtype: charge, atomcoord x, y, z
        /// 17-20     idem second atom
        /// 21-24     idem third atom etc
        /// </pre>
        ///
        /// </summary>
        /// <param name="crystal">the Crystal to serialize
        /// </param>
        //UPGRADE_NOTE: Access modifiers of method 'write' were changed to 'public'. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1204'"
        public void write(ICrystal crystal)
        {
            System.String sg = crystal.SpaceGroup;
            if ("P 2_1 2_1 2_1".Equals(sg))
            {
                write("P 21 21 21 (1)\n");
            }
            else
            {
                write("P 1 (1)\n");
            }

            // output unit cell axes
            writeVector3d(crystal.A);
            writeVector3d(crystal.B);
            writeVector3d(crystal.C);

            // output number of atoms
            int noatoms = crystal.AtomCount;

            write(((System.Int32)noatoms).ToString());
            write("\n");

            // output number of asym. units (Z)
            if (sg.Equals("P1"))
            {
                write("1\n");
            }
            else
            {
                // duno
                write("1\n");
            }

            // output atoms
            for (int i = 0; i < noatoms; i++)
            {
                // output atom sumbol
                IAtom atom = crystal.getAtomAt(i);
                write(atom.Symbol);
                write(":");
                // output atom charge
                write(((double)atom.getCharge()).ToString() + "\n");
                // output coordinates
                write(((double)atom.X3d).ToString() + "\n");
                write(((double)atom.Y3d).ToString() + "\n");
                write(((double)atom.Z3d).ToString() + "\n");
            }
        }
コード例 #3
0
ファイル: HINWriter.cs プロジェクト: carlhuth/GenXSource
        /// <summary> writes all the molecules supplied in a SetOfMolecules class to
        /// a single HIN file. You can also supply a single Molecule object
        /// as well
        /// </summary>
        /// <param name="mol">the Molecule to write
        /// </param>
        private void writeMolecule(ISetOfMolecules som)
        {
            //int na = 0;
            //String info = "";
            System.String sym  = "";
            double        chrg = 0.0;

            //boolean writecharge = true;

            for (int molnum = 0; molnum < som.MoleculeCount; molnum++)
            {
                IMolecule mol = som.getMolecule(molnum);

                try
                {
                    int natom = mol.AtomCount;
                    int nbond = mol.getBondCount();

                    System.String molname = "mol " + (molnum + 1) + " " + ((System.String)mol.getProperty(CDKConstants.TITLE));

                    //UPGRADE_NOTE: Exceptions thrown by the equivalent in .NET of method 'java.io.BufferedWriter.write' may be different. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1099'"
                    writer.Write(molname.ToCharArray(), 0, molname.Length);
                    //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                    writer.WriteLine();

                    // Loop through the atoms and write them out:
                    IAtom[] atoms = mol.Atoms;
                    IBond[] bonds = mol.Bonds;

                    for (int i = 0; i < natom; i++)
                    {
                        System.String line = "atom ";
                        IAtom         a    = atoms[i];

                        sym  = a.Symbol;
                        chrg = a.getCharge();
                        Point3d p3 = a.getPoint3d();

                        line = line + ((System.Int32)(i + 1)).ToString() + " - " + sym + " ** - " + ((double)chrg).ToString() + " " + p3.x.ToString() + " " + p3.y.ToString() + " " + p3.z.ToString() + " ";

                        System.String buf  = "";
                        int           ncon = 0;
                        for (int j = 0; j < nbond; j++)
                        {
                            IBond b = bonds[j];
                            if (b.contains(a))
                            {
                                // current atom is in the bond so lets get the connected atom
                                IAtom         ca     = b.getConnectedAtom(a);
                                double        bo     = b.Order;
                                int           serial = -1;
                                System.String bt     = "";

                                // get the serial no for this atom
                                serial = mol.getAtomNumber(ca);

                                if (bo == 1)
                                {
                                    bt = new System.Text.StringBuilder("s").ToString();
                                }
                                else if (bo == 2)
                                {
                                    bt = new System.Text.StringBuilder("d").ToString();
                                }
                                else if (bo == 3)
                                {
                                    bt = new System.Text.StringBuilder("t").ToString();
                                }
                                else if (bo == 1.5)
                                {
                                    bt = new System.Text.StringBuilder("a").ToString();
                                }
                                buf = buf + ((System.Int32)(serial + 1)).ToString() + " " + bt + " ";
                                ncon++;
                            }
                        }
                        line = line + " " + ((System.Int32)ncon).ToString() + " " + buf;
                        //UPGRADE_NOTE: Exceptions thrown by the equivalent in .NET of method 'java.io.BufferedWriter.write' may be different. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1099'"
                        writer.Write(line.ToCharArray(), 0, line.Length);
                        //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                        writer.WriteLine();
                    }
                    System.String buf2 = "endmol " + (molnum + 1);
                    //UPGRADE_NOTE: Exceptions thrown by the equivalent in .NET of method 'java.io.BufferedWriter.write' may be different. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1099'"
                    writer.Write(buf2.ToCharArray(), 0, buf2.Length);
                    //UPGRADE_TODO: Method 'java.io.BufferedWriter.newLine' was converted to 'System.IO.TextWriter.WriteLine' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                    writer.WriteLine();
                }
                catch (System.IO.IOException e)
                {
                    throw e;
                }
            }
        }