Exemplo n.º 1
0
        public Atom(string symbol)
        {
            Symbol = symbol;
            switch (symbol)
            {
            case "He":
                Number = 2;
                Mass   = 4.003m;
                Type   = AtomType.GasesNobre;
                break;

            case "O":
                Number = 8;
                Mass   = 15.999m;
                Type   = AtomType.NaoMetal;
                break;

            case "H":
            default:
                Number = 1;
                Mass   = 1.008m;
                Type   = AtomType.NaoMetal;
                break;
            }
        }
Exemplo n.º 2
0
        public void AddAtomCreation(DreamObject atom, ServerIconAppearance appearance)
        {
            AtomType atomType = AtomType.Atom;

            if (atom.IsSubtypeOf(DreamPath.Area))
            {
                atomType = AtomType.Area;
            }
            else if (atom.IsSubtypeOf(DreamPath.Turf))
            {
                atomType = AtomType.Turf;
            }
            else if (atom.IsSubtypeOf(DreamPath.Mob))
            {
                atomType = AtomType.Movable;
            }
            else if (atom.IsSubtypeOf(DreamPath.Obj))
            {
                atomType = AtomType.Movable;
            }

            lock (_dreamStateManagerLock) {
                _currentDeltaState.AddAtomCreation(DreamMetaObjectAtom.AtomIDs[atom], atomType, appearance.GetID());
            }
        }
Exemplo n.º 3
0
 public Atom(string element, AtomType type)
 {
     if (element == "*")
     {
         m_Element = ELEMENTS.WILD_CARD;
     }
     else if (element == "X")
     {
         m_Element = ELEMENTS.Halogen;
     }
     else
     {
         m_Element = (ELEMENTS)Enum.Parse(typeof(ELEMENTS), element);
     }
     m_ExplicitHydrogens = 0;
     m_Isotope           = 0;
     m_Charge            = 0;
     m_Chiral            = Chirality.UNSPECIFIED;
     AtomType            = type;
     m_Chiral            = Chirality.UNSPECIFIED;
     if (this.Element != ELEMENTS.Halogen)
     {
         this.SetColor(SustainableChemistryWeb.ChemInfo.Element.ElementColor(m_Element));
     }
     else
     {
         Color = System.Drawing.Color.FromName("olivedrab");
     }
     _x = (int)(random.NextDouble() * 100);
     _y = (int)(random.NextDouble() * 100);
     //m_WeiningerInvariant = new WeiningerInvariant(this);
 }
Exemplo n.º 4
0
 public static Molecule GetRandom(this Molecule[] soundsGroup, AtomType leadAtom, PositionType position)
 {
     return(soundsGroup
            .Where(t => t.LeadType == leadAtom)
            .ToWeightedDictionary(item => item.GetWeight(position))
            .GetRandomItem());
 }
Exemplo n.º 5
0
 public AtomData(Vector3 position, float electicValue, Color color, float size, AtomType atomType)
 {
     this.position     = position;
     this.electicValue = electicValue;
     this.color        = color;
     this.size         = size;
     this.atomType     = atomType;
 }
Exemplo n.º 6
0
        public static string GetInjectableAtom(AtomType atom)
        {
            if (!typeNames.ContainsKey(atom))
            {
                throw new ArgumentOutOfRangeException(nameof(atom));
            }

            return(GetInjectableAtom(typeNames[atom], string.Empty));
        }
Exemplo n.º 7
0
 public Molecule(string value, AtomType startsWith, AtomType endsWith, int leadWeight, int midWeight, int trailWeight)
 {
     Value       = value;
     LeadType    = startsWith;
     TrailType   = endsWith;
     LeadWeight  = leadWeight;
     MidWeight   = midWeight;
     TrailWeight = trailWeight;
 }
            public override void Render(HtmlNode parentElement, AtomType atomType)
            {
                var element = parentElement.OwnerDocument.CreateElement("a");

                element.Attributes.Add(parentElement.OwnerDocument.CreateAttribute("href", "~/"));
                element.AppendChild(parentElement.OwnerDocument.CreateTextNode(atomType.Text));

                parentElement.AppendChild(element);
            }
Exemplo n.º 9
0
        public void TestConfigure_IAtom_IAtomType()
        {
            IAtom     atom     = new Atom(ChemicalElement.C);
            IAtomType atomType = new AtomType(ChemicalElement.C)
            {
                IsHydrogenBondAcceptor = true
            };

            AtomTypeManipulator.Configure(atom, atomType);
            Assert.AreEqual(atomType.IsHydrogenBondAcceptor, atom.IsHydrogenBondAcceptor);
        }
