<commit_before>/* 
 * 
 * <NAME> - <EMAIL>
 * Copyright (c) 2014, Regents of the University of California
 * Released under BSD 2-Clause License (see "LICENSE" file)
 * 
 * This library of functions implements various comparison ISDMs
 * intended to quanitfy the difference between two input structures
 * from a trajectory. The gromacs libraries are required and
 * some functions are performed in libmammothmod.c and libesa.c.
 * 
 * See help output for citation information.
 */


#include <math.h>
#include <string.h>

#include "libisdm.h"

#include <gromacs/statutil.h>
#include <gromacs/sysstuff.h>
#include <gromacs/typedefs.h>
#include <gromacs/smalloc.h>
#include <gromacs/macros.h>
#include <gromacs/vec.h>
#include <gromacs/pbc.h>
#include <gromacs/copyrite.h>
#include <gromacs/futil.h>
#include <gromacs/statutil.h>
#include <gromacs/index.h>
#include <gromacs/mshift.h>
#include <gromacs/xvgr.h>
#include <gromacs/rmpbc.h>
#include <gromacs/txtdump.h>
#include <gromacs/tpxio.h>
#include <gromacs/gstat.h>
#include <gromacs/gmx_ana.h>



//extern void mammothmod_(double xfit[], double xref[], int* nc, int* rnum, double* zscore);
double esa_analysis(int iatoms, rvec frame[], rvec rframe[], int sample);



real calc_rmsd(int iatoms, rvec frame[], rvec rframe[])
{
    /* This is a simplified version of something in the gromacs lib.
     * The accuracy is slightly improved by using doubles instead of reals.
     */
    int i, d;
    double xd, msdt;
    
    msdt = 0.0;
    for(i = 0; i < iatoms; i++)
    {
        // Calculations to find msd.
        for(d = 0; d < 3; d++)
        {
            xd     = (double)(frame[i][d] - rframe[i][d]);
            msdt += xd * xd;
        }
    }
    // Normalize for number of atoms.
    return (real)sqrt(msdt / iatoms);
}



real calc_rmsd_n(int iatoms, rvec frame[], rvec rframe[], real rmsd[])
{
    /* This is a simplified version of something in the gromacs lib.
     * The accuracy is slightly improved by using doubles instead of reals.
     */
    int i, d;
    double xd, rmsdi, rmsdt;
    
    rmsdt = 0.0;
    for(i = 0; i < iatoms; i++)
    {
        // Calculations to find msd.
        rmsdi = 0.0;
        for(d = 0; d < 3; d++)
        {
            xd     = (double)(frame[i][d] - rframe[i][d]);
            rmsdi += xd * xd;
        }
        rmsdi   = sqrt(rmsdi);
        rmsd[i] = (real)rmsdi;
        rmsdt  += rmsdi;
    }
    // Normalize for number of atoms.
    return (real)(rmsdt / iatoms);
}



real calc_srms(int iatoms, rvec frame[], rvec rframe[])
{
    /* Size-independent modification of RMSD. Scaled to a value [0,1].
     * 
     * Maiorov and Crippen, 1995.
     * SRMS = D(A,B) / [2*R(A)^2 + 2*R(B)^2 - D(A,B)^2]^(1/2)
     * 
     * The original equation (16) replaces 2*R(B)^2 with R(B)^2 which appears
     * to be a typo.
     */
    int i, d;
    double xd, rc, rr, msdt, denom;
    
    msdt = 0.0; rc = 0.0; rr = 0.0;
    for(i = 0; i < iatoms; i++)
    {
        // Calculations to find MSD and Rg.
        for(d = 0; d < 3; d++)
        {
            // MSD portion.
            xd    = (double)(frame[i][d] - rframe[i][d]);
            msdt += xd * xd;
            // Rg portion.
            rc   += (double)( frame[i][d] *  frame[i][d]);
            rr   += (double)(rframe[i][d] * rframe[i][d]);
        }
    }
    // Normalize for the number of atoms.
    msdt /= iatoms;
    rc   /= iatoms;
    rr   /= iatoms;
    // Equation 16 appeared to have a typo.
    return (real)sqrt(msdt) / sqrt((2 * rc) + (2 * rr) - (2 * msdt));
}



