/// <summary> Method that assign properties to an atom given a particular atomType.
        /// 
        /// </summary>
        /// <param name="atom"> Atom to configure
        /// </param>
        /// <param name="atomType">   AtomType
        /// </param>
        public static void configure(IAtom atom, IAtomType atomType)
        {
            atom.AtomTypeName = atomType.AtomTypeName;
            atom.MaxBondOrder = atomType.MaxBondOrder;
            atom.BondOrderSum = atomType.BondOrderSum;
            atom.VanderwaalsRadius = atomType.VanderwaalsRadius;
            atom.CovalentRadius = atomType.CovalentRadius;
            atom.Valency = atomType.Valency;
            atom.setFormalCharge(atomType.getFormalCharge());
            atom.Hybridization = atomType.Hybridization;
            atom.FormalNeighbourCount = atomType.FormalNeighbourCount;
            atom.setFlag(CDKConstants.IS_HYDROGENBOND_ACCEPTOR, atomType.getFlag(CDKConstants.IS_HYDROGENBOND_ACCEPTOR));
            atom.setFlag(CDKConstants.IS_HYDROGENBOND_DONOR, atomType.getFlag(CDKConstants.IS_HYDROGENBOND_DONOR));
            System.Object constant = atomType.getProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT);
            if (constant != null)
            {
                atom.setProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT, constant);
            }
            atom.setFlag(CDKConstants.ISAROMATIC, atomType.getFlag(CDKConstants.ISAROMATIC));

            System.Object color = atomType.getProperty("org.openscience.cdk.renderer.color");
            if (color != null)
            {
                atom.setProperty("org.openscience.cdk.renderer.color", color);
            }
            if (atomType.AtomicNumber != 0)
            {
                atom.AtomicNumber = atomType.AtomicNumber;
            }
            if (atomType.getExactMass() > 0.0)
            {
                atom.setExactMass(atomType.getExactMass());
            }
        }