Exemplo n.º 10
0
        public void TestConfigureUnSetProperties()
        {
            IAtom     atom     = new Atom(ChemicalElement.C);
            IAtomType atomType = new AtomType(ChemicalElement.C)
            {
                ExactMass = 12.0
            };

            AtomTypeManipulator.ConfigureUnsetProperties(atom, atomType);
            Assert.AreEqual(12.0, atom.ExactMass.Value, 0.1);
        }
Exemplo n.º 11
0
 public MpegAtom(MpegAtom parentAtom,
                 ArrayList childAtoms,
                 AtomType atomType,
                 long atomOffset,
                 uint atomSize)
 {
     Parent   = parentAtom;
     Children = childAtoms;
     Type     = atomType;
     Offset   = atomOffset;
     Size     = atomSize;
 }
Exemplo n.º 12
0
        public void UnknownAtomTypeDoesNotModifyProperties()
        {
            IAtom     atom     = new Atom(ChemicalElement.C);
            IAtomType atomType = new AtomType(ChemicalElement.R)
            {
                AtomTypeName = "X"
            };

            AtomTypeManipulator.Configure(atom, atomType);
            Assert.AreEqual("C", atom.Symbol);
            Assert.AreEqual(6, atom.AtomicNumber);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Ctr.
        /// </summary>
        /// <param name="atomType">Atom type.</param>
        /// <param name="name">The name to be used for parsing. See <see cref="Name"/>.</param>
        /// <param name="expressionGenerator">The functor responsible for generating expressions.</param>
        public AtomMetadata(AtomType atomType, string name, ExpressionGeneratorCallback expressionGenerator)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            ValidateExpressionGenerator(expressionGenerator);

            AtomType            = atomType;
            Name                = name;
            ExpressionGenerator = expressionGenerator;
        }
        public LexicalMachineState GetNext(AtomType command)
        {
            LexicalMachineState    nextState  = this.CurrentState;
            LexicalStateTransition transition = new LexicalStateTransition(CurrentState, command);

            if (!transitions.TryGetValue(transition, out nextState))
            {
                throw new Exception("Lexical: Invalid transition: " + CurrentState + " -> " + command);
            }

            Console.WriteLine("Lexical :" + this.CurrentState + " -> " + nextState + " : " + command.ToString());

            return(nextState);
        }
Exemplo n.º 15
0
        public static string GetInjectableAtom(AtomType atom, AtomTarget target)
        {
            if (!targetNames.ContainsKey(target))
            {
                throw new ArgumentOutOfRangeException(nameof(target));
            }

            if (!typeNames.ContainsKey(atom))
            {
                throw new ArgumentOutOfRangeException(nameof(atom));
            }

            return(GetInjectableAtom(typeNames[atom], targetNames[target]));
        }
Exemplo n.º 16
0
        public void AromaticityIsNotOverwritten()
        {
            IAtom atom = new Atom(ChemicalElement.C)
            {
                IsAromatic = true
            };
            IAtomType atomType = new AtomType(ChemicalElement.R)
            {
                IsAromatic   = false,
                AtomTypeName = "C.sp3"
            };

            AtomTypeManipulator.Configure(atom, atomType);
            Assert.IsTrue(atom.IsAromatic);
        }
Exemplo n.º 17
0
        public void AromaticitySetIfForType()
        {
            IAtom atom = new Atom(ChemicalElement.C)
            {
                IsAromatic = false
            };
            IAtomType atomType = new AtomType(ChemicalElement.R)
            {
                IsAromatic   = true,
                AtomTypeName = "C.am"
            };

            AtomTypeManipulator.Configure(atom, atomType);
            Assert.IsTrue(atom.IsAromatic);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Ctr.
        /// </summary>
        /// <param name="atomType">Atom type.</param>
        /// <param name="name">The name to be used for parsing. See <see cref="Name"/>.</param>
        /// <param name="functor">Functor responsible for extracting values from source. See <see cref="Functor"/>.</param>
        public AtomMetadata(AtomType atomType, string name, object functor)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            ValidateFunctor(functor);

            AtomType     = atomType;
            Name         = name;
            Functor      = functor;
            MethodInfo   = GetMethodInfo(functor);
            MethodTarget = GetMethodTarget(functor);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Read atom header, add known flags.
        /// </summary>
        private AtomEvent ReadAtom()
        {
            // get size
            uint sizeShort;

            if (!TryReadUint(out sizeShort))
            {
                return(null); // end of stream
            }
            long size     = sizeShort;
            long dataSize = size - 8; // header length
            // get type
            string name = ReadAsciiStr(4);

            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }
            // check for wide atom
            if (sizeShort == 0)
            {
                // Should not be hard to support it but dont need it yet.
                throw new InvalidOperationException("Open atom not supported.");
            }
            if (sizeShort == 1)
            {
                // wide atom (should be "mdat")
                ulong sizeLong;
                if (!TryReadUlong(out sizeLong))
                {
                    return(null);          // end of stream
                }
                size     = (long)sizeLong; // better to have size ulong, bot other methods expect long
                dataSize = size - 16;
            }

            // get known flags
            AtomTypeFlags flags = AtomTypeFlags.None;
            AtomType      type  = Types.GetValueOrDefault(name);

            if (type != null)
            {
                flags = type.Flags;
            }

            return(new AtomEvent(name, flags, size, dataSize));
        }
