Ejemplo n.º 1
0
 /// <summary>
 /// Adds a specific amount of molecules to the placement queue.
 /// </summary>
 /// <param name="species">Species to place</param>
 /// <param name="count">Quantity of that species to place</param>
 public void AddMolecules(MoleculeSpecies species, int count)
 {
     for (int i = 0; i < count; i++)
     {
         molecules.Enqueue(species);
     }
 }
Ejemplo n.º 2
0
 private string SpeciesToString(MoleculeSpecies species)
 {
     if (species == null)
     {
         return("?");
     }
     return(species.Name);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a Species to COPASI
        /// </summary>
        /// <returns>COPASI Metabolite</returns>
        /// <param name="species">Species.</param>
        public CMetab AddSpecies(MoleculeSpecies species)
        {
            CCompartment compartment = this.compartment;
            int          status      = CMetab.REACTIONS;

            CMetab metab = model.createMetabolite(species.Name, compartment.getObjectName());

            metab.setStatus(status);

            copasiMetabBySpecies.Add(species, metab);

            return(metab);
        }
Ejemplo n.º 4
0
    public MoleculeSpecies Popup(MoleculeSpecies selected, bool small)
    {
        int i = ArrayUtility.IndexOf <MoleculeSpecies> (moleculeSpecies, selected);

        if (small)
        {
            i = EditorGUILayout.Popup(i, moleculeSpeciesString, GUILayout.MaxWidth(40));
        }
        else
        {
            i = EditorGUILayout.Popup(i, moleculeSpeciesString);
        }
        return(GetSelection(moleculeSpecies, i));
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Place all the molecules in the placement queue.
        /// </summary>
        public void Place()
        {
            while (molecules.Count > 0)
            {
                // Get next species to add
                MoleculeSpecies s = molecules.Dequeue();

                // Get random location
                // s.Size is subtracted so never half of the molecule reaches outside the defined radius
                Vector3 l = Location + Random.insideUnitSphere * (Utility.Utils.ScaleFromNm(Radius) - s.Size);

                // create molecule
                Molecule m = s.CreateMolecule(l);

                // Add DelayedDrag component that resets the drag after a
                // specified amount of time
                DelayedDrag delayedDrag = m.gameObject.AddComponent <DelayedDrag>();
                delayedDrag.delay       = DragDelay;
                delayedDrag.initialDrag = InitialDrag;
                delayedDrag.drag        = Molecule.Drag;
            }
        }
Ejemplo n.º 6
0
    public MoleculeSpeciesPopup(CUE cue, bool nullPossible)
    {
        MoleculeSpecies[] cueSpecies = cue.Species;

        moleculeSpecies = new MoleculeSpecies[cueSpecies.Length + (nullPossible ? 1 : 0)];

        moleculeSpeciesString = new string[moleculeSpecies.Length];

        int i = 0;

        if (nullPossible)
        {
            moleculeSpecies[i]       = null;
            moleculeSpeciesString[i] = "none";
            i++;
        }

        foreach (var item in cueSpecies)
        {
            moleculeSpecies[i]       = item;
            moleculeSpeciesString[i] = item.Name;
            i++;
        }
    }
Ejemplo n.º 7
0
        public MoleculeSpecies Create()
        {
            // find a name if not specified
            findName();

            // create main object of the species
            GameObject mol = new GameObject(name);

            mol.transform.position = Vector3.zero;

            float colliderRadius = 0;

            //
            // Find center of all gameObjects
            //

            Vector3 center = Vector3.zero;

            foreach (var obj in gameObjects)
            {
                // set main object as parent
                obj.transform.parent = mol.transform;

                center += obj.transform.position;

                // remove collider for performance boost
                if (obj.collider != null)
                {
                    obj.collider.enabled = false;
                    CellUnity.Utility.ScriptManager.RemoveComponent(obj.collider);
                }
            }

            center = center / gameObjects.Length;

            //
            // locate object to (0,0,0) by setting center to (0,0,0)
            // and calculate the colliderRadius by making sure every atom is inside this radius
            //
            foreach (var obj in gameObjects)
            {
                obj.transform.position -= center;

                colliderRadius = Math.Max(colliderRadius, Math.Abs(obj.renderer.bounds.min.x));
                colliderRadius = Math.Max(colliderRadius, Math.Abs(obj.renderer.bounds.min.y));
                colliderRadius = Math.Max(colliderRadius, Math.Abs(obj.renderer.bounds.min.z));
                colliderRadius = Math.Max(colliderRadius, Math.Abs(obj.renderer.bounds.max.x));
                colliderRadius = Math.Max(colliderRadius, Math.Abs(obj.renderer.bounds.max.y));
                colliderRadius = Math.Max(colliderRadius, Math.Abs(obj.renderer.bounds.max.z));
            }

            // Create a new species and add it to the CUE
            CUE             cue     = CUE.GetInstance();
            MoleculeSpecies species = cue.CreateMoleculeSpecies();

            species.Name = name;
            cue.AddSpecies(species);

            // Add the molecule script to the main object
            CellUnity.Molecule script = mol.AddComponent <CellUnity.Molecule>();
            script.Species = species;
            species.Mass   = mass;
            species.Size   = colliderRadius * 2;

            // Add a sphere collider to the main object
            SphereCollider sphereCollider = mol.AddComponent <SphereCollider> ();
            Rigidbody      rigidbody      = mol.AddComponent <Rigidbody> ();

            rigidbody.useGravity  = false;
            rigidbody.mass        = mass;
            sphereCollider.radius = colliderRadius;

            // Add a diffusion script to the main object
            View.Diffusion diffusion = mol.AddComponent <View.Diffusion> ();
            diffusion.Intensity = Diffusion;

            // create the prefab used as template for the species
            string assetPath = "Assets/Molecules/" + name + ".prefab";

            UnityEngine.Object prefab = PrefabUtility.CreateEmptyPrefab(assetPath);
            PrefabUtility.ReplacePrefab(mol, prefab);
            AssetDatabase.Refresh();

            species.PrefabPath = assetPath;

            EditorUtility.SetDirty(cue);

            // Delete game objects
            foreach (var obj in gameObjects)
            {
                GameObject.DestroyImmediate(obj);
            }
            GameObject.DestroyImmediate(mol);

            return(species);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Remove a species.
 /// </summary>
 /// <param name="species">Species to remove.</param>
 public void RemoveSpecies(MoleculeSpecies species)
 {
     model.removeMetabolite(GetMetab(species));
     copasiMetabBySpecies.Remove(species);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Gets the COPASI Metabolite by Species
 /// </summary>
 /// <returns>The metab.</returns>
 /// <param name="species">Species.</param>
 public CMetab GetMetab(MoleculeSpecies species)
 {
     return(copasiMetabBySpecies [species]);
 }