Beispiel #2
0
        /// <summary> Method that assign properties to an atom given a particular atomType.
        ///
        /// </summary>
        /// <param name="atom"> Atom to configure
        /// </param>
        /// <param name="atomType">   AtomType
        /// </param>
        public static void configure(IAtom atom, IAtomType atomType)
        {
            atom.AtomTypeName      = atomType.AtomTypeName;
            atom.MaxBondOrder      = atomType.MaxBondOrder;
            atom.BondOrderSum      = atomType.BondOrderSum;
            atom.VanderwaalsRadius = atomType.VanderwaalsRadius;
            atom.CovalentRadius    = atomType.CovalentRadius;
            atom.Valency           = atomType.Valency;
            atom.setFormalCharge(atomType.getFormalCharge());
            atom.Hybridization        = atomType.Hybridization;
            atom.FormalNeighbourCount = atomType.FormalNeighbourCount;
            atom.setFlag(CDKConstants.IS_HYDROGENBOND_ACCEPTOR, atomType.getFlag(CDKConstants.IS_HYDROGENBOND_ACCEPTOR));
            atom.setFlag(CDKConstants.IS_HYDROGENBOND_DONOR, atomType.getFlag(CDKConstants.IS_HYDROGENBOND_DONOR));
            System.Object constant = atomType.getProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT);
            if (constant != null)
            {
                atom.setProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT, constant);
            }
            atom.setFlag(CDKConstants.ISAROMATIC, atomType.getFlag(CDKConstants.ISAROMATIC));

            System.Object color = atomType.getProperty("org.openscience.cdk.renderer.color");
            if (color != null)
            {
                atom.setProperty("org.openscience.cdk.renderer.color", color);
            }
            if (atomType.AtomicNumber != 0)
            {
                atom.AtomicNumber = atomType.AtomicNumber;
            }
            if (atomType.getExactMass() > 0.0)
            {
                atom.setExactMass(atomType.getExactMass());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Set integer FormalCharge for an atom
        /// </summary>
        /// <param name="atom"></param>
        /// <param name="charge"></param>

        public static void SetFormalCharge(
            IAtom atom,
            int charge)
        {
            atom.setFormalCharge(new java.lang.Integer(charge));
            return;
        }
Beispiel #4
0
        /// <summary> Procedure required by the CDOInterface. This function is only
        /// supposed to be called by the JCFL library
        /// </summary>
        public virtual void setObjectProperty(System.String objectType, System.String propertyType, System.String propertyValue)
        {
            //logger.debug("objectType: " + objectType);
            //logger.debug("propType: " + propertyType);
            //logger.debug("property: " + propertyValue);

            if (objectType == null)
            {
                //logger.error("Cannot add property for null object");
                return;
            }
            if (propertyType == null)
            {
                //logger.error("Cannot add property for null property type");
                return;
            }
            if (propertyValue == null)
            {
                //logger.warn("Will not add null property");
                return;
            }

            if (objectType.Equals("Molecule"))
            {
                if (propertyType.Equals("id"))
                {
                    currentMolecule.ID = propertyValue;
                }
                else if (propertyType.Equals("inchi"))
                {
                    currentMolecule.setProperty("iupac.nist.chemical.identifier", propertyValue);
                }
                else if (propertyType.Equals("pdb:residueName"))
                {
                    currentMolecule.setProperty(new DictRef(propertyType, propertyValue), propertyValue);
                }
                else if (propertyType.Equals("pdb:oneLetterCode"))
                {
                    currentMolecule.setProperty(new DictRef(propertyType, propertyValue), propertyValue);
                }
                else if (propertyType.Equals("pdb:id"))
                {
                    currentMolecule.setProperty(new DictRef(propertyType, propertyValue), propertyValue);
                }
                else
                {
                    //logger.warn("Not adding molecule property!");
                }
            }
            else if (objectType.Equals("PseudoAtom"))
            {
                if (propertyType.Equals("label"))
                {
                    if (!(currentAtom is IPseudoAtom))
                    {
                        currentAtom = currentChemFile.Builder.newPseudoAtom(currentAtom);
                    }
                    ((IPseudoAtom)currentAtom).Label = propertyValue;
                }
            }
            else if (objectType.Equals("Atom"))
            {
                if (propertyType.Equals("type"))
                {
                    if (propertyValue.Equals("R") && !(currentAtom is IPseudoAtom))
                    {
                        currentAtom = currentChemFile.Builder.newPseudoAtom(currentAtom);
                    }
                    currentAtom.Symbol = propertyValue;
                }
                else if (propertyType.Equals("x2"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.X2d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("y2"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.Y2d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("x3"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.X3d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("y3"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.Y3d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("z3"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.Z3d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("xFract"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.FractX3d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("yFract"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.FractY3d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("zFract"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.FractZ3d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("formalCharge"))
                {
                    currentAtom.setFormalCharge(System.Int32.Parse(propertyValue));
                }
                else if (propertyType.Equals("charge") || propertyType.Equals("partialCharge"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.setCharge(System.Double.Parse(propertyValue));
                }
                else if (propertyType.Equals("hydrogenCount"))
                {
                    currentAtom.setHydrogenCount(System.Int32.Parse(propertyValue));
                }
                else if (propertyType.Equals("dictRef"))
                {
                    currentAtom.setProperty("org.openscience.cdk.dict", propertyValue);
                }
                else if (propertyType.Equals("atomicNumber"))
                {
                    currentAtom.AtomicNumber = System.Int32.Parse(propertyValue);
                }
                else if (propertyType.Equals("massNumber"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.MassNumber = (int)(System.Double.Parse(propertyValue));
                }
                else if (propertyType.Equals("spinMultiplicity"))
                {
                    int unpairedElectrons = System.Int32.Parse(propertyValue) - 1;
                    for (int i = 0; i < unpairedElectrons; i++)
                    {
                        currentMolecule.addElectronContainer(currentChemFile.Builder.newSingleElectron(currentAtom));
                    }
                }
                else if (propertyType.Equals("id"))
                {
                    //logger.debug("id: ", propertyValue);
                    currentAtom.ID = propertyValue;
                    atomEnumeration[propertyValue] = (System.Int32)numberOfAtoms;
                }
            }
            else if (objectType.Equals("Bond"))
            {
                if (propertyType.Equals("atom1"))
                {
                    bond_a1 = System.Int32.Parse(propertyValue);
                }
                else if (propertyType.Equals("atom2"))
                {
                    bond_a2 = System.Int32.Parse(propertyValue);
                }
                else if (propertyType.Equals("id"))
                {
                    //logger.debug("id: " + propertyValue);
                    bond_id = propertyValue;
                }
                else if (propertyType.Equals("order"))
                {
                    try
                    {
                        bond_order = System.Double.Parse(propertyValue);
                    }
                    catch (System.Exception e)
                    {
                        //logger.error("Cannot convert to double: " + propertyValue);
                        bond_order = 1.0;
                    }
                }
                else if (propertyType.Equals("stereo"))
                {
                    if (propertyValue.Equals("H"))
                    {
                        bond_stereo = CDKConstants.STEREO_BOND_DOWN;
                    }
                    else if (propertyValue.Equals("W"))
                    {
                        bond_stereo = CDKConstants.STEREO_BOND_UP;
                    }
                }
            }
            else if (objectType.Equals("Reaction"))
            {
                if (propertyType.Equals("id"))
                {
                    currentReaction.ID = propertyValue;
                }
            }
            else if (objectType.Equals("SetOfReactions"))
            {
                if (propertyType.Equals("id"))
                {
                    currentSetOfReactions.ID = propertyValue;
                }
            }
            else if (objectType.Equals("Reactant"))
            {
                if (propertyType.Equals("id"))
                {
                    currentMolecule.ID = propertyValue;
                }
            }
            else if (objectType.Equals("Product"))
            {
                if (propertyType.Equals("id"))
                {
                    currentMolecule.ID = propertyValue;
                }
            }
            else if (objectType.Equals("Crystal"))
            {
                // set these variables
                if (currentMolecule is ICrystal)
                {
                    ICrystal current = (ICrystal)currentMolecule;
                    if (propertyType.Equals("spacegroup"))
                    {
                        //logger.debug("Setting crystal spacegroup to: " + propertyValue);
                        current.SpaceGroup = propertyValue;
                    }
                    else if (propertyType.Equals("z"))
                    {
                        try
                        {
                            //logger.debug("Setting z to: " + propertyValue);
                            current.Z = System.Int32.Parse(propertyValue);
                        }
                        catch (System.FormatException exception)
                        {
                            //logger.error("Error in format of Z value");
                        }
                    }
                }
                else
                {
                    //logger.warn("Cannot add crystal cell parameters to a non " + "Crystal class!");
                }
            }
            else if (objectType.Equals("a-axis") || objectType.Equals("b-axis") || objectType.Equals("c-axis"))
            {
                // set these variables
                if (currentMolecule is ICrystal)
                {
                    //logger.debug("Setting axis (" + objectType + "): " + propertyValue);
                    if (propertyType.Equals("x"))
                    {
                        crystal_axis_x = System.Double.Parse(propertyValue);
                    }
                    else if (propertyType.Equals("y"))
                    {
                        crystal_axis_y = System.Double.Parse(propertyValue);
                    }
                    else if (propertyType.Equals("z"))
                    {
                        crystal_axis_z = System.Double.Parse(propertyValue);
                    }
                }
                else
                {
                    //logger.warn("Cannot add crystal cell parameters to a non " + "Crystal class!");
                }
            }
            //logger.debug("Object property set...");
        }
Beispiel #5
0
        /// <summary> Reads the atoms, coordinates and charges.
        ///
        /// <p>IMPORTANT: it does not support the atom list and its negation!
        /// </summary>
        public virtual void readAtomBlock(IAtomContainer readData)
        {
            bool foundEND = false;

            while (Ready && !foundEND)
            {
                System.String command = readCommand();
                if ("END ATOM".Equals(command))
                {
                    // FIXME: should check wether 3D is really 2D
                    foundEND = true;
                }
                else
                {
                    //logger.debug("Parsing atom from: " + command);
                    SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(command);
                    IAtom atom = readData.Builder.newAtom("C");
                    // parse the index
                    try
                    {
                        System.String indexString = tokenizer.NextToken();
                        atom.ID = indexString;
                    }
                    catch (System.Exception exception)
                    {
                        System.String error = "Error while parsing atom index";
                        //logger.error(error);
                        //logger.debug(exception);
                        throw new CDKException(error, exception);
                    }
                    // parse the element
                    System.String element   = tokenizer.NextToken();
                    bool          isElement = false;
                    try
                    {
                        isElement = IsotopeFactory.getInstance(atom.Builder).isElement(element);
                    }
                    catch (System.Exception exception)
                    {
                        throw new CDKException("Could not determine if element exists!", exception);
                    }
                    if (isPseudoAtom(element))
                    {
                        atom = readData.Builder.newPseudoAtom(atom);
                    }
                    else if (isElement)
                    {
                        atom.Symbol = element;
                    }
                    else
                    {
                        System.String error = "Cannot parse element of type: " + element;
                        //logger.error(error);
                        throw new CDKException("(Possible CDK bug) " + error);
                    }
                    // parse atom coordinates (in Angstrom)
                    try
                    {
                        System.String xString = tokenizer.NextToken();
                        System.String yString = tokenizer.NextToken();
                        System.String zString = tokenizer.NextToken();
                        double        x       = System.Double.Parse(xString);
                        double        y       = System.Double.Parse(yString);
                        double        z       = System.Double.Parse(zString);
                        atom.setPoint3d(new Point3d(x, y, z));
                        atom.setPoint2d(new Point2d(x, y)); // FIXME: dirty!
                    }
                    catch (System.Exception exception)
                    {
                        System.String error = "Error while parsing atom coordinates";
                        //logger.error(error);
                        //logger.debug(exception);
                        throw new CDKException(error, exception);
                    }
                    // atom-atom mapping
                    System.String mapping = tokenizer.NextToken();
                    if (!mapping.Equals("0"))
                    {
                        //logger.warn("Skipping atom-atom mapping: " + mapping);
                    } // else: default 0 is no mapping defined

                    // the rest are key value things
                    if (command.IndexOf("=") != -1)
                    {
                        System.Collections.Hashtable   options = parseOptions(exhaustStringTokenizer(tokenizer));
                        System.Collections.IEnumerator keys    = options.Keys.GetEnumerator();
                        //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationhasMoreElements'"
                        while (keys.MoveNext())
                        {
                            //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilEnumerationnextElement'"
                            System.String key           = (System.String)keys.Current;
                            System.String value_Renamed = (System.String)options[key];
                            try
                            {
                                if (key.Equals("CHG"))
                                {
                                    int charge = System.Int32.Parse(value_Renamed);
                                    if (charge != 0)
                                    {
                                        // zero is no charge specified
                                        atom.setFormalCharge(charge);
                                    }
                                }
                                else
                                {
                                    //logger.warn("Not parsing key: " + key);
                                }
                            }
                            catch (System.Exception exception)
                            {
                                //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'"
                                System.String error = "Error while parsing key/value " + key + "=" + value_Renamed + ": " + exception.Message;
                                //logger.error(error);
                                //logger.debug(exception);
                                throw new CDKException(error, exception);
                            }
                        }
                    }

                    // store atom
                    readData.addAtom(atom);
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    //logger.debug("Added atom: " + atom);
                }
            }
        }