Exemplo n.º 20
0
        public static AtomType Consume(Parser parser)
        {
            AtomType atomType = null;

            switch (parser.LookAhead().Type)
            {
            case TokenInfo.TokenType.BOOL:
                parser.Eat(TokenInfo.TokenType.BOOL);
                atomType = new BoolType();
                break;

            case TokenInfo.TokenType.CHAR:
                parser.Eat(TokenInfo.TokenType.CHAR);
                atomType = new CharType();
                break;

            case TokenInfo.TokenType.DOUBLE:
                parser.Eat(TokenInfo.TokenType.DOUBLE);
                atomType = new DoubleType();
                break;

            case TokenInfo.TokenType.INT:
                parser.Eat(TokenInfo.TokenType.INT);
                atomType = new IntType();
                break;

            case TokenInfo.TokenType.STRING:
                parser.Eat(TokenInfo.TokenType.STRING);
                atomType = new StringType();
                break;

            case TokenInfo.TokenType.VOID:
                parser.Eat(TokenInfo.TokenType.VOID);
                atomType = new VoidType();
                break;

            default:
                break;
            }

            if (atomType == null)
            {
                throw new ParserError(new FailedConsumer(), parser.Cursor);
            }

            return(atomType);
        }
Exemplo n.º 21
0
        private List <AtomBehavior> GetStartingPointsByType(GameObject[] molecule, AtomType symbol)
        {
            List <AtomBehavior> atomsFound = new List <AtomBehavior>();

            foreach (GameObject atom in molecule)
            {
                AtomBehavior atomScript = atom.GetComponent <AtomBehavior>();
                if (atomScript.Symbol == symbol)
                {
                    atomsFound.Add(atomScript);
                }
            }

            Debug.Log("GetStartingPointsByType size : " + atomsFound.Count);

            return(atomsFound);
        }
Exemplo n.º 22
0
        private bool SameMoleculeAs(string index)
        {
            Debug.Log("SameMolecule : " + moleculeDictionary[index]);
            // We retrieve a copy of the SMILES from the dictionary
            string smiles = string.Copy(moleculeDictionary[index]);

            // We retrieve the atoms in the molecule GameObject
            GameObject[] atomsInMolecule = GameObject.FindGameObjectsWithTag("Atom");
            Debug.Log("Atoms retrieved from molecule object : " + atomsInMolecule.Length);

            // We retrieve the starting points of the recursion...
            while (smiles[0] == '(')
            {
                smiles = smiles.Substring(1);
            }
            AtomType smilesStartingSymbol = GetSmilesStartingSymbol(ref smiles);

            Debug.Log("SameMolecule starting symbol : " + smilesStartingSymbol);
            List <AtomBehavior> startingPoints = GetStartingPointsByType(atomsInMolecule, smilesStartingSymbol);
            // ...and start it from there
            bool match = false;

            foreach (AtomBehavior atom in startingPoints)
            {
                ResetAllMarks(atomsInMolecule);
                if (CompareBranchFrom(ref smiles, atom))
                {
                    match = true;
                    break;
                }
            }

            // we clean all our atoms
            ResetAllMarks(atomsInMolecule);

            if (match)
            {
                Debug.Log("This molecule is " + index);
                return(true);
            }
            else
            {
                Debug.Log("This molecule is not " + index);
                return(false);
            }
        }
Exemplo n.º 23
0
        private void DrawNextAtom(AtomType type)
        {
            Wordbook saccadeBook = new Wordbook(calculatedSaccades);
            AtomBook atomBook    = new AtomBook(saccadeBook);

            List <Atom> mediumLines = atomBook.atoms[type];

            if (current < mediumLines.Count)
            {
                RemoveLabels();
                RemoveFixationCircles();
                RemoveSaccades();
                DrawSaccades(mediumLines[current++].saccades);
            }
            else
            {
                current = 0;
            }
        }
