Пример #1
0
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            selectedElement = null;

            if (!Enabled)
            {
                return;
            }

            // test hit on element
            int group  = 19 * (ptWidth / (e.X - tableOrigin.Width));
            int period = 8 * (ptHeight / (e.Y - tableOrigin.Height));

            if (group > 1 && period > 1 && group < 20 && period < 9)
            {
                // look for element fitting desc
                foreach (PeriodicTableElement element in ElementPTFactory.Instance)
                {
                    if (element.Group.Length > 0)
                    {
                        if (group == int.Parse(element.Group) &&
                            period == int.Parse(element.Period))
                        {
                            selectedElement = element;
                            break;
                        }
                    }
                }
            }

            if (OnElementSelect != null)
            {
                OnElementSelect(this, null);
            }
        }
Пример #2
0
 public override void startElement(System.String uri, System.String local, System.String raw, SaxAttributesSupport atts)
 {
     currentChars = "";
     dictRef      = "";
     //logger.debug("startElement: ", raw);
     //logger.debug("uri: ", uri);
     //logger.debug("local: ", local);
     //logger.debug("raw: ", raw);
     if ("elementType".Equals(local))
     {
         for (int i = 0; i < atts.GetLength(); i++)
         {
             if ("id".Equals(atts.GetFullName(i)))
             {
                 elementType = new PeriodicTableElement(atts.GetValue(i));
             }
         }
     }
     else if ("scalar".Equals(local))
     {
         for (int i = 0; i < atts.GetLength(); i++)
         {
             if ("dictRef".Equals(atts.GetFullName(i)))
             {
                 if ("cas:id".Equals(atts.GetValue(i)))
                 {
                     scalarType = LABEL_CAS;
                 }
                 else if ("cdk:name".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_NAME;
                 }
                 else if ("cdk:atomicNumber".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_ATOMICNUMBER;
                 }
                 else if ("cdk:name".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_NAME;
                 }
                 else if ("cdk:chemicalSerie".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_CHEMICALSERIE;
                 }
                 else if ("cdk:period".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_PERIOD;
                 }
                 else if ("cdk:group".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_GROUP;
                 }
                 else if ("cdk:phase".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_PHASE;
                 }
             }
         }
     }
 }
Пример #3
0
        public AtomWrapper(IAtom atom)
        {
            this.atom = atom;

            // rip some stats from the atom
            pe = (PeriodicTableElement)atom.Properties["PeriodicTableElement"];
        }
Пример #4
0
        /// <summary>  Configures an element. Finds the correct element type
        /// by looking at the element symbol.
        ///
        /// </summary>
        /// <param name="element">    The element to be configure
        /// </param>
        /// <returns>             The configured atom
        /// </returns>
        public virtual PeriodicTableElement configure(PeriodicTableElement element)
        {
            PeriodicTableElement elementInt = getElement(element.Symbol);

            element.Symbol        = elementInt.Symbol;
            element.AtomicNumber  = elementInt.AtomicNumber;
            element.Name          = elementInt.Name;
            element.ChemicalSerie = elementInt.ChemicalSerie;
            element.Period        = elementInt.Period;
            element.Group         = elementInt.Group;
            element.Phase         = elementInt.Phase;
            element.CASid         = elementInt.CASid;
            return(element);
        }
Пример #5
0
        private void CreatePreviewMolecule()
        {
            atoms = new IAtom[] { new Atom("O", new Point3d(0, 0, 0)), new Atom("H", new Point3d(0, 0, 1)) };

            ElementPTFactory elements = ElementPTFactory.Instance;

            foreach (IAtom atom in atoms)
            {
                PeriodicTableElement pe = elements.getElement(atom.Symbol);
                if (pe != null)
                {
                    atom.AtomicNumber = pe.AtomicNumber;
                    atom.Properties["PeriodicTableElement"] = pe;
                    atom.Properties["Period"] = int.Parse(pe.Period);
                }
            }

            bonds = new IBond[] { new Bond(atoms[0], atoms[1], 1) };

            projMat = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, Width / Height, 0.1f, 20);
            viewMat = Matrix.LookAtLH(new Vector3(2, 3, -1), new Vector3(0, 0, 1), new Vector3(0, 1, 0));
        }
        public override void LoadModuleSettings(HashTableSettings settings)
        {
            //settings["Materials.Molecules.IMoleculeMaterialLookup"] = this;

            // load molecule settings from xml resource
            ColorConverter cc  = new ColorConverter();
            Stream         str = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenSVisualLib.Molecule.config");
            XmlDocument    doc = new XmlDocument();

            doc.Load(str);

            // load series settings
            XmlNodeList series = doc.SelectNodes("configuration/chemicalSeries/chemicalSerie");

            foreach (XmlNode serie in series)
            {
                string id        = serie.Attributes["id"].InnerText;
                Color  baseColor = (Color)cc.ConvertFromString(serie.SelectSingleNode("color").Attributes["desc"].InnerText);

                this.series[id] = new AtomMaterial(baseColor);
            }

            // load symbols
            XmlNodeList      symbols    = doc.SelectNodes("configuration/chemicalSymbols/symbol");
            ElementPTFactory ptElements = ElementPTFactory.Instance;

            foreach (XmlNode symbol in symbols)
            {
                string id        = symbol.Attributes["id"].InnerText;
                Color  baseColor = (Color)cc.ConvertFromString(symbol.SelectSingleNode("color").Attributes["desc"].InnerText);

                PeriodicTableElement element = ptElements.getElement(id);

                IMoleculeMaterial serie = null;
                this.series.TryGetValue(element.ChemicalSerie, out serie);

                elements[id] = new MoleculeMaterialTemplate(new AtomMaterial(baseColor), serie);
            }
        }
