Beispiel #1
0
 public void minusParticle(MovingChargedParticle mcp)
 {
     chargedParticles.Remove(mcp);
     movingChargedParticles.Remove(mcp);
     //Destroy(mcp);
     //createList();
 }
    private void ApplyMagneticForce(MovingChargedParticle mcp)
    {
        Vector3 newForce = Vector3.zero;

        foreach (ChargedParticle cp in chargedParticles)
        {
            if (mcp == cp)
            {
                continue;
            }

            float distance = Vector3.Distance(mcp.transform.position, cp.gameObject.transform.position);
            float force    = 1000 * mcp.charge * cp.charge / Mathf.Pow(distance, 2);

            Vector3 direction = mcp.transform.position - cp.transform.position;
            direction.Normalize();

            newForce += force * direction * cycleInterval;

            if (float.IsNaN(newForce.x))
            {
                newForce = Vector3.zero;
            }

            mcp.rb.AddForce(newForce);
        }
    }
Beispiel #3
0
    private void ApplyMagneticForce(MovingChargedParticle mcp)
    {
        Vector3 newForce = Vector3.zero;

        foreach (ChargedParticle cp in chargedParticles)
        {
            if (mcp == cp)
            {
                continue;
            }

            if (mcp == null)
            {
                continue;
            }

            float distance = Vector3.Distance(mcp.transform.position, cp.gameObject.transform.position); // Distance between two charged particles.
            float force    = 1000 * mcp.charge * cp.charge / Mathf.Pow(distance, 2);                     //Relatively good scale number, and F = (q*q)/d^2 (Coulombs Law).

            Vector3 direction = mcp.transform.position - cp.transform.position;
            direction.Normalize();                            //Just care for the direction so magnitude does not matter here.

            newForce += force * direction * samplingInterval; //new force vector that results from all the different forces *directions * interval.


            if (float.IsNaN(newForce.x))
            {
                newForce = Vector3.zero;
            }
            mcp.rb.AddForce(newForce);
        }
    }
 public IEnumerator Cycle(MovingChargedParticle mcp)
 {
     while (true)
     {
         ApplyMagneticForce(mcp);
         yield return(new WaitForSeconds(cycleInterval));
     }
 }
Beispiel #5
0
 public IEnumerator Cycle(MovingChargedParticle mcp)
 {
     while (true)        // false disables ES
     {
         ApplyElectrostaticForce(mcp);
         yield return(new WaitForSeconds(cycleInterval));
     }
 }
Beispiel #6
0
 public void RegisterMovingChargedParticle(MovingChargedParticle mcp)
 {
     chargedParticles.Add(mcp);
     movingChargedParticles.Add(mcp);
     //if (electrostaticsOn)
     {
         StartCoroutine(Cycle(mcp));
     }
 }
Beispiel #7
0
    public IEnumerator Cycle(MovingChargedParticle mcp)
    {
        bool isFirst = true;

        while (mcp != null)
        {
            if (isFirst)
            {
                isFirst = false;
                yield return(new WaitForSeconds(Random.Range(0, samplingInterval)));
            }
            ApplyMagneticForce(mcp);
            yield return(new WaitForSeconds(samplingInterval));
        }
    }
    private void ApplyElectrostaticForce(MovingChargedParticle mcp)
    {
        Vector3 newForce = Vector3.zero;

        // null checks - seem to be necessary when sidechain mcp are deleted

        if (mcp)
        {
            //Debug.Log("mcp - " + mcp);
            //Debug.Log("mcp.rb - " + mcp.rb);

            foreach (ChargedParticle cp in chargedParticles)
            {
                //Debug.Log("cp - " + cp);
                if (cp)
                {
                    if (mcp == cp)
                    {
                        continue;
                    }

                    float distance = Vector3.Distance(mcp.transform.position, cp.transform.position);
                    float force    = (0.1f * mcp.charge * cp.charge) / Mathf.Pow(distance, 2);

                    Vector3 direction = mcp.transform.position - cp.transform.position;
                    direction.Normalize();

                    newForce += force * direction * cycleInterval;

                    if (float.IsNaN(newForce.x))
                    {
                        newForce = Vector3.zero;
                    }

                    //Debug.Log(mcp);
                    //Debug.Log(mcp.rb);
                    if (mcp.rb)
                    {
                        mcp.rb.AddForce(newForce, ForceMode.Impulse);
                    }
                }
            }
        }
    }
Beispiel #9
0
    // Update is called once per frame
    void Update()
    {
        time += Time.deltaTime;

        // Verifica si ya se instancio la particula
        if (!particleGO)
        {
            try
            {
                particleGO = GameObject.FindGameObjectWithTag("Particle");
            }
            catch (System.Exception)
            {

            }

        }

        // Obtiene el objeto
        if(flag && particleGO)
        {
            particle = GameObject.FindObjectOfType<MovingChargedParticle>();
            flag = false;
        }

        //Verifica si ya se tiene que terminar
        if (particleGO && (particle.isInEnd() || (time >= 15f)) && !finish)
        {
            Finish();
        }

        // Pausa
        if (Input.GetKeyDown(KeyCode.Escape) && !finish)
        {
            TogglePause();
        }
    }
Beispiel #10
0
 public void addParticle(MovingChargedParticle mcp)
 {
     chargedParticles.Add(mcp);
     movingChargedParticles.Add(mcp);
     createList();
 }
