Beispiel #1
0
    public IEnumerator GetAmberEGH(bool suppressStretches = false, bool suppressBends = false, bool suppressTorsions = true, bool suppressNonBonding = false)
    {
        _busy++;

        rmsForces = 0f;
        int c;

        for (int atomNum = 0; atomNum < atoms.size; atomNum++)
        {
            for (c = 0; c < 3; c++)
            {
                positions[atomNum * 3 + c] = atoms[atomNum].p[c];
            }
        }
        int numAtoms = size;

        forces = new double[numAtoms * 3];
        Fortran.allocate_atom_arrays(ref numAtoms);

        int status = 0;

        double[] stretchesEnergy = new double[2];
        double[] bendsEnergy     = new double[2];
        double[] torsionsEnergy  = new double[2];
        double[] vdwsEnergy      = new double[2];
        double[] coulombicEnergy = new double[2];

        Fortran.e_amber(positions, forces,
                        stretchesEnergy, bendsEnergy, torsionsEnergy, vdwsEnergy,
                        coulombicEnergy, ref rmsForces, ref status
                        );
        Fortran.CheckStatus(status);

        //GetStretchesEGH();
        //yield return null;
        //GetBendsEGH();
        //yield return null;
        //GetTorsionEGH();
        ///yield return null;
        //GetNonBondingEGH();
        //yield return null;

        allStretchesEnergy = stretchesEnergy[0];
        allBendsEnergy     = bendsEnergy[0];
        allTorsionsEnergy  = torsionsEnergy[0];
        allVdwsEnergy      = vdwsEnergy[0];
        allCoulombicEnergy = coulombicEnergy[0];

        amberEnergy = allStretchesEnergy + allBendsEnergy + allTorsionsEnergy + allVdwsEnergy + allCoulombicEnergy;
        totalEnergy = amberEnergy + kineticEnergy;
        for (int atomNum = 0; atomNum < atoms.size; atomNum++)
        {
            for (c = 0; c < 3; c++)
            {
                atoms[atomNum].force[c] = (float)forces[3 * atomNum + c];
            }
        }
        _busy--;
        yield return(null);
    }
Beispiel #2
0
    public void InitialiseMasses()
    {
        int status = 0;

        Fortran.set_masses(atoms.masses, ref status);
        Fortran.CheckStatus(status);
    }
Beispiel #3
0
    public IEnumerator AMBEROpt(int steps, int updateAfterSteps = 5)
    {
        _busy++;

        int status   = 0;
        int c        = 0;
        int numAtoms = size;

        positions = new double[numAtoms * 3];

        for (int atomNum = 0; atomNum < numAtoms; atomNum++)
        {
            for (c = 0; c < 3; c++)
            {
                positions[3 * atomNum + c] = atoms[atomNum].p[c];
            }
        }

        Fortran.allocate_atom_arrays(ref numAtoms);

        IEnumerator iEnumerator;

        iEnumerator = InitialiseParameters();
        while (iEnumerator.MoveNext())
        {
        }
        yield return(null);

        double[] stretchesEnergy = new double[2];
        double[] bendsEnergy     = new double[2];
        double[] torsionsEnergy  = new double[2];
        double[] vdwsEnergy      = new double[2];
        double[] coulombicEnergy = new double[2];

        string logPath = "/Users/tristanmackenzie/Unity/ONIOM/Assets/Plugins/out.log";

        System.IO.File.Delete(logPath);

        double convergence_threshold = 0.00001;
        int    precision             = 3;
        int    iprint             = 0;
        int    matrix_corrections = 17;

        int     stepNum   = 0;
        Vector3 vPosition = new Vector3();

        while (stepNum < steps)
        {
            writeArray(positions, logPath);
            Fortran.lbfgs_optimise(positions, ref updateAfterSteps,
                                   stretchesEnergy, bendsEnergy, torsionsEnergy,
                                   vdwsEnergy, coulombicEnergy, ref convergence_threshold,
                                   ref precision, ref iprint, ref matrix_corrections, ref status
                                   );
            writeArray(positions, logPath);
            Fortran.CheckStatus(status);

            allStretchesEnergy = stretchesEnergy[0];
            allBendsEnergy     = bendsEnergy[0];
            allTorsionsEnergy  = torsionsEnergy[0];
            allVdwsEnergy      = vdwsEnergy[0];
            allCoulombicEnergy = coulombicEnergy[0];

            amberEnergy = allStretchesEnergy + allBendsEnergy + allTorsionsEnergy + allVdwsEnergy + allCoulombicEnergy;
            totalEnergy = amberEnergy + kineticEnergy;

            stepNum += updateAfterSteps;
            for (int atomNum = 0; atomNum < numAtoms; atomNum++)
            {
                for (c = 0; c < 3; c++)
                {
                    vPosition[c] = (float)positions[3 * atomNum + c];
                }
                atoms[atomNum].transform.localPosition = vPosition;
            }

            yield return(null);
        }

        _busy--;
        yield return(null);
    }
Beispiel #4
0
    public IEnumerator MDVerlet(int steps, int updateAfterSteps = 5)
    {
        _busy++;

        int status   = 0;
        int c        = 0;
        int numAtoms = size;

        positions = new double[numAtoms * 3];

        for (int atomNum = 0; atomNum < numAtoms; atomNum++)
        {
            for (c = 0; c < 3; c++)
            {
                positions[3 * atomNum + c] = atoms[atomNum].p[c];
            }
        }



        Fortran.allocate_atom_arrays(ref numAtoms);

        IEnumerator iEnumerator;

        iEnumerator = InitialiseParameters();
        while (iEnumerator.MoveNext())
        {
        }
        yield return(null);

        double[] stretchesEnergy = new double[2];
        double[] bendsEnergy     = new double[2];
        double[] torsionsEnergy  = new double[2];
        double[] vdwsEnergy      = new double[2];
        double[] coulombicEnergy = new double[2];

        double mdTimeStep      = atoms.globalSettings.mdTimeStep;
        double mdDampingFactor = atoms.globalSettings.mdDampingFactor;

        string logPath = "/Users/tristanmackenzie/Unity/ONIOM/Assets/Plugins/out.log";

        System.IO.File.Delete(logPath);

        //Run MD
        int     stepNum   = 0;
        Vector3 vPosition = new Vector3();

        while (stepNum < steps)
        {
            writeArray(positions, logPath);
            Fortran.md_verlet(positions, ref updateAfterSteps,
                              ref mdTimeStep, ref mdDampingFactor,
                              stretchesEnergy, bendsEnergy, torsionsEnergy, vdwsEnergy, coulombicEnergy,
                              ref kineticEnergy, ref rmsForces, ref status);
            writeArray(positions, logPath);
            Fortran.CheckStatus(status);

            allStretchesEnergy = stretchesEnergy[0];
            allBendsEnergy     = bendsEnergy[0];
            allTorsionsEnergy  = torsionsEnergy[0];
            allVdwsEnergy      = vdwsEnergy[0];
            allCoulombicEnergy = coulombicEnergy[0];

            amberEnergy = allStretchesEnergy + allBendsEnergy + allTorsionsEnergy + allVdwsEnergy + allCoulombicEnergy;
            totalEnergy = amberEnergy + kineticEnergy;

            stepNum += updateAfterSteps;
            for (int atomNum = 0; atomNum < numAtoms; atomNum++)
            {
                for (c = 0; c < 3; c++)
                {
                    vPosition[c] = (float)positions[3 * atomNum + c];
                }
                atoms[atomNum].transform.localPosition = vPosition;
            }

            yield return(null);
        }

        _busy--;
        yield return(null);
    }