Пример #7
0
        public Texture this[string symbol]
        {
            get
            {
                Texture tex = null;
                if (symbolTextures.TryGetValue(symbol, out tex))
                {
                    return(tex);
                }
                // try load
                ElementPTFactory     elements = ElementPTFactory.Instance;
                PeriodicTableElement element  = elements.getElement(symbol);
                if (element != null)
                {
                    System.Drawing.Font font = new System.Drawing.Font("Tahoma", 20);
                    tex = TextTexture.DrawTextToTexture(element.Symbol,
                                                        font, device, 64, 64).Texture;

                    return(symbolTextures[element.Symbol] = tex);
                }
                return(null);
            }
        }
Пример #8
0
        private void CreatePreviewData()
        {
            atoms = new IAtom[] { new Atom("O", new Point3d(0, 0, 0)) };

            ElementPTFactory elements = ElementPTFactory.Instance;

            foreach (IAtom atom in atoms)
            {
                PeriodicTableElement pe = elements.getElement(atom.Symbol);
                if (pe != null)
                {
                    atom.AtomicNumber = pe.AtomicNumber;
                    atom.Properties["PeriodicTableElement"] = pe;
                    atom.Properties["Period"] = int.Parse(pe.Period);
                }
            }

            projMat = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, Width / Height, 0.1f, 20);
            viewMat = Matrix.LookAtLH(new Vector3(2, 0, 0), new Vector3(0, 0, 0), new Vector3(0, 1, 0));

            latestCoDesc = CompleteOutputDescription.New();
            latestCoDesc.SchemeSettings         = new BallAndStickSchemeSettings();
            latestCoDesc.SchemeSettings.AtomLOD = 3;
        }
