public override void LoadModuleSettings(HashTableSettings settings) { // Load random template Random ran = new Random(); // series foreach (string serie in serieNames) { int r = (int)(ran.NextDouble() * 255f); int g = (int)(ran.NextDouble() * 255f); int b = (int)(ran.NextDouble() * 255f); Color baseColor = Color.FromArgb(r, g, b); series[serie] = new AtomMaterial(baseColor); } // elements ElementPTFactory ptElements = ElementPTFactory.Instance; foreach (PeriodicTableElement element in ptElements) { int r = (int)(ran.NextDouble() * 255f); int g = (int)(ran.NextDouble() * 255f); int b = (int)(ran.NextDouble() * 255f); Color baseColor = Color.FromArgb(r, g, b); IMoleculeMaterial serieMat = null; series.TryGetValue(element.ChemicalSerie, out serieMat); elements[element.Symbol] = new MoleculeMaterialTemplate(new AtomMaterial(baseColor), serieMat); } }
private void LoadingProcess(object param) { LoadingResourcesDlg dlg = (LoadingResourcesDlg)param; try { // load symbols for elements ElementPTFactory elements = ElementPTFactory.Instance; System.Drawing.Font font = new System.Drawing.Font("Tahoma", 20); float onePer = 100.0f / elements.Size; float prog = 0; foreach (PeriodicTableElement element in elements) { Texture tex = TextTexture.DrawTextToTexture(element.Symbol, font, device, 64, 64).Texture; symbolTextures[element.Symbol] = tex; prog += onePer; dlg.Progress = (int)prog; } dlg.TryClose(); } catch { } }
public override void LoadModuleSettings(NuGenSVisualLib.Settings.HashTableSettings settings) { // ignore series // elements ElementPTFactory ptElements = ElementPTFactory.Instance; foreach (PeriodicTableElement element in ptElements) { int r = 0; int g = 0; int b = 0; // calc group (103/35) int group = (int)((float)element.AtomicNumber / 35f); // calc shade int index = element.AtomicNumber - (group * 35); int clr1, clr2, clr3; int amt = (int)((float)index * 5.55f); if (index < 18) { // light clr1 = 255; clr2 = clr3 = 100 - amt; } else { // dark clr1 = 255 - amt; clr2 = clr3 = 0; } if (group == 0) { r = clr1; g = clr2; b = clr3; } else if (group == 1) { r = clr2; g = clr1; b = clr3; } else { r = clr2; g = clr3; b = clr1; } Color baseColor = Color.FromArgb(r, g, b); elements[element.Symbol] = new MoleculeMaterialTemplate(new AtomMaterial(baseColor), null); } }
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); } }
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 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); } }
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; }
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); }