Exemplo n.º 24
0
            // Lookup returns the atom whose name is s. It returns zero if there is no
            // such atom. The lookup is case sensitive.
            public static AtomType Lookup(byte[] s)
            {
                if (s.Length == 0 || s.Length > maxAtomLen)
                {
                    return(0);
                }
                var      h = fnv(hash0, s);
                AtomType a = table[h & (uint)(table.Length - 1)];

                if ((a & 0xff) == s.Length && match(a.ToStringUnsafe(), s))
                {
                    return(a);
                }
                a = table[(h >> 16) & (uint)(table.Length - 1)];
                if ((a & 0xff) == s.Length && match(a.ToStringUnsafe(), s))
                {
                    return(a);
                }
                return(0);
            }
Exemplo n.º 25
0
 public Atom(string element, AtomType type, int isotope, Chirality chirality, int hCount, int charge, int atomClass)
 {
     //degree = 0;
     if (element == "*")
     {
         m_Element = ELEMENTS.WILD_CARD;
     }
     else
     {
         m_Element = (ELEMENTS)Enum.Parse(typeof(ELEMENTS), element);
     }
     m_ExplicitHydrogens = hCount;
     m_Isotope           = isotope;
     m_Charge            = charge;
     m_Chiral            = chirality;
     AtomType            = type;
     this.SetColor(SustainableChemistryWeb.ChemInfo.Element.ElementColor(m_Element));
     _x = (int)(random.NextDouble() * 100);
     _y = (int)(random.NextDouble() * 100);
     //m_WeiningerInvariant = new WeiningerInvariant(this);
 }
Exemplo n.º 26
0
 public Atom(string element, AtomType type, Chirality chirality)
 {
     //degree = 0;
     if (element == "*")
     {
         m_Element = ELEMENTS.WILD_CARD;
     }
     else
     {
         m_Element = (ELEMENTS)Enum.Parse(typeof(ELEMENTS), element);
     }
     m_ExplicitHydrogens = 0;
     m_Isotope           = 0;
     m_Charge            = 0;
     m_Chiral            = Chirality.UNSPECIFIED;
     AtomType            = AtomType.NONE;
     m_Chiral            = chirality;
     this.SetColor(SustainableChemistryWeb.ChemInfo.Element.ElementColor(m_Element));
     _x = (int)(random.NextDouble() * 100);
     _y = (int)(random.NextDouble() * 100);
     //m_WeiningerInvariant = new WeiningerInvariant(this);
 }
Exemplo n.º 27
0
 public Atom(AtomType t)
 {
     t_ = t;
 }
Exemplo n.º 28
0
        /// <summary>
        /// Ctr.
        /// </summary>
        /// <param name="atomType">Atom type.</param>
        /// <param name="name">The name to be used for parsing. See <see cref="Name"/>.</param>
        /// <param name="expressionGenerator">The functor responsible for generating expressions.</param>
        public AtomMetadata(AtomType atomType, string name, ExpressionGeneratorCallback expressionGenerator)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            ValidateExpressionGenerator(expressionGenerator);

            AtomType = atomType;
            Name = name;
            ExpressionGenerator = expressionGenerator;
        }
 public LexicalStateTransition(LexicalMachineState currentState, AtomType command)
 {
     this.CurrentState = currentState;
     this.Command      = command;
 }
Exemplo n.º 30
0
        /// <summary>
        /// Ctr.
        /// </summary>
        /// <param name="atomType">Atom type.</param>
        /// <param name="name">The name to be used for parsing. See <see cref="Name"/>.</param>
        /// <param name="functor">Functor responsible for extracting values from source. See <see cref="Functor"/>.</param>
        public AtomMetadata(AtomType atomType, string name, object functor)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            ValidateFunctor(functor);

            AtomType = atomType;
            Name = name;
            Functor = functor;
            MethodInfo = GetMethodInfo(functor);
            MethodTarget = GetMethodTarget(functor);
        }