Пример #9
0
        public override void CreateGeometryForObjects(Device device, ICollection <IAtom> objs, GeomDataBufferStream geomStream,
                                                      int stream, ref BufferedGeometryData buffer,
                                                      CompleteOutputDescription coDesc)
        {
            // fillable fields
            int positionPos = -1;
            int normalPos   = -1;
            int diffusePos  = -1;
            int texPos      = -1;

            // match field locations
            //int[] fieldsPos = new int[fields.Length];
            for (int i = 0; i < fields.Length; i++)
            {
                for (int gf = 0; gf < geomStream.Fields.Length; gf++)
                {
                    if (fields[i].Format == geomStream.Fields[gf])
                    {
                        if (fields[i].Usage == "POSITION")
                        {
                            positionPos = geomStream.FieldPositions[gf];
                        }
                        else if (fields[i].Usage == "NORMAL")
                        {
                            normalPos = geomStream.FieldPositions[gf];
                        }
                        else if (fields[i].Usage == "DIFFUSE")
                        {
                            diffusePos = geomStream.FieldPositions[gf];
                        }
                        else if (fields[i].Usage == "TEXTURE0")
                        {
                            texPos = geomStream.FieldPositions[gf];
                        }
                        //fieldsPos[i] = geomStream.FieldPositions[gf];
                        break;
                    }
                }
            }

            int numVerts = sphereDetail1 * sphereDetail2 * 6;
            int numTris  = sphereDetail1 * sphereDetail2 * 2;

            // create buffers
            buffer                    = new BufferedGeometryData(device, objs.Count);
            buffer.vBuffers           = new BufferedGeometryData.VertexData[1];
            buffer.vBuffers[0]        = new BufferedGeometryData.VertexData();
            buffer.vBuffers[0].Buffer = new VertexBuffer(device, geomStream.Stride * numVerts * objs.Count,
                                                         Usage.WriteOnly, geomStream.Format, Pool.Managed);
            buffer.vBuffers[0].Stride      = geomStream.Stride;
            buffer.vBuffers[0].NumElements = objs.Count * numVerts;
            buffer.vBuffers[0].Format      = geomStream.Format;

            buffer.iBuffers                  = new BufferedGeometryData.IndexData[1];
            buffer.iBuffers[0]               = new BufferedGeometryData.IndexData();
            buffer.iBuffers[0].Desc          = BufferedGeometryData.IndexData.Description.Geometry;
            buffer.iBuffers[0].NumPrimitives = objs.Count * numTris;
            buffer.iBuffers[0].PrimType      = PrimitiveType.TriangleList;

            // lock stream
            GraphicsStream data = buffer.vBuffers[0].Buffer.Lock(0, 0, LockFlags.None);

            // fill fields
            bool newWay = true;

            if (!newWay)
            {
                // create template sphere
                SphereMathHelper.SphereN sphere = SphereMathHelper.CalcSphereWNormals(sphereDetail1, sphereDetail2, 1.0f, new Vector3(), true);

                // clone and scale template for each size required
                Vector3 center = new Vector3();
                Dictionary <int, Vector3[]> spheres  = new Dictionary <int, Vector3[]>();
                AtomShadingDesc             aShading = coDesc.AtomShadingDesc;

                //int vertsIdx = 0;
                long pos = 0;
                foreach (IAtom atom in objs)
                {
                    int period = 1;
                    if (atom.Properties.ContainsKey("Period"))
                    {
                        period = (int)atom.Properties["Period"];
                    }

                    // check for existing
                    if (!spheres.ContainsKey(period))
                    {
                        // scale template
                        float     size      = period * _Scaling;
                        Vector4[] vertices  = Vector3.Transform(sphere.Positions, Matrix.Scaling(size, size, size));
                        Vector3[] vertices3 = new Vector3[vertices.Length];
                        for (int i = 0; i < vertices.Length; i++)
                        {
                            vertices3[i] = new Vector3(vertices[i].X, vertices[i].Y, vertices[i].Z);
                        }
                        spheres.Add(period, vertices3);
                    }
                    Vector3[] sphereData = spheres[period];

                    // write to buffer
                    IMoleculeMaterialLookup   lookup   = aShading.MoleculeMaterials;
                    IMoleculeMaterialTemplate matTemp  = lookup.ResolveBySymbol(atom.Symbol);
                    IMoleculeMaterial         material = null;
                    if (matTemp != null)
                    {
                        material = matTemp.BySymbol;
                    }
                    else
                    {
                        PeriodicTableElement pe = (PeriodicTableElement)atom.Properties["PeriodicTableElement"];
                        if (pe != null)
                        {
                            material = lookup.GetBySeries(pe.ChemicalSerie);
                        }
                    }

                    // copy sphere
                    Vector3 atomSpace = new Vector3((float)atom.X3d, (float)atom.Y3d, (float)atom.Z3d);

                    /*Vector4 clr = new Vector4((float)material.BaseColor.R / 255f, (float)material.BaseColor.G / 255f,
                     *                        (float)material.BaseColor.B / 255f, (float)material.BaseColor.A / 255f);*/
                    int clr = material.BaseColor.ToArgb();
                    for (int v = 0; v < sphereData.Length; v++)
                    {
                        if (positionPos != -1)
                        {
                            Vector3 position = sphereData[v] + atomSpace;
                            data.Seek(pos + positionPos, SeekOrigin.Begin);
                            data.Write(position.X);
                            data.Write(position.Y);
                            data.Write(position.Z);
                        }
                        if (texPos != -1)
                        {
                            data.Seek(pos + texPos, SeekOrigin.Begin);
                            data.Write(0f); //sphere.TexCoords[v].X);
                            data.Write(0f); //sphere.TexCoords[v].Y);
                        }
                        if (normalPos != -1)
                        {
                            data.Seek(pos + normalPos, SeekOrigin.Begin);
                            data.Write(sphere.Normals[v].X);
                            data.Write(sphere.Normals[v].Y);
                            data.Write(sphere.Normals[v].Z);
                        }
                        if (diffusePos != -1)
                        {
                            data.Seek(pos + diffusePos, SeekOrigin.Begin);

                            /*data.Write(clr.X);
                            *  data.Write(clr.Y);
                            *  data.Write(clr.Z);
                            *  data.Write(clr.W);*/
                            data.Write((Int32)clr);
                        }
                        pos += geomStream.Stride;
                    }
                }
            }
            else
            {
                Vector3[] Positions, normals;
                Vector2[] texCoords;
                SphereMathHelper.CreateSphereTriangles(new Vector3(), 1, sphereDetail1, out Positions,
                                                       out normals, out texCoords);

                // clone and scale template for each size required
                Vector3 center = new Vector3();
                Dictionary <int, Vector3[]> spheres  = new Dictionary <int, Vector3[]>();
                AtomShadingDesc             aShading = coDesc.AtomShadingDesc;

                int  vertsIdx = 0;
                long pos      = 0;
                foreach (IAtom atom in objs)
                {
                    int period = 1;
                    if (atom.Properties.ContainsKey("Period"))
                    {
                        period = (int)atom.Properties["Period"];
                    }

                    // check for existing
                    if (!spheres.ContainsKey(period))
                    {
                        // scale template
                        float     size      = period * _Scaling;
                        Vector4[] vertices  = Vector3.Transform(Positions, Matrix.Scaling(size, size, size));
                        Vector3[] vertices3 = new Vector3[vertices.Length];
                        for (int i = 0; i < vertices.Length; i++)
                        {
                            vertices3[i] = new Vector3(vertices[i].X, vertices[i].Y, vertices[i].Z);
                        }
                        spheres.Add(period, vertices3);
                    }
                    Vector3[] sphereData = spheres[period];

                    // write to buffer
                    IMoleculeMaterialLookup   lookup   = aShading.MoleculeMaterials;
                    IMoleculeMaterialTemplate matTemp  = lookup.ResolveBySymbol(atom.Symbol);
                    IMoleculeMaterial         material = null;
                    if (matTemp != null)
                    {
                        material = matTemp.BySymbol;
                    }
                    else
                    {
                        PeriodicTableElement pe = (PeriodicTableElement)atom.Properties["PeriodicTableElement"];
                        if (pe != null)
                        {
                            material = lookup.GetBySeries(pe.ChemicalSerie);
                        }
                    }

                    // copy sphere
                    Vector3 atomSpace = new Vector3((float)atom.X3d, (float)atom.Y3d, (float)atom.Z3d);
                    int     clr       = material.BaseColor.ToArgb();
                    for (int v = 0; v < sphereData.Length; v++)
                    {
                        if (positionPos != -1)
                        {
                            Vector3 position = sphereData[v] + atomSpace;
                            data.Seek(pos + positionPos, SeekOrigin.Begin);
                            data.Write(position.X);
                            data.Write(position.Y);
                            data.Write(position.Z);
                        }
                        if (texPos != -1)
                        {
                            data.Seek(pos + texPos, SeekOrigin.Begin);
                            data.Write(texCoords[v].X);
                            data.Write(texCoords[v].Y);
                        }
                        if (normalPos != -1)
                        {
                            data.Seek(pos + normalPos, SeekOrigin.Begin);
                            data.Write(normals[v].X);
                            data.Write(normals[v].Y);
                            data.Write(normals[v].Z);
                        }
                        if (diffusePos != -1)
                        {
                            data.Seek(pos + diffusePos, SeekOrigin.Begin);

                            /*data.Write(clr.X);
                            *  data.Write(clr.Y);
                            *  data.Write(clr.Z);
                            *  data.Write(clr.W);*/
                            data.Write((Int32)clr);
                        }
                        pos += geomStream.Stride;
                    }
                }
            }

            buffer.vBuffers[0].Buffer.Unlock();
        }
