<commit_before>/*******************************************************************************
GPU OPTIMIZED MONTE CARLO (GOMC) 2.70
Copyright (C) 2018  GOMC Group
A copy of the GNU General Public License can be found in the COPYRIGHT.txt
along with this program, also can be found at <http://www.gnu.org/licenses/>.
********************************************************************************/
#include <vector>
#include "StrLib.h" //for string comparison wrapper
#include "ExtendedSystem.h" //Corresponding header to this body
#include "FixedWidthReader.h" //For fixed width reader
#include "ConfigSetup.h" //For restart info
#include "DCDlib.h" // for Error output
#include "Velocity.h" // for velocity data
#include <stdlib.h> //for exit
#include <string> // for to_string

ExtendedSystem::ExtendedSystem()
{
  firstStep = 0;
  axis.Init(BOX_TOTAL);
  for(int b = 0; b < BOX_TOTAL; b++) {
    cellBasis[b] = XYZArray(3);
    hasCellBasis[b] = false;
    center[b].Reset();
  }
}

void ExtendedSystem::Init(PDBSetup &pdb, Velocity &vel,  config_setup::Input inputFiles,
                          MoleculeLookup & molLookup, Molecules & mols)
{
  // Read the extended system file and update the cellBasis data
  if(inputFiles.restart.restartFromXSCFile) {
    for(int b = 0; b < BOX_TOTAL; b++) {
      if(inputFiles.files.xscInput.defined[b]) {
        std::string fName = inputFiles.files.xscInput.name[b];
        ReadExtendedSystem(fName.c_str(), b);
        UpdateCellBasis(pdb, b);
      }
    }
  }
  // Read the binary coordinate and update the PDB coordinate
  if(inputFiles.restart.restartFromBinaryCoorFile) {
    int cmIndex = 0;
    for(int b = 0; b < BOX_TOTAL; b++) {
      if(inputFiles.files.binaryCoorInput.defined[b]) {
        std::string fName = inputFiles.files.binaryCoorInput.name[b];
        UpdateCoordinate(pdb, fName.c_str(), b, molLookup, mols, cmIndex);
      }
    }
  }
  // Read the binary velocity and update the buffer
  if(inputFiles.restart.restartFromBinaryVelFile) {
    int cmIndex = 0;
    for(int b = 0; b < BOX_TOTAL; b++) {
      if(inputFiles.files.binaryVelInput.defined[b]) {
        std::string fName = inputFiles.files.binaryVelInput.name[b];
        UpdateVelocity(pdb, vel, fName.c_str(), b, molLookup, mols, cmIndex);
      }
    }
  }
}

void ExtendedSystem::UpdateCoordinate(PDBSetup &pdb, const char *filename, const int box, MoleculeLookup & molLookup,
                                      Molecules & mols, int & cmIndex)
{
  // We must read restart PDB, which hold correct
  // number atom info in each Box
  int numAtoms = pdb.atoms.numAtomsInBox[box];
  int moleculeOffset = 0;
  XYZ *binaryCoor;
  binaryCoor = new XYZ[numAtoms];
  read_binary_file(filename, binaryCoor, numAtoms);
  //find the starting index

  for(; cmIndex < (int) molLookup.molLookupCount; cmIndex++) {
    if(moleculeOffset >= numAtoms) break;
    int currentMolecule = molLookup.molLookup[cmIndex];
    int numberOfAtoms = mols.start[currentMolecule + 1] - mols.start[currentMolecule];
    int atomDestinationStart = mols.start[currentMolecule];

    for(int atom = 0; atom < numberOfAtoms; atom++) {
      pdb.atoms.x[atomDestinationStart + atom] = binaryCoor[moleculeOffset + atom].x;
      pdb.atoms.y[atomDestinationStart + atom] = binaryCoor[moleculeOffset + atom].y;
      pdb.atoms.z[atomDestinationStart + atom] = binaryCoor[moleculeOffset + atom].z;
    }

    moleculeOffset += numberOfAtoms;
  }

  delete [] binaryCoor;
}