Exemplo n.º 31
0
        public void TestButadiene()
        {
            var mol    = new AtomContainer();
            var carbon = new AtomType(ChemicalElement.C);

            var a0 = new Atom("C")
            {
                Hybridization         = Hybridization.SP2,
                ImplicitHydrogenCount = 2
            };

            AtomTypeManipulator.ConfigureUnsetProperties(a0, carbon);
            var a1 = new Atom("C")
            {
                Hybridization         = Hybridization.SP2,
                ImplicitHydrogenCount = 1
            };

            AtomTypeManipulator.ConfigureUnsetProperties(a1, carbon);
            var a2 = new Atom("C")
            {
                Hybridization         = Hybridization.SP2,
                ImplicitHydrogenCount = 1
            };

            AtomTypeManipulator.ConfigureUnsetProperties(a2, carbon);
            var a3 = new Atom("C")
            {
                Hybridization         = Hybridization.SP2,
                ImplicitHydrogenCount = 2
            };

            AtomTypeManipulator.ConfigureUnsetProperties(a3, carbon);

            mol.Atoms.Add(a0);
            mol.Atoms.Add(a1);
            mol.Atoms.Add(a2);
            mol.Atoms.Add(a3);

            var b0 = new Bond(a0, a1)
            {
                IsSingleOrDouble = true
            };

            mol.Bonds.Add(b0);
            var b1 = new Bond(a1, a2)
            {
                IsSingleOrDouble = true
            };

            mol.Bonds.Add(b1);
            IBond b2 = new Bond(a2, a3)
            {
                IsSingleOrDouble = true
            };

            mol.Bonds.Add(b2);

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol);

            atasc.DecideBondOrder(mol, true);

            Assert.AreEqual(BondOrder.Double, mol.Bonds[0].Order);
            Assert.AreEqual(BondOrder.Single, mol.Bonds[1].Order);
            Assert.AreEqual(BondOrder.Double, mol.Bonds[2].Order);
        }
Exemplo n.º 32
0
        public void TestASimpleCarbonRing()
        {
            // First we create a simple carbon ring to play with...
            var mol    = new AtomContainer();
            var carbon = new AtomType(ChemicalElement.C);

            var a0 = new Atom("C")
            {
                Hybridization         = Hybridization.SP2,
                ImplicitHydrogenCount = 1
            };

            AtomTypeManipulator.ConfigureUnsetProperties(a0, carbon);
            var a1 = new Atom("C")
            {
                Hybridization         = Hybridization.SP2,
                ImplicitHydrogenCount = 1
            };

            AtomTypeManipulator.ConfigureUnsetProperties(a1, carbon);
            var a2 = new Atom("C")
            {
                Hybridization         = Hybridization.SP2,
                ImplicitHydrogenCount = 1
            };

            AtomTypeManipulator.ConfigureUnsetProperties(a2, carbon);
            var a3 = new Atom("C")
            {
                Hybridization         = Hybridization.SP2,
                ImplicitHydrogenCount = 1
            };

            AtomTypeManipulator.ConfigureUnsetProperties(a3, carbon);
            var a4 = new Atom("C")
            {
                Hybridization         = Hybridization.SP2,
                ImplicitHydrogenCount = 1
            };

            AtomTypeManipulator.ConfigureUnsetProperties(a4, carbon);
            var a5 = new Atom("C")
            {
                Hybridization         = Hybridization.SP2,
                ImplicitHydrogenCount = 1
            };

            AtomTypeManipulator.ConfigureUnsetProperties(a5, carbon);

            mol.Atoms.Add(a0);
            mol.Atoms.Add(a1);
            mol.Atoms.Add(a2);
            mol.Atoms.Add(a3);
            mol.Atoms.Add(a4);
            mol.Atoms.Add(a5);

            var b0 = new Bond(a0, a1)
            {
                IsSingleOrDouble = true
            };

            mol.Bonds.Add(b0);
            var b1 = new Bond(a1, a2)
            {
                IsSingleOrDouble = true
            };

            mol.Bonds.Add(b1);
            var b2 = new Bond(a2, a3)
            {
                IsSingleOrDouble = true
            };

            mol.Bonds.Add(b2);
            var b3 = new Bond(a3, a4)
            {
                IsSingleOrDouble = true
            };

            mol.Bonds.Add(b3);
            var b4 = new Bond(a4, a5)
            {
                IsSingleOrDouble = true
            };

            mol.Bonds.Add(b4);
            var b5 = new Bond(a5, a0)
            {
                IsSingleOrDouble = true
            };

            mol.Bonds.Add(b5);

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol);

            // ...then we send it to the method we want to test...
            atasc.DecideBondOrder(mol, false);

            Assert.AreEqual(BondOrder.Double, b0.Order);
            Assert.AreEqual(BondOrder.Single, b1.Order);
            Assert.AreEqual(BondOrder.Double, b2.Order);
            Assert.AreEqual(BondOrder.Single, b3.Order);
            Assert.AreEqual(BondOrder.Double, b4.Order);
            Assert.AreEqual(BondOrder.Single, b5.Order);

            Assert.IsTrue(satcheck.IsSaturated(a0, mol));
        }
 public override bool CanRender(AtomType atomType) => atomType.Name == "link";