Пример #10
0
        public override void CreateGeometryForObjects(Device device, ICollection <IAtom> objs,
                                                      GeomDataBufferStream geomStream, int stream,
                                                      ref BufferedGeometryData buffer, CompleteOutputDescription coDesc)
        {
            // fillable fields
            int positionPos = -1;
            int sizePos     = -1;
            int diffusePos  = -1;

            // match field locations
            for (int i = 0; i < fields.Length; i++)
            {
                for (int gf = 0; gf < geomStream.Fields.Length; gf++)
                {
                    if (fields[i].Format == geomStream.Fields[gf])
                    {
                        if (fields[i].Usage == "POSITION")
                        {
                            positionPos = geomStream.FieldPositions[gf];
                        }
                        else if (fields[i].Usage == "DIFFUSE")
                        {
                            diffusePos = geomStream.FieldPositions[gf];
                        }
                        else if (fields[i].Usage == "SIZEFLOAT")
                        {
                            sizePos = geomStream.FieldPositions[gf];
                        }
                        break;
                    }
                }
            }

            // create buffers
            buffer                    = new BufferedGeometryData(device, objs.Count);
            buffer.vBuffers           = new BufferedGeometryData.VertexData[1];
            buffer.vBuffers[0]        = new BufferedGeometryData.VertexData();
            buffer.vBuffers[0].Buffer = new VertexBuffer(typeof(MetaBlobsEffect.PointVertex), objs.Count, device, Usage.None, VertexFormats.Position | VertexFormats.PointSize | VertexFormats.Diffuse, Pool.SystemMemory);

            /*new VertexBuffer(device, geomStream.Stride * objs.Count,
             *                                       Usage.WriteOnly, geomStream.Format, Pool.SystemMemory);*/
            buffer.vBuffers[0].Stride      = geomStream.Stride;
            buffer.vBuffers[0].NumElements = objs.Count;
            buffer.vBuffers[0].Format      = geomStream.Format;
            buffer.DataValidity            = BufferedGeometryData.DataValidityType.Source;
            buffer.Target = BufferedGeometryData.DataTarget.Geometry;

            // lock stream
            GraphicsStream data = buffer.vBuffers[0].Buffer.Lock(0, 0, LockFlags.None);

            // fill fields

            // create points
            AtomShadingDesc aShading = coDesc.AtomShadingDesc;
            long            pos      = 0;

            foreach (IAtom atom in objs)
            {
                int period = 1;
                if (atom.Properties.ContainsKey("Period"))
                {
                    period = (int)atom.Properties["Period"];
                }

                if (positionPos != -1)
                {
                    data.Seek(pos + positionPos, SeekOrigin.Begin);
                    data.Write((float)atom.X3d);
                    data.Write((float)atom.Y3d);
                    data.Write((float)atom.Z3d);
                }
                if (sizePos != -1)
                {
                    data.Seek(pos + sizePos, SeekOrigin.Begin);
                    data.Write((float)period);
                }
                if (diffusePos != -1)
                {
                    IMoleculeMaterialLookup   lookup   = aShading.MoleculeMaterials;
                    IMoleculeMaterialTemplate matTemp  = lookup.ResolveBySymbol(atom.Symbol);
                    IMoleculeMaterial         material = null;
                    if (matTemp != null)
                    {
                        material = matTemp.BySymbol;
                    }
                    else
                    {
                        PeriodicTableElement pe = (PeriodicTableElement)atom.Properties["PeriodicTableElement"];
                        if (pe != null)
                        {
                            material = lookup.GetBySeries(pe.ChemicalSerie);
                        }
                    }
                    if (material != null)
                    {
                        data.Seek(pos + diffusePos, SeekOrigin.Begin);
                        //data.Write((float)material.BaseColor.ToArgb());
                        if (material.BaseColor.R > 0)
                        {
                            data.Write(255f / material.BaseColor.R);
                        }
                        else
                        {
                            data.Write((float)0);
                        }
                        if (material.BaseColor.G > 0)
                        {
                            data.Write(255f / material.BaseColor.G);
                        }
                        else
                        {
                            data.Write((float)0);
                        }
                        if (material.BaseColor.B > 0)
                        {
                            data.Write(255f / material.BaseColor.B);
                        }
                        else
                        {
                            data.Write((float)0);
                        }
                    }
                }
                pos += geomStream.Stride;
            }
            buffer.vBuffers[0].Buffer.Unlock();
        }