real calc_srms_n(int iatoms, rvec frame[], rvec rframe[], real srms[])
{
    /* Size-independent modification of RMSD. Scaled to a value [0,1].
     * 
     * 
     */
    int i, d;
    double xd, rmsdi, rmsdt;
    
    rmsdt = 0.0;
    for(i = 0; i < iatoms; i++)
    {
        // Calculations to find msd.
        rmsdi = 0.0;
        for(d = 0; d < 3; d++)
        {
            xd     = (double)(frame[i][d] - rframe[i][d]);
            rmsdi += xd * xd;
        }
        rmsdi   = sqrt(rmsdi);
        srms[i] = (real)rmsdi;
        rmsdt  += rmsdi;
    }
    // Normalize for number of atoms.<commit_msg>Fixed a multiplier in an equation for the size-independent RMSD function.<commit_after>/* 
 * 
 * <NAME> - <EMAIL>
 * Copyright (c) 2014, Regents of the University of California
 * Released under BSD 2-Clause License (see "LICENSE" file)
 * 
 * This library of functions implements various comparison ISDMs
 * intended to quanitfy the difference between two input structures
 * from a trajectory. The gromacs libraries are required and
 * some functions are performed in libmammothmod.c and libesa.c.
 * 
 * See help output for citation information.
 */


#include <math.h>
#include <string.h>

#include "libisdm.h"

#include <gromacs/statutil.h>
#include <gromacs/sysstuff.h>
#include <gromacs/typedefs.h>
#include <gromacs/smalloc.h>
#include <gromacs/macros.h>
#include <gromacs/vec.h>
#include <gromacs/pbc.h>
#include <gromacs/copyrite.h>
#include <gromacs/futil.h>
#include <gromacs/statutil.h>
#include <gromacs/index.h>
#include <gromacs/mshift.h>
#include <gromacs/xvgr.h>
#include <gromacs/rmpbc.h>
#include <gromacs/txtdump.h>
#include <gromacs/tpxio.h>
#include <gromacs/gstat.h>
#include <gromacs/gmx_ana.h>



//extern void mammothmod_(double xfit[], double xref[], int* nc, int* rnum, double* zscore);
double esa_analysis(int iatoms, rvec frame[], rvec rframe[], int sample);



real calc_rmsd(int iatoms, rvec frame[], rvec rframe[])
{
    /* This is a simplified version of something in the gromacs lib.
     * The accuracy is slightly improved by using doubles instead of reals.
     */
    int i, d;
    double xd, msdt;
    
    msdt = 0.0;
    for(i = 0; i < iatoms; i++)
    {
        // Calculations to find msd.
        for(d = 0; d < 3; d++)
        {
            xd     = (double)(frame[i][d] - rframe[i][d]);
            msdt += xd * xd;
        }
    }
    // Normalize for number of atoms.
    return (real)sqrt(msdt / iatoms);
}



real calc_rmsd_n(int iatoms, rvec frame[], rvec rframe[], real rmsd[])
{
    /* This is a simplified version of something in the gromacs lib.
     * The accuracy is slightly improved by using doubles instead of reals.
     */
    int i, d;
    double xd, rmsdi, rmsdt;
    
    rmsdt = 0.0;
    for(i = 0; i < iatoms; i++)
    {
        // Calculations to find msd.
        rmsdi = 0.0;
        for(d = 0; d < 3; d++)
        {
            xd     = (double)(frame[i][d] - rframe[i][d]);
            rmsdi += xd * xd;
        }
        rmsdi   = sqrt(rmsdi);
        rmsd[i] = (real)rmsdi;
        rmsdt  += rmsdi;
    }
    // Normalize for number of atoms.
    return (real)(rmsdt / iatoms);
}



real calc_srms(int iatoms, rvec frame[], rvec rframe[])
{
    /* Size-independent modification of RMSD. Scaled to a value [0,1].
     * 
     * Maiorov and Crippen, 1995.
     * SRMS = D(A,B) / [2*R(A)^2 + 2*R(B)^2 - D(A,B)^2]^(1/2)
     * 
     * The original equation (16) replaces 2*R(B)^2 with R(B)^2 which appears
     * to be a typo.
     */
    int i, d;
    double xd, rc, rr, msdt;
    
    msdt = 0.0; rc = 0.0; rr = 0.0;
    for(i = 0; i < iatoms; i++)
    {
        // Calculations to find MSD and Rg.
        for(d = 0; d < 3; d++)
        {
            // MSD portion.
            xd    = (double)(frame[i][d] - rframe[i][d]);
            msdt += xd * xd;
            // Rg portion.
            rc   += (double)( frame[i][d] *  frame[i][d]);
            rr   += (double)(rframe[i][d] * rframe[i][d]);
        }
    }
    // Normalize for the number of atoms.
    msdt /= iatoms;
    rc   /= iatoms;
    rr   /= iatoms;
    // Equation 16 appeared to have a typo.
    return (real)sqrt(msdt) / sqrt((2 * rc) + (2 * rr) - msdt);
}



real calc_srms_n(int iatoms, rvec frame[], rvec rframe[], real srms[])
{
    /* Size-independent modification of RMSD. Scaled to a value [0,1].
     * 
     * 
     */
    int i, d;
    double xd, rmsdi, rmsdt;
    
    rmsdt = 0.0;
    for(i = 0; i < iatoms; i++)
    {
        // Calculations to find msd.
        rmsdi = 0.0;
        for(d = 0; d < 3; d++)
        {
            xd     = (double)(frame[i][d] - rframe[i][d]);
            rmsdi += xd * xd;
        }
        rmsdi   = sqrt(rmsdi);
        srms[i] = (real)rmsdi;
        rmsdt  += rmsdi;
    }
    // Normalize for number of atoms.
{'fraction_non_alphanumeric': 0.14803300251106064, 'fraction_numerical': 0.013751046275260075, 'mean_word_length': 2.102373887240356, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6378464', 'n_tokens_mistral': 3349, 'n_tokens_neox': 3184, 'n_words': 883}