Skip to content

Commit

Permalink
prebuild array
Browse files Browse the repository at this point in the history
  • Loading branch information
JensKrumsieck committed Sep 13, 2022
1 parent f35995d commit 337099b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions ChemSharp.Molecules/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class Element
/// </summary>
private static readonly Element Dummy = new() {Symbol = "DA", Name = "Dummy Atom"};

private readonly string[] _metalloids = {"B", "Si", "Ge", "As", "Sb", "Bi", "Se", "Te", "Po"};
private readonly string[] _nonMetals = {"H", "C", "N", "O", "P", "S", "Se"};

[JsonIgnore] private string? _color;

static Element()
Expand Down Expand Up @@ -58,6 +61,7 @@ public Element() { }
/// <param name="symbol"></param>
public Element(string symbol)
{
if (symbol == "D") symbol = "H"; //filter deuterium
var shadow = ElementDataProvider.ElementData.FirstOrDefault(s => s.Symbol == symbol) ?? Dummy;

Name = shadow.Name;
Expand All @@ -84,16 +88,13 @@ public Element(string symbol)
public string Color => _color ??= ElementDataProvider.ColorData[Symbol];

[JsonIgnore] public bool IsMetal => !IsMetalloid && !IsNonMetal;
[JsonIgnore] public int Charge { get; set; } = 0;
[JsonIgnore] public int Charge { get; set; }

[JsonIgnore] public int Electrons => AtomicNumber - Charge;

[JsonIgnore]
public bool IsMetalloid => new[] {"B", "Si", "Ge", "As", "Sb", "Bi", "Se", "Te", "Po"}.Contains(Symbol);

[JsonIgnore]
public bool IsNonMetal => new[] {"H", "C", "N", "O", "P", "S", "Se"}.Contains(Symbol) || Group is 18 or 17;
[JsonIgnore] public bool IsMetalloid => _metalloids.Contains(Symbol);

[JsonIgnore] public bool IsNonMetal => _nonMetals.Contains(Symbol) || Group is 18 or 17;
public string Name { get; set; }
public string Symbol { get; set; }
public string Appearance { get; set; }
Expand Down

0 comments on commit 337099b

Please sign in to comment.