コード例 #1
0
        public bool ParseLine(MoleculeDefinition molecule, string line)
        {
            var regexCoordLine = "[ ]+(\\d+)[ ]+(\\d+)[ ]+(\\d+)[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)";

            bool isLookingForActualInput = index > InitialLines.Length - 1;

            if (isLookingForActualInput)
            {
                var match = Regex.Match(line, regexCoordLine);
                if (match.Success)
                {
                    var atomicNumber = int.Parse(match.Groups [2].Value.Trim());

                    var x = float.Parse(match.Groups [4].Value.Trim());
                    var y = float.Parse(match.Groups [5].Value.Trim());
                    var z = float.Parse(match.Groups [6].Value.Trim());
                    molecule.Atoms.Add(new AtomDefinition()
                    {
                        Position = new Vector3(x, y, z),
                        Element  = AssetDatabase.FindAssets("t:Element")
                                   .Select(e => AssetDatabase.LoadAssetAtPath <Element>(AssetDatabase.GUIDToAssetPath(e)))
                                   .Where(e => e != null && e.AtomicNumber == atomicNumber).FirstOrDefault()
                    });
                    return(true);
                }
                else
                {
                    index = 0;
                    return(false);
                }
            }
            else
            {
                string desiredLine = InitialLines [index];
                if (line.Equals(desiredLine))
                {
                    index++;
                    if (index == InitialLines.Length)
                    {
                        molecule.Atoms.Clear();
                    }
                    return(true);
                }
                index = 0;
                return(false);
            }
        }
コード例 #2
0
    public override void OnImportAsset(AssetImportContext ctx)
    {
        var lines = File.ReadAllLines(ctx.assetPath);

        int modeCoordinates    = 0;
        int maxModeCoordinates = 0;

        var coordParser = new CoordinateParser();
        var modeParser  = new ModeParser();

        MoleculeDefinition molecule = new MoleculeDefinition();

        foreach (var line in lines)
        {
            coordParser.ParseLine(molecule, line);

            modeParser.ParseLine(molecule, line);

            if (molecule.VibrationalModes.Count > 0)
            {
                var regexBond = " ! R\\d+ +R\\((\\d+),(\\d+)\\)";
                var match     = Regex.Match(line, regexBond);
                if (match.Success)
                {
                    var atom1 = int.Parse(match.Groups [1].Value) - 1;
                    var atom2 = int.Parse(match.Groups [2].Value) - 1;
                    molecule.Bonds.Add(new BondDefinition()
                    {
                        AtomIndex1 = atom1, AtomIndex2 = atom2
                    });
                }
            }
        }

        ctx.AddObjectToAsset("Data", molecule);
        ctx.SetMainObject(molecule);
    }
コード例 #3
0
    /// Creates a molecule from a definition. NOTE: Does not actually create it in game, for this then call CreateMoleculeGraphic
    public Molecule CreateMolecule(MoleculeDefinition definition)
    {
        var molecule = new Molecule(definition);

        foreach (var atomDefinition in definition.Atoms)
        {
            var atom = new Atom(molecule, atomDefinition);
            molecule.Atoms.Add(atom);
        }

        foreach (var modeDefinition in definition.VibrationalModes)
        {
            var mode = new VibrationalMode(molecule, modeDefinition);
            molecule.VibrationalModes.Add(mode);
        }

        foreach (var bondDefinition in definition.Bonds)
        {
            var bond = new Bond(molecule, bondDefinition);
            molecule.Bonds.Add(bond);
        }

        return(molecule);
    }
コード例 #4
0
        public bool ParseLine(MoleculeDefinition molecule, string line)
        {
            string freqLineRegex   = " Frequencies --[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)";
            string pointsLineRegex = "[ ]+ \\d+[ ]+ \\d+[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)";

            int blockSize = 7 + molecule.Atoms.Count;
            //var regexCoordLine = "[ ]+(\\d+)[ ]+(\\d+)[ ]+(\\d+)[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)[ ]+(-?\\d+.\\d+)";

            bool isLookingForActualInput = index > InitialLines.Length - 1;

            if (isLookingForActualInput)
            {
                if (line.Count() == 0)
                {
                    index = 0;
                    return(false);
                }
                else
                {
                    if (freqIndex == 2)
                    {
                        var match = Regex.Match(line, freqLineRegex);
                        CurrentModes.Clear();
                        for (var i = 1; i <= 3; i++)
                        {
                            var freq = float.Parse(match.Groups [i].Value);
                            var mode = new VibrationalModeDefinition();
                            mode.Wavenumber = freq;
                            CurrentModes.Add(mode);
                        }
                    }
                    if (freqIndex >= 7)
                    {
                        var match = Regex.Match(line, pointsLineRegex);
                        for (var i = 0; i <= 2; i++)
                        {
                            Debug.Log(line);
                            Debug.Log(match.Success);
                            var x = float.Parse(match.Groups [1 + i * 3].Value);
                            var y = float.Parse(match.Groups [2 + i * 3].Value);
                            var z = float.Parse(match.Groups [3 + i * 3].Value);
                            CurrentModes [i].Displacements.Add(new Vector3(x, y, z));
                        }
                    }
                    freqIndex++;
                    if (freqIndex == blockSize)
                    {
                        freqIndex = 0;
                        molecule.VibrationalModes.AddRange(CurrentModes);
                        CurrentModes.Clear();
                    }
                }
                return(true);
            }
            else
            {
                string desiredLine = InitialLines [index];
                if (line.Equals(desiredLine))
                {
                    index++;
                    //if (index == InitialLines.Length) {
                    //	molecule.Atoms.Clear ();
                    //}
                    return(true);
                }
                index = 0;
                return(false);
            }
        }
コード例 #5
0
 public Molecule(MoleculeDefinition definition)
 {
 }