Beispiel #11
0
    private void ApplyElectrostaticForce(MovingChargedParticle mcp)
    {
        Vector3 newForce = Vector3.zero;

        // null checks - seem to be necessary when sidechain mcp are deleted

        if (mcp)
        {
            //Debug.Log("mcp - " + mcp);
            //Debug.Log("mcp.rb - " + mcp.rb);

            foreach (MovingChargedParticle mcp2 in movingChargedParticles)
            {
                //Debug.Log("cp - " + cp);
                if (mcp2)
                {
                    // Exclusions

                    // 1. don't act on myself
                    if (mcp == mcp2)
                    {
                        continue;
                    }

                    // 2. don't act on mcp in same residue
                    if (mcp.residueGO && mcp2.residueGO)
                    {
                        if (mcp.residueGO == mcp2.residueGO)
                        {
                            continue;
                        }
                    }

                    // 3. if backbone HN / OC don't act on adjacent residues
                    // (performance - not sure if paralleled in real MD sim)
                    if (mcp.rb && mcp2.rb)
                    {
                        if ((mcp.isBBAmide && mcp2.isBBCarbonyl) || (mcp2.isBBAmide && mcp.isBBCarbonyl))
                        {
                            if (mcp.myPPBChain == mcp2.myPPBChain)
                            {
                                if ((mcp.resid == mcp2.resid + 1) || (mcp.resid == mcp2.resid - 1))
                                {
                                    continue;
                                }
                            }
                        }

                        //if (mcp.rb.tag == "amide")
                        //{
                        //	if (mcp2.rb.tag == "carbonyl")
                        //	{

                        //		if (mcp.residueGO.GetComponent<Residue>().myPolyPepBuilder == mcp2.residueGO.GetComponent<Residue>().myPolyPepBuilder)
                        //		{
                        //			if (mcp.residueGO.GetComponent<Residue>().resid == (mcp2.residueGO.GetComponent<Residue>().resid + 1))
                        //			{
                        //				continue;
                        //			}
                        //			if (mcp.residueGO.GetComponent<Residue>().resid == (mcp2.residueGO.GetComponent<Residue>().resid - 1))
                        //			{
                        //				continue;
                        //			}
                        //		}

                        //	}
                        //}
                        //if (mcp.rb.tag == "carbonyl")
                        //{
                        //	if (mcp2.rb.tag == "amide")
                        //	{

                        //		if (mcp.residueGO.GetComponent<Residue>().myPolyPepBuilder == mcp2.residueGO.GetComponent<Residue>().myPolyPepBuilder)
                        //		{
                        //			if (mcp.residueGO.GetComponent<Residue>().resid == (mcp2.residueGO.GetComponent<Residue>().resid - 1))
                        //			{
                        //				continue;
                        //			}
                        //			if (mcp.residueGO.GetComponent<Residue>().resid == (mcp2.residueGO.GetComponent<Residue>().resid + 1))
                        //			{
                        //				continue;
                        //			}
                        //		}

                        //	}

                        //}
                    }



                    float distance = Vector3.Distance(mcp.transform.position, mcp2.transform.position);
                    float force    = (5.0f * 0.0025f * electrostaticsStrength * mcp.charge * mcp2.charge) / Mathf.Pow(distance, 2);

                    Vector3 direction = mcp.transform.position - mcp2.transform.position;
                    direction.Normalize();

                    newForce += force * direction * cycleInterval;

                    if (float.IsNaN(newForce.x))
                    {
                        newForce = Vector3.zero;
                    }
                }
            }
            //Debug.Log(mcp);
            //Debug.Log(mcp.rb);
            if (mcp.rb)
            {
                mcp.rb.AddForce(newForce, ForceMode.Impulse);
            }

            // particle system update
            if (mcp.myChargedParticle_ps)
            {
                if (showElectrostatics)
                {
                    if (!mcp.myChargedParticle_ps.isPlaying)
                    {
                        mcp.myChargedParticle_ps.Play();
                    }

                    //
                    var fo    = mcp.myChargedParticle_ps.forceOverLifetime;
                    var main  = mcp.myChargedParticle_ps.main;
                    var shape = mcp.myChargedParticle_ps.shape;

                    var em = mcp.myChargedParticle_ps.emission;
                    em.rate = Mathf.Abs(mcp.charge) * Mathf.Abs(mcp.charge) * 5000;


                    float scaleParticleForce = 7.5f * (1 / cycleInterval);                     // 1000.0f;
                    fo.x = scaleParticleForce * newForce.x;
                    fo.y = scaleParticleForce * newForce.y;
                    fo.z = scaleParticleForce * newForce.z;

                    //
                    main.startLifetimeMultiplier = Mathf.Clamp((1.0f - (0.5f * Vector3.Magnitude(newForce))), 0.1f, 1.0f);

                    //main.startSize = Mathf.Lerp(0.4f, 1.0f, (electrostaticsStrength / 100.0f));

                    main.startSize = Mathf.Lerp(0.4f, 2.0f, Vector3.Magnitude(newForce));

                    // scale shape radius to keep particles visible
                    // 2f is base radius in particle effect
                    shape.radius = 2f * myPolyPepManager.vdwScale;
                }
                else
                {
                    if (mcp.myChargedParticle_ps.isPlaying)
                    {
                        mcp.myChargedParticle_ps.Stop();
                    }
                }
            }
        }
    }
Beispiel #12
0
 public void UnRegisterMovingChargedParticle(MovingChargedParticle mcp)
 {
     movingChargedParticles.Remove(mcp);
     chargedParticles.Remove(mcp);
 }
 public void RegisterMovingChargedParticle(MovingChargedParticle mcp)
 {
     chargedParticles.Add(mcp);
     movingChargedParticles.Add(mcp);
     StartCoroutine(Cycle(mcp));
 }