Пример #11
0
        public static void GenericBondSetup(IBond bond, bool sort, BondShadingDesc bShading,
                                            out Vector3 direction, out Vector3 directionUV,
                                            out IAtom[] atoms, out Vector3[] atomsPos,
                                            out IMoleculeMaterial matA, out IMoleculeMaterial matB)
        {
            atoms = bond.getAtoms();

            Vector3 v1 = new Vector3((float)atoms[0].X3d, (float)atoms[0].Y3d, (float)atoms[0].Z3d);
            Vector3 v2 = new Vector3((float)atoms[1].X3d, (float)atoms[1].Y3d, (float)atoms[1].Z3d);

            direction = v2 - v1;

            atomsPos = new Vector3[2];
            if (sort)
            {
                if (direction.Z < (v1 - v2).Z)
                {
                    IAtom temp = atoms[0];
                    atoms[0] = atoms[1];
                    atoms[1] = temp;

                    atomsPos[0] = v2;
                    atomsPos[1] = v1;
                }
                else
                {
                    atomsPos[0] = v1;
                    atomsPos[1] = v2;
                }

                direction = Vector3.Normalize(atomsPos[1] - atomsPos[0]);
            }
            else
            {
                atomsPos[0] = v1;
                atomsPos[1] = v2;
            }

            directionUV = Vector3.Normalize(direction);

            IMoleculeMaterialLookup   lookup  = bShading.MoleculeMaterials;
            IMoleculeMaterialTemplate matTemp = lookup.ResolveBySymbol(atoms[0].Symbol);

            if (matTemp != null)
            {
                matA = matTemp.BySymbol;
            }
            else
            {
                PeriodicTableElement pe = (PeriodicTableElement)atoms[0].Properties["PeriodicTableElement"];
                matA = lookup.GetBySeries(pe.ChemicalSerie);
            }

            matTemp = lookup.ResolveBySymbol(atoms[1].Symbol);
            if (matTemp != null)
            {
                matB = matTemp.BySymbol;
            }
            else
            {
                PeriodicTableElement pe = (PeriodicTableElement)atoms[1].Properties["PeriodicTableElement"];
                matB = lookup.GetBySeries(pe.ChemicalSerie);
            }
        }
Пример #12
0
        // SAX Parser methods

        public override void startDocument()
        {
            elements = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            scalarType = SCALAR_UNSET;
            elementType = null;
        }
Пример #13
0
 public override void startElement(System.String uri, System.String local, System.String raw, SaxAttributesSupport atts)
 {
     currentChars = "";
     dictRef = "";
     //logger.debug("startElement: ", raw);
     //logger.debug("uri: ", uri);
     //logger.debug("local: ", local);
     //logger.debug("raw: ", raw);
     if ("elementType".Equals(local))
     {
         for (int i = 0; i < atts.GetLength(); i++)
         {
             if ("id".Equals(atts.GetFullName(i)))
             {
                 elementType = new PeriodicTableElement(atts.GetValue(i));
             }
         }
     }
     else if ("scalar".Equals(local))
         for (int i = 0; i < atts.GetLength(); i++)
         {
             if ("dictRef".Equals(atts.GetFullName(i)))
             {
                 if ("cas:id".Equals(atts.GetValue(i)))
                 {
                     scalarType = LABEL_CAS;
                 }
                 else if ("cdk:name".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_NAME;
                 }
                 else if ("cdk:atomicNumber".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_ATOMICNUMBER;
                 }
                 else if ("cdk:name".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_NAME;
                 }
                 else if ("cdk:chemicalSerie".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_CHEMICALSERIE;
                 }
                 else if ("cdk:period".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_PERIOD;
                 }
                 else if ("cdk:group".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_GROUP;
                 }
                 else if ("cdk:phase".Equals(atts.GetValue(i)))
                 {
                     scalarType = SCALAR_PHASE;
                 }
             }
         }
 }
