<commit_before>
/*******************************************************************************
 ** Copyright <NAME> 2011
 ** Filtering routines written in C to improve performance
 *******************************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "utilities.h"


/*******************************************************************************
 ** Specie filter
 *******************************************************************************/
int specieFilter(int NVisibleIn, int *visibleAtoms, int visSpecDim, int* visSpec, int specieDim, int *specie)
{
    int i, j, index, match, NVisible;
    
    
    NVisible = 0;
    for (i=0; i<NVisibleIn; i++)
    {
        index = visibleAtoms[i];
        
        match = 0;
        for (j=0; j<visSpecDim; j++)
        {
            if (specie[index] == visSpec[j])
            {
                match = 1;
                break;
            }
        }
        
        if (match)
        {
            visibleAtoms[NVisible] = index;
            NVisible++;
        }
    }
    
    return NVisible;
}


/*******************************************************************************
 ** Slice filter
 *******************************************************************************/
int sliceFilter(int NVisibleIn, int *visibleAtoms, int posDim, double *pos, double x0,
                double y0, double z0, double xn, double yn, double zn, int invert)
{
    int i, NVisible, index, addFlag;
    double mag, xd, yd, zd, dotProd, distanceToPlane;
    
    /* normalise (xn, yn, zn) */
    mag = sqrt(x0 * x0 + y0 * y0 + z0 * z0);
    xn = xn / mag;
    yn = yn / mag;
    zn = zn / mag;
    
    NVisible = 0;
    for (i=0; i<NVisibleIn; i++)
    {
        index = visibleAtoms[i];
        
        xd = pos[3*index] - x0;
        yd = pos[3*index+1] - y0;
        zd = pos[3*index+2] - z0;
        
        dotProd = xd * xn + yd * yn + zd * zn;
        distanceToPlane = dotProd / mag;
        
        addFlag = 0;
        if ((invert && distanceToPlane > 0) || (!invert && distanceToPlane < 0))
        {
            addFlag = 1;
        }
        
        if (addFlag)
        {
            visibleAtoms[NVisible] = index;
            NVisible++;
        }
    }
    
    return NVisible;
}


/*******************************************************************************
 ** Crop sphere filter
 *******************************************************************************/
int cropSphereFilter(int NVisibleIn, int *visibleAtoms, int posDim, double *pos, double xCentre, 
                     double yCentre, double zCentre, double radius, int cellDimsDim, double *cellDims, 
                     int PBCDim, int *PBC, int invertSelection)
{
    int i, NVisible, index;
    double radius2, sep2;
    <commit_msg>Removed unnecessary section from sliceFilter (clib).<commit_after>
/*******************************************************************************
 ** Copyright <NAME> 2011
 ** Filtering routines written in C to improve performance
 *******************************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "utilities.h"


/*******************************************************************************
 ** Specie filter
 *******************************************************************************/
int specieFilter(int NVisibleIn, int *visibleAtoms, int visSpecDim, int* visSpec, int specieDim, int *specie)
{
    int i, j, index, match, NVisible;
    
    
    NVisible = 0;
    for (i=0; i<NVisibleIn; i++)
    {
        index = visibleAtoms[i];
        
        match = 0;
        for (j=0; j<visSpecDim; j++)
        {
            if (specie[index] == visSpec[j])
            {
                match = 1;
                break;
            }
        }
        
        if (match)
        {
            visibleAtoms[NVisible] = index;
            NVisible++;
        }
    }
    
    return NVisible;
}


/*******************************************************************************
 ** Slice filter
 *******************************************************************************/
int sliceFilter(int NVisibleIn, int *visibleAtoms, int posDim, double *pos, double x0,
                double y0, double z0, double xn, double yn, double zn, int invert)
{
    int i, NVisible, index;
    double mag, xd, yd, zd, dotProd, distanceToPlane;
    
    /* normalise (xn, yn, zn) */
    mag = sqrt(x0 * x0 + y0 * y0 + z0 * z0);
    xn = xn / mag;
    yn = yn / mag;
    zn = zn / mag;
    
    NVisible = 0;
    for (i=0; i<NVisibleIn; i++)
    {
        index = visibleAtoms[i];
        
        xd = pos[3*index] - x0;
        yd = pos[3*index+1] - y0;
        zd = pos[3*index+2] - z0;
        
        dotProd = xd * xn + yd * yn + zd * zn;
        distanceToPlane = dotProd / mag;
        
        if ((invert && distanceToPlane > 0) || (!invert && distanceToPlane < 0))
        {
            visibleAtoms[NVisible] = index;
            NVisible++;
        }
    }
    
    return NVisible;
}


/*******************************************************************************
 ** Crop sphere filter
 *******************************************************************************/
int cropSphereFilter(int NVisibleIn, int *visibleAtoms, int posDim, double *pos, double xCentre, 
                     double yCentre, double zCentre, double radius, int cellDimsDim, double *cellDims, 
                     int PBCDim, int *PBC, int invertSelection)
{
    int i, NVisible, index;
    double radius2, sep2;
    
{'fraction_non_alphanumeric': 0.315511783327471, 'fraction_numerical': 0.01160745691171298, 'mean_word_length': 2.474037874160049, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 15, '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': '6314355', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1572, 'n_words': 416}