void ExtendedSystem::UpdateVelocity(PDBSetup &pdb, Velocity &vel, const char *filename, const int box,
                                    MoleculeLookup & molLookup, Molecules & mols, int & cmIndex)
{
  // We must read restart PDB, which hold correct
  // number atom info in each Box
  int numAtoms = pdb.atoms.numAtomsInBox[box];
  int moleculeOffset = 0;
  XYZ *binaryVel;
  binaryVel = new XYZ[numAtoms];
  read_binary_file(filename, binaryVel, numAtoms);
  //find the starting index

  for(; cmIndex < (int) molLookup.molLookupCount; cmIndex++) {<commit_msg>Use the same loading pattern from PDBSetup in XTC<commit_after>/*******************************************************************************
GPU OPTIMIZED MONTE CARLO (GOMC) 2.70
Copyright (C) 2018  GOMC Group
A copy of the GNU General Public License can be found in the COPYRIGHT.txt
along with this program, also can be found at <http://www.gnu.org/licenses/>.
********************************************************************************/
#include <vector>
#include "StrLib.h" //for string comparison wrapper
#include "ExtendedSystem.h" //Corresponding header to this body
#include "FixedWidthReader.h" //For fixed width reader
#include "ConfigSetup.h" //For restart info
#include "DCDlib.h" // for Error output
#include "Velocity.h" // for velocity data
#include <stdlib.h> //for exit
#include <string> // for to_string

ExtendedSystem::ExtendedSystem()
{
  firstStep = 0;
  axis.Init(BOX_TOTAL);
  for(int b = 0; b < BOX_TOTAL; b++) {
    cellBasis[b] = XYZArray(3);
    hasCellBasis[b] = false;
    center[b].Reset();
  }
}

void ExtendedSystem::Init(PDBSetup &pdb, Velocity &vel,  config_setup::Input inputFiles,
                          MoleculeLookup & molLookup, Molecules & mols)
{
  // Read the extended system file and update the cellBasis data
  if(inputFiles.restart.restartFromXSCFile) {
    for(int b = 0; b < BOX_TOTAL; b++) {
      if(inputFiles.files.xscInput.defined[b]) {
        std::string fName = inputFiles.files.xscInput.name[b];
        ReadExtendedSystem(fName.c_str(), b);
        UpdateCellBasis(pdb, b);
      }
    }
  }
  // Read the binary coordinate and update the PDB coordinate
  if(inputFiles.restart.restartFromBinaryCoorFile) {
    int cmIndex = 0;
    for(int b = 0; b < BOX_TOTAL; b++) {
      if(inputFiles.files.binaryCoorInput.defined[b]) {
        std::string fName = inputFiles.files.binaryCoorInput.name[b];
        UpdateCoordinate(pdb, fName.c_str(), b, molLookup, mols, cmIndex);
      }
    }
  }
  // Read the binary velocity and update the buffer
  if(inputFiles.restart.restartFromBinaryVelFile) {
    int cmIndex = 0;
    for(int b = 0; b < BOX_TOTAL; b++) {
      if(inputFiles.files.binaryVelInput.defined[b]) {
        std::string fName = inputFiles.files.binaryVelInput.name[b];
        UpdateVelocity(pdb, vel, fName.c_str(), b, molLookup, mols, cmIndex);
      }
    }
  }
}

void ExtendedSystem::UpdateCoordinate(PDBSetup &pdb, const char *filename, const int box, MoleculeLookup & molLookup,
                                      Molecules & mols, int & cmIndex)
{
    uint p, d, trajectoryI, dataI, placementStart, placementEnd, dataStart, dataEnd;
  // We must read restart PDB, which hold correct
  // number atom info in each Box
  int numAtoms = pdb.atoms.numAtomsInBox[box];
  int moleculeOffset = 0;
  XYZ *binaryCoor;
  binaryCoor = new XYZ[numAtoms];
  read_binary_file(filename, binaryCoor, numAtoms);
  //find the starting index
  for (int mol = 0; mol < molLookup.molLookupCount; mol++){
    trajectoryI = molLookupRef.originalMoleculeIndices[mol];
    dataI = mol;
    //Loop through particles in mol.
    mols.GetOriginalRangeStartStop(placementStart, placementEnd, trajectoryI);
    mols.GetRangeStartStop(dataStart, dataEnd, dataI);
    for (p = placementStart, d = dataStart; p < placementEnd; ++p, ++d) {
      pdb.atoms.x[p] = binaryCoor[d].x;
      pdb.atoms.y[p] = binaryCoor[d].y;
      pdb.atoms.z[p] = binaryCoor[d].z;
    }
  }
  delete [] binaryCoor;
}

void ExtendedSystem::UpdateVelocity(PDBSetup &pdb, Velocity &vel, const char *filename, const int box,
                                    MoleculeLookup & molLookup, Molecules & mols, int & cmIndex)
{
  // We must read restart PDB, which hold correct
  // number atom info in each Box
  int numAtoms = pdb.atoms.numAtomsInBox[box];
  int moleculeOffset = 0;
  XYZ *binaryVel;
  binaryVel = new XYZ[numAtoms];
  read_binary_file(filename, binaryVel, numAtoms);
  //find the starting index

  for(; cmIndex < (int) molLookup.molLookupCount; cmIndex++) {
{'fraction_non_alphanumeric': 0.1523927905531386, 'fraction_numerical': 0.004599129894344313, 'mean_word_length': 3.532957746478873, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3673754', 'n_tokens_mistral': 2702, 'n_tokens_neox': 2578, 'n_words': 677}