Пример #14
0
        private static void ProcessChemModel(IChemModel chemModel, ISettings settings, FileUsage usage,
                                             MoleculeLoadingResults results, MoleculeProcessingProgress progress,
                                             float sectionSz)
        {
            //if (ChemModelManipulator.getAllInOneContainer(chemModel).getBondCount() == 0)
            //{
            //    return;
            //}

            // check for coordinates
            if ((GeometryTools.has2DCoordinatesNew(ChemModelManipulator.getAllInOneContainer(chemModel)) != 0))//
            {
                results.Num2DCoords++;
            }
            //    usage == FileUsage.TwoD)
            //{
            //    throw new UserLevelException("File has no 2D coords", UserLevelException.ExceptionType.FileLoading,
            //                                 typeof(MoleculeLoader), null);
            //}
            if ((GeometryTools.has2DCoordinatesNew(ChemModelManipulator.getAllInOneContainer(chemModel)) != 0))// &&
            {
                results.Num3DCoords++;
            }
            //    usage == FileUsage.ThreeD)
            //{
            //    throw new UserLevelException("File has no 3D coords", UserLevelException.ExceptionType.FileLoading,
            //                                 typeof(MoleculeLoader), null);
            //}

            ElementPTFactory elements = ElementPTFactory.Instance;

            // calc item sz
            int numItems = 0;

            if (chemModel.SetOfMolecules != null)
            {
                results.NumMolecules += chemModel.SetOfMolecules.MoleculeCount;
                for (int mol = 0; mol < chemModel.SetOfMolecules.MoleculeCount; mol++)
                {
                    numItems += chemModel.SetOfMolecules.Molecules[mol].Atoms.Length;
                    //numItems += chemModel.SetOfMolecules.Molecules[mol].Bonds.Length;
                }
            }
            float itemSz = sectionSz / (float)numItems;

            if (chemModel.SetOfMolecules != null)
            {
                results.NumMolecules += chemModel.SetOfMolecules.MoleculeCount;
                for (int mol = 0; mol < chemModel.SetOfMolecules.MoleculeCount; mol++)
                {
                    IMolecule molecule = chemModel.SetOfMolecules.Molecules[mol];
                    results.NumAtoms += molecule.Atoms.Length;
                    results.NumBonds += molecule.Bonds.Length;
                    foreach (IAtom atom in molecule.Atoms)
                    {
                        PeriodicTableElement pe = elements.getElement(atom.Symbol);
                        if (pe != null)
                        {
                            atom.AtomicNumber = pe.AtomicNumber;
                            atom.Properties["PeriodicTableElement"] = pe;
                            atom.Properties["Period"] = int.Parse(pe.Period);
                        }
                        else
                        {
                            progress.Log(string.Format("Failed to find periodic element: {0}", atom.Symbol), LogItem.ItemLevel.Failure);
                        }
                        progress.UpdateProgress(itemSz);
                    }
                    progress.Log(string.Format("Processed {0} atoms", molecule.Atoms.Length), LogItem.ItemLevel.Info);
                }
            }
            progress.Log("Processed Model", LogItem.ItemLevel.Success);
        }
Пример #15
0
        // SAX Parser methods

        public override void startDocument()
        {
            elements    = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            scalarType  = SCALAR_UNSET;
            elementType = null;
        }
Пример #16
0
        public override void CreateGeometryForObjects(Device device, ICollection <IAtom> objs,
                                                      GeomDataBufferStream geomStream, int stream,
                                                      ref BufferedGeometryData buffer, CompleteOutputDescription coDesc)
        {
            // fillable fields
            int positionPos = -1;
            int normalPos   = -1;
            int diffusePos  = -1;

            // match field locations
            for (int i = 0; i < fields.Length; i++)
            {
                for (int gf = 0; gf < geomStream.Fields.Length; gf++)
                {
                    if (fields[i].Format == geomStream.Fields[gf])
                    {
                        if (fields[i].Usage == "POSITION")
                        {
                            positionPos = geomStream.FieldPositions[gf];
                        }
                        else if (fields[i].Usage == "NORMAL")
                        {
                            normalPos = geomStream.FieldPositions[gf];
                        }
                        else if (fields[i].Usage == "DIFFUSE")
                        {
                            diffusePos = geomStream.FieldPositions[gf];
                        }
                        break;
                    }
                }
            }

            // actually create the metaball triangles or points
            IVolume[]               volumes  = new IVolume[objs.Count];
            int                     sIdx     = 0;
            AtomShadingDesc         aShading = coDesc.AtomShadingDesc;
            IMoleculeMaterialLookup lookup   = aShading.MoleculeMaterials;

            foreach (IAtom atom in objs)
            {
                IMoleculeMaterialTemplate matTemp  = lookup.ResolveBySymbol(atom.Symbol);
                IMoleculeMaterial         material = null;
                if (matTemp != null)
                {
                    material = matTemp.BySymbol;
                }
                else
                {
                    PeriodicTableElement pe = (PeriodicTableElement)atom.Properties["PeriodicTableElement"];
                    if (pe != null)
                    {
                        material = lookup.GetBySeries(pe.ChemicalSerie);
                    }
                }

                volumes[sIdx++] = new Metaball(new Vector3((float)atom.X3d, (float)atom.Y3d, (float)atom.Z3d), 0.17f, material.BaseColor);
            }

            // process volume into triangles
            GenericVolumeScene scene = new GenericVolumeScene(volumes);

            int[]     triangles = null;
            Vector3[] vertices;
            Color[]   colours;
            Vector3[] normals = null;

            if (!pointsOnly)
            {
                IsosurfaceGenerator3D.GenerateSimpleMesh(scene, new Vector3(), scene.EstimateVolumeMaxSize(), 40, false, out triangles, out vertices, out colours);
                MeshOptimzer.GenerateTriPointNormals(triangles, vertices, out normals);
            }
            else
            {
                IsosurfaceGenerator3D.GenerateSimplePointOutline(scene, new Vector3(), scene.EstimateVolumeMaxSize(), 40, out vertices, out colours);
            }

            // create buffers
            buffer                    = new BufferedGeometryData(device, objs.Count);
            buffer.vBuffers           = new BufferedGeometryData.VertexData[1];
            buffer.vBuffers[0]        = new BufferedGeometryData.VertexData();
            buffer.vBuffers[0].Buffer = new VertexBuffer(device, geomStream.Stride * vertices.Length,
                                                         Usage.WriteOnly, geomStream.Format, Pool.Managed);
            buffer.vBuffers[0].Stride      = geomStream.Stride;
            buffer.vBuffers[0].NumElements = vertices.Length;
            buffer.vBuffers[0].Format      = geomStream.Format;

            buffer.iBuffers         = new BufferedGeometryData.IndexData[1];
            buffer.iBuffers[0]      = new BufferedGeometryData.IndexData();
            buffer.iBuffers[0].Desc = BufferedGeometryData.IndexData.Description.Geometry;
            if (pointsOnly)
            {
                buffer.iBuffers[0].NumPrimitives = vertices.Length;
                buffer.iBuffers[0].PrimType      = PrimitiveType.PointList;
                buffer.Light = false;
            }
            else
            {
                buffer.iBuffers[0].NumPrimitives = triangles.Length / 3;
                buffer.iBuffers[0].PrimType      = PrimitiveType.TriangleList;
                buffer.iBuffers[0].Buffer        = new IndexBuffer(typeof(int), triangles.Length, device, Usage.WriteOnly, Pool.Managed);
            }

            // lock stream
            GraphicsStream data = buffer.vBuffers[0].Buffer.Lock(0, 0, LockFlags.None);

            // fill fields

            int  clr = Color.FromArgb(255, 255, 255).ToArgb();
            long pos = 0;

            for (int i = 0; i < vertices.Length; i++)
            {
                if (positionPos != -1)
                {
                    data.Seek(pos + positionPos, SeekOrigin.Begin);
                    data.Write(vertices[i].X);
                    data.Write(vertices[i].Y);
                    data.Write(vertices[i].Z);
                }
                if (normalPos != -1 && !pointsOnly)
                {
                    data.Seek(pos + normalPos, SeekOrigin.Begin);
                    data.Write(normals[i].X);
                    data.Write(normals[i].Y);
                    data.Write(normals[i].Z);
                }
                if (diffusePos != -1)
                {
                    data.Seek(pos + diffusePos, SeekOrigin.Begin);
                    data.Write(colours[i].ToArgb());
                }
                //verts[i].Color = colours[i].ToArgb();
                pos += geomStream.Stride;
            }

            buffer.vBuffers[0].Buffer.Unlock();

            if (!pointsOnly)
            {
                buffer.iBuffers[0].Buffer.SetData(triangles, 0, LockFlags.None);
            }

            // dispose of temp data
        }
Пример #17
0
        /// <summary>  Configures an element. Finds the correct element type
        /// by looking at the element symbol.
        /// 
        /// </summary>
        /// <param name="element">    The element to be configure
        /// </param>
        /// <returns>             The configured atom
        /// </returns>
        public virtual PeriodicTableElement configure(PeriodicTableElement element)
        {
            PeriodicTableElement elementInt = getElement(element.Symbol);

            element.Symbol = elementInt.Symbol;
            element.AtomicNumber = elementInt.AtomicNumber;
            element.Name = elementInt.Name;
            element.ChemicalSerie = elementInt.ChemicalSerie;
            element.Period = elementInt.Period;
            element.Group = elementInt.Group;
            element.Phase = elementInt.Phase;
            element.CASid = elementInt.CASid;
            return element;
        }
Пример #18
0
        public override void CreateGeometryForObjects(Device device, ICollection <IAtom> objs,
                                                      GeomDataBufferStream geomStream, int stream,
                                                      ref BufferedGeometryData buffer, CompleteOutputDescription coDesc)
        {
            if (spriteTexture == null)
            {
                Stream texstm = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenSVisualLib.Resources.Atom.PNG");
                spriteTexture = TextureLoader.FromStream(device, texstm);
            }

            // fillable fields
            int positionPos = -1;
            int sizePos     = -1;
            int diffusePos  = -1;

            // match field locations
            for (int i = 0; i < fields.Length; i++)
            {
                for (int gf = 0; gf < geomStream.Fields.Length; gf++)
                {
                    if (fields[i].Format == geomStream.Fields[gf])
                    {
                        if (fields[i].Usage == "POSITION")
                        {
                            positionPos = geomStream.FieldPositions[gf];
                        }
                        else if (fields[i].Usage == "DIFFUSE")
                        {
                            diffusePos = geomStream.FieldPositions[gf];
                        }
                        else if (fields[i].Usage == "POINTSIZE")
                        {
                            sizePos = geomStream.FieldPositions[gf];
                        }
                        break;
                    }
                }
            }

            // create buffers
            buffer                    = new BufferedGeometryData(device, objs.Count);
            buffer.vBuffers           = new BufferedGeometryData.VertexData[1];
            buffer.vBuffers[0]        = new BufferedGeometryData.VertexData();
            buffer.vBuffers[0].Buffer = new VertexBuffer(typeof(PointSprite), objs.Count, device, Usage.WriteOnly,
                                                         geomStream.Format, Pool.Managed);

            /*new VertexBuffer(device, geomStream.Stride * objs.Count,
             *                                       Usage.None, geomStream.Format, Pool.Managed);*/
            buffer.vBuffers[0].Stride      = geomStream.Stride;
            buffer.vBuffers[0].NumElements = objs.Count;
            buffer.vBuffers[0].Format      = geomStream.Format;

            buffer.iBuffers                  = new BufferedGeometryData.IndexData[1];
            buffer.iBuffers[0]               = new BufferedGeometryData.IndexData();
            buffer.iBuffers[0].Desc          = BufferedGeometryData.IndexData.Description.Sprites;
            buffer.iBuffers[0].NumPrimitives = objs.Count;
            buffer.iBuffers[0].PrimType      = PrimitiveType.PointList;

            buffer.iBuffers[0].Textures = new Texture[] { spriteTexture };

            // lock stream
            GraphicsStream data = buffer.vBuffers[0].Buffer.Lock(0, 0, LockFlags.None);

            AtomShadingDesc aShading = coDesc.AtomShadingDesc;

            long pos = 0;

            foreach (IAtom atom in objs)
            {
                if (positionPos != -1)
                {
                    data.Seek(pos + positionPos, SeekOrigin.Begin);
                    data.Write((float)atom.X3d);
                    data.Write((float)atom.Y3d);
                    data.Write((float)atom.Z3d);
                }
                if (sizePos != -1)
                {
                    data.Seek(pos + sizePos, SeekOrigin.Begin);
                    int period = 1;
                    if (atom.Properties.ContainsKey("Period"))
                    {
                        period = (int)atom.Properties["Period"];
                    }
                    data.Write((float)period * 0.4f);
                }
                if (diffusePos != -1)
                {
                    IMoleculeMaterialLookup   lookup   = aShading.MoleculeMaterials;
                    IMoleculeMaterialTemplate matTemp  = lookup.ResolveBySymbol(atom.Symbol);
                    IMoleculeMaterial         material = null;
                    if (matTemp != null)
                    {
                        material = matTemp.BySymbol;
                    }
                    else
                    {
                        PeriodicTableElement pe = (PeriodicTableElement)atom.Properties["PeriodicTableElement"];
                        if (pe != null)
                        {
                            material = lookup.GetBySeries(pe.ChemicalSerie);
                        }
                    }

                    data.Seek(pos + diffusePos, SeekOrigin.Begin);
                    data.Write(material.BaseColor.ToArgb());
                }
                pos += geomStream.Stride;
            }

            /*Dictionary<int, List<int>> atomSizeGroups = new Dictionary<int, List<int>>();
             * // first split into group counts
             * int aIdx = 0;
             * foreach (IAtom[] atoms in atomSets)
             * {
             *  foreach (IAtom atom in atoms)
             *  {
             *      int period = 1;
             *      if (atom.Properties.ContainsKey("Period"))
             *          period = (int)atom.Properties["Period"];
             *
             *      List<int> groupAtoms = null;
             *      if (!atomSizeGroups.TryGetValue(period, out groupAtoms))
             *          atomSizeGroups.Add(period, groupAtoms = new List<int>());
             *
             *      groupAtoms.Add(aIdx++);
             *  }
             * }
             *
             * int vertsIdx = 0;
             * Dictionary<int, List<int>>.Enumerator group = atomSizeGroups.GetEnumerator();
             * sBuffer.groupLengths = new int[atomSizeGroups.Count];
             * sBuffer.groupSizes = new int[atomSizeGroups.Count];
             * sBuffer.groupStarts = new int[atomSizeGroups.Count];
             * int bIdx = 0;
             * while (group.MoveNext())
             * {
             *  int groupPeriod = group.Current.Key;
             *  List<int> groupMembers = group.Current.Value;
             *  aIdx = 0;
             *  int gIdx = 0;
             *  sBuffer.groupSizes[bIdx] = groupPeriod;
             *  sBuffer.groupStarts[bIdx] = vertsIdx;
             *  sBuffer.groupLengths[bIdx] = groupMembers.Count;
             *  foreach (IAtom[] atoms in atomSets)
             *  {
             *      foreach (IAtom atom in atoms)
             *      {
             *          if (aIdx == groupMembers[gIdx])
             *          {
             *              IMoleculeMaterialLookup lookup = aShading.MoleculeMaterials;
             *              IMoleculeMaterialTemplate matTemp = lookup.ResolveBySymbol(atom.Symbol);
             *              IMoleculeMaterial material = null;
             *              if (matTemp != null)
             *                  material = matTemp.BySymbol;
             *              else
             *              {
             *                  PeriodicTableElement pe = (PeriodicTableElement)atom.Properties["PeriodicTableElement"];
             *                  if (pe != null)
             *                      material = lookup.GetBySeries(pe.ChemicalSerie);
             *              }
             *
             *              atomVerts[vertsIdx].Position = new Vector3((float)atom.X3d, (float)atom.Y3d, (float)atom.Z3d);
             *              atomVerts[vertsIdx].Color = material.BaseColor.ToArgb();
             *              vertsIdx++;
             *              gIdx++;
             *          }
             *          if (gIdx == groupMembers.Count)
             *              break;
             *          aIdx++;
             *      }
             *      if (gIdx == groupMembers.Count)
             *          break;
             *  }
             *  bIdx++;
             * }*/
            buffer.vBuffers[0].Buffer.Unlock();
        }