Commit 04ea8ce9 authored by Peter Eastman's avatar Peter Eastman
Browse files

Fixed lots of errors and warnings compiling under Windows

parent a01da386
......@@ -41,11 +41,11 @@ SET(OPENMM_SOURCE_SUBDIRS . openmmapi olla platforms/reference)
# SET(LIB64) # nothing
#ENDIF (ARCH64)
IF( ${CMAKE_SIZEOF_VOID_P} EQUAL 8 )
IF( CMAKE_SIZEOF_VOID_P EQUAL 8 )
SET( LIB64 64 )
ELSE( ${CMAKE_SIZEOF_VOID_P} EQUAL 8 )
ELSE( CMAKE_SIZEOF_VOID_P EQUAL 8 )
SET( LIB64 )
ENDIF( ${CMAKE_SIZEOF_VOID_P} EQUAL 8 )
ENDIF( CMAKE_SIZEOF_VOID_P EQUAL 8 )
IF(UNIX AND NOT CMAKE_BUILD_TYPE)
......
......@@ -68,7 +68,7 @@ class OPENMM_EXPORT StreamImpl;
* may choose to implement it internally with single precision values.
*/
class Stream {
class OPENMM_EXPORT Stream {
public:
Stream();
Stream(const Stream& copy);
......
......@@ -43,7 +43,7 @@ namespace OpenMM {
* A StreamImpl defines the internal implementation of a Stream object.
*/
class StreamImpl {
class OPENMM_EXPORT StreamImpl {
public:
/**
* Create a StreamImpl.
......
......@@ -49,7 +49,7 @@ class System;
* This is the internal implementation of an OpenMMContext.
*/
class OpenMMContextImpl {
class OPENMM_EXPORT OpenMMContextImpl {
public:
/**
* Create an OpenMMContextImpl for an OpenMMContext;
......
......@@ -41,7 +41,7 @@ namespace OpenMM {
* This Platform subclass uses CUDA implementations of the OpenMM kernels to run on NVidia GPUs.
*/
class CudaPlatform : public Platform {
class OPENMM_EXPORT CudaPlatform : public Platform {
public:
CudaPlatform();
std::string getName() const {
......
......@@ -40,7 +40,7 @@ namespace OpenMM {
* This StreamFactory creates all streams for CudaPlatform.
*/
class CudaStreamFactory : public StreamFactory {
class OPENMM_EXPORT CudaStreamFactory : public StreamFactory {
public:
StreamImpl* createStreamImpl(std::string name, int size, Stream::DataType type, const Platform& platform, OpenMMContextImpl& context) const;
};
......
......@@ -70,8 +70,8 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
psBondID->_pSysStream[0][i].y = bondIndices[i][1];
psBondID->_pSysStream[0][i].z = gpu->pOutputBufferCounter[psBondID->_pSysStream[0][i].x]++;
psBondID->_pSysStream[0][i].w = gpu->pOutputBufferCounter[psBondID->_pSysStream[0][i].y]++;
psBondParameter->_pSysStream[0][i].x = bondParameters[i][0];
psBondParameter->_pSysStream[0][i].y = bondParameters[i][1];
psBondParameter->_pSysStream[0][i].x = (float) bondParameters[i][0];
psBondParameter->_pSysStream[0][i].y = (float) bondParameters[i][1];
}
psBondID->Upload();
psBondParameter->Upload();
......@@ -95,8 +95,8 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
psBondAngleID1->_pSysStream[0][i].w = gpu->pOutputBufferCounter[psBondAngleID1->_pSysStream[0][i].x]++;
psBondAngleID2->_pSysStream[0][i].x = gpu->pOutputBufferCounter[psBondAngleID1->_pSysStream[0][i].y]++;
psBondAngleID2->_pSysStream[0][i].y = gpu->pOutputBufferCounter[psBondAngleID1->_pSysStream[0][i].z]++;
psBondAngleParameter->_pSysStream[0][i].x = angleParameters[i][0]*180.0/M_PI;
psBondAngleParameter->_pSysStream[0][i].y = angleParameters[i][1];
psBondAngleParameter->_pSysStream[0][i].x = (float) (angleParameters[i][0]*180.0/3.14159265);
psBondAngleParameter->_pSysStream[0][i].y = (float) angleParameters[i][1];
}
psBondAngleID1->Upload();
psBondAngleID2->Upload();
......@@ -123,9 +123,9 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
psDihedralID2->_pSysStream[0][i].y = gpu->pOutputBufferCounter[psDihedralID1->_pSysStream[0][i].y]++;
psDihedralID2->_pSysStream[0][i].z = gpu->pOutputBufferCounter[psDihedralID1->_pSysStream[0][i].z]++;
psDihedralID2->_pSysStream[0][i].w = gpu->pOutputBufferCounter[psDihedralID1->_pSysStream[0][i].w]++;
psDihedralParameter->_pSysStream[0][i].x = periodicTorsionParameters[i][0];
psDihedralParameter->_pSysStream[0][i].y = periodicTorsionParameters[i][1];
psDihedralParameter->_pSysStream[0][i].z = periodicTorsionParameters[i][2];
psDihedralParameter->_pSysStream[0][i].x = (float) periodicTorsionParameters[i][0];
psDihedralParameter->_pSysStream[0][i].y = (float) periodicTorsionParameters[i][1];
psDihedralParameter->_pSysStream[0][i].z = (float) periodicTorsionParameters[i][2];
psDihedralParameter->_pSysStream[0][i].w = 0.0f;
}
psDihedralID1->Upload();
......@@ -156,12 +156,12 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
psRbDihedralID2->_pSysStream[0][i].y = gpu->pOutputBufferCounter[psRbDihedralID1->_pSysStream[0][i].y]++;
psRbDihedralID2->_pSysStream[0][i].z = gpu->pOutputBufferCounter[psRbDihedralID1->_pSysStream[0][i].z]++;
psRbDihedralID2->_pSysStream[0][i].w = gpu->pOutputBufferCounter[psRbDihedralID1->_pSysStream[0][i].w]++;
psRbDihedralParameter1->_pSysStream[0][i].x = rbTorsionParameters[i][0];
psRbDihedralParameter1->_pSysStream[0][i].y = rbTorsionParameters[i][1];
psRbDihedralParameter1->_pSysStream[0][i].z = rbTorsionParameters[i][2];
psRbDihedralParameter1->_pSysStream[0][i].w = rbTorsionParameters[i][3];
psRbDihedralParameter2->_pSysStream[0][i].x = rbTorsionParameters[i][4];
psRbDihedralParameter2->_pSysStream[0][i].y = rbTorsionParameters[i][5];
psRbDihedralParameter1->_pSysStream[0][i].x = (float) rbTorsionParameters[i][0];
psRbDihedralParameter1->_pSysStream[0][i].y = (float) rbTorsionParameters[i][1];
psRbDihedralParameter1->_pSysStream[0][i].z = (float) rbTorsionParameters[i][2];
psRbDihedralParameter1->_pSysStream[0][i].w = (float) rbTorsionParameters[i][3];
psRbDihedralParameter2->_pSysStream[0][i].x = (float) rbTorsionParameters[i][4];
psRbDihedralParameter2->_pSysStream[0][i].y = (float) rbTorsionParameters[i][5];
}
psRbDihedralID1->Upload();
psRbDihedralID2->Upload();
......@@ -171,9 +171,9 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
// Initialize nonbonded interactions.
for (int i = 0; i < numAtoms; i++) {
gpu->psPosq4->_pSysStream[0][i].w = nonbondedParameters[i][0];
gpu->psSigEps2->_pSysStream[0][i].x = nonbondedParameters[i][1];
gpu->psSigEps2->_pSysStream[0][i].y = nonbondedParameters[i][2];
gpu->psPosq4->_pSysStream[0][i].w = (float) nonbondedParameters[i][0];
gpu->psSigEps2->_pSysStream[0][i].x = (float) nonbondedParameters[i][1];
gpu->psSigEps2->_pSysStream[0][i].y = (float) nonbondedParameters[i][2];
}
gpu->psPosq4->Upload();
gpu->psSigEps2->Upload();
......@@ -197,9 +197,9 @@ void CudaCalcStandardMMForceFieldKernel::initialize(const vector<vector<int> >&
psLJ14ID->_pSysStream[0][i].y = atom2;
psLJ14ID->_pSysStream[0][i].z = gpu->pOutputBufferCounter[psLJ14ID->_pSysStream[0][i].x]++;
psLJ14ID->_pSysStream[0][i].w = gpu->pOutputBufferCounter[psLJ14ID->_pSysStream[0][i].y]++;
psLJ14Parameter->_pSysStream[0][i].x = atom1params[0]+atom2params[0];
psLJ14Parameter->_pSysStream[0][i].y = lj14Scale*(atom1params[1]*atom2params[1]);
psLJ14Parameter->_pSysStream[0][i].z = coulomb14Scale*(atom1params[2]*atom2params[2]);
psLJ14Parameter->_pSysStream[0][i].x = (float) (atom1params[0]+atom2params[0]);
psLJ14Parameter->_pSysStream[0][i].y = (float) (lj14Scale*(atom1params[1]*atom2params[1]));
psLJ14Parameter->_pSysStream[0][i].z = (float) (coulomb14Scale*(atom1params[2]*atom2params[2]));
}
psLJ14ID->Upload();
psLJ14Parameter->Upload();
......@@ -217,6 +217,7 @@ void CudaCalcStandardMMForceFieldKernel::executeForces(const Stream& positions,
}
double CudaCalcStandardMMForceFieldKernel::executeEnergy(const Stream& positions) {
return 0.0;
}
//CudaCalcGBSAOBCForceFieldKernel::~CudaCalcGBSAOBCForceFieldKernel() {
......
......@@ -141,15 +141,15 @@ void CudaStreamImpl<T>::loadFromArray(const void* array) {
double* arrayData = (double*) array;
for (int i = 0; i < getSize(); ++i)
for (int j = 0; j < width; ++j)
data[i*rowOffset+j] = arrayData[i*width+j];
data[i*rowOffset+j] = (float) arrayData[i*width+j];
}
else {
int* arrayData = (int*) array;
for (int i = 0; i < getSize(); ++i)
for (int j = 0; j < width; ++j)
data[i*rowOffset+j] = arrayData[i*width+j];
data[i*rowOffset+j] = (float) arrayData[i*width+j];
}
for (int i = getSize(); i < stream->_length; ++i)
for (int i = getSize(); i < (int) stream->_length; ++i)
for (int j = 0; j < rowOffset; ++j)
data[i*rowOffset+j] = paddingValues[j];
stream->Upload();
......@@ -174,7 +174,7 @@ void CudaStreamImpl<T>::saveToArray(void* array) {
int* arrayData = (int*) array;
for (int i = 0; i < getSize(); ++i)
for (int j = 0; j < width; ++j)
arrayData[i*width+j] = data[i*rowOffset+j];
arrayData[i*width+j] = (int) data[i*rowOffset+j];
}
stream->Download();
}
......@@ -192,15 +192,15 @@ void CudaStreamImpl<T>::fillWithValue(void* value) {
double valueData = *((double*) value);
for (int i = 0; i < getSize(); ++i)
for (int j = 0; j < width; ++j)
data[i*rowOffset+j] = valueData;
data[i*rowOffset+j] = (float) valueData;
}
else {
int valueData = *((int*) value);
for (int i = 0; i < getSize(); ++i)
for (int j = 0; j < width; ++j)
data[i*rowOffset+j] = valueData;
data[i*rowOffset+j] = (float) valueData;
}
for (int i = getSize(); i < stream->_length; ++i)
for (int i = getSize(); i < (int) stream->_length; ++i)
for (int j = 0; j < rowOffset; ++j)
data[i*rowOffset+j] = paddingValues[j];
stream->Upload();
......
......@@ -71,16 +71,16 @@ void testStream(Stream::DataType type, T scale) {
array[i] = 0;
stream.saveToArray(array);
for (int i = 0; i < length; ++i)
ASSERT_EQUAL_TOL((i*scale), array[i], TOL);
ASSERT_EQUAL_TOL(0, array[length], TOL);
ASSERT_EQUAL_TOL((double) (i*scale), array[i], TOL);
ASSERT_EQUAL_TOL(0.0, (double) array[length], TOL);
}
int main() {
try {
testStream<float, 1>(Stream::Float, 0.1);
testStream<float, 2>(Stream::Float2, 0.1);
testStream<float, 3>(Stream::Float3, 0.1);
testStream<float, 4>(Stream::Float4, 0.1);
testStream<float, 1>(Stream::Float, 0.1f);
testStream<float, 2>(Stream::Float2, 0.1f);
testStream<float, 3>(Stream::Float3, 0.1f);
testStream<float, 4>(Stream::Float4, 0.1f);
testStream<double, 1>(Stream::Double, 0.1);
testStream<double, 2>(Stream::Double2, 0.1);
testStream<double, 3>(Stream::Double3, 0.1);
......
......@@ -164,10 +164,10 @@ void ReferenceCalcStandardMMForceFieldKernel::initialize(const vector<vector<int
bonded14ParamArray[i][2] = static_cast<RealOpenMM>( coulomb14Scale*(atomParamArray[atom1][2]*atomParamArray[atom2][2]) );
}
this->nonbondedMethod = nonbondedMethod;
this->nonbondedCutoff = nonbondedCutoff;
this->periodicBoxSize[0] = periodicBoxSize[0];
this->periodicBoxSize[1] = periodicBoxSize[1];
this->periodicBoxSize[2] = periodicBoxSize[2];
this->nonbondedCutoff = (RealOpenMM) nonbondedCutoff;
this->periodicBoxSize[0] = (RealOpenMM) periodicBoxSize[0];
this->periodicBoxSize[1] = (RealOpenMM) periodicBoxSize[1];
this->periodicBoxSize[2] = (RealOpenMM) periodicBoxSize[2];
if (nonbondedMethod == NoCutoff)
neighborList = NULL;
else
......@@ -191,14 +191,14 @@ void ReferenceCalcStandardMMForceFieldKernel::executeForces(const Stream& positi
bool periodic = (nonbondedMethod == CutoffPeriodic);
if (nonbondedMethod != NoCutoff) {
computeNeighborListVoxelHash(*neighborList, numAtoms, posData, exclusions, periodic ? periodicBoxSize : NULL, nonbondedCutoff, 0.0);
clj.setUseCutoff(nonbondedCutoff, *neighborList, 78.3);
clj.setUseCutoff(nonbondedCutoff, *neighborList, 78.3f);
}
if (periodic)
clj.setPeriodic(periodicBoxSize);
clj.calculatePairIxn(numAtoms, posData, atomParamArray, exclusionArray, 0, forceData, 0, 0);
ReferenceLJCoulomb14 nonbonded14;
if (nonbondedMethod != NoCutoff)
nonbonded14.setUseCutoff(nonbondedCutoff, 78.3);
nonbonded14.setUseCutoff(nonbondedCutoff, 78.3f);
refBondForce.calculateForce(num14, bonded14IndexArray, posData, bonded14ParamArray, forceData, 0, 0, 0, nonbonded14);
}
......@@ -229,14 +229,14 @@ double ReferenceCalcStandardMMForceFieldKernel::executeEnergy(const Stream& posi
bool periodic = (nonbondedMethod == CutoffPeriodic);
if (nonbondedMethod != NoCutoff) {
computeNeighborListVoxelHash(*neighborList, numAtoms, posData, exclusions, periodic ? periodicBoxSize : NULL, nonbondedCutoff, 0.0);
clj.setUseCutoff(nonbondedCutoff, *neighborList, 78.3);
clj.setUseCutoff(nonbondedCutoff, *neighborList, 78.3f);
}
if (periodic)
clj.setPeriodic(periodicBoxSize);
clj.calculatePairIxn(numAtoms, posData, atomParamArray, exclusionArray, 0, forceData, 0, &energy);
ReferenceLJCoulomb14 nonbonded14;
if (nonbondedMethod != NoCutoff)
nonbonded14.setUseCutoff(nonbondedCutoff, 78.3);
nonbonded14.setUseCutoff(nonbondedCutoff, 78.3f);
for (int i = 0; i < arraySize; ++i)
energyArray[i] = 0;
refBondForce.calculateForce(num14, bonded14IndexArray, posData, bonded14ParamArray, forceData, energyArray, 0, &energy, nonbonded14);
......
......@@ -70,7 +70,7 @@ ReferenceForce::~ReferenceForce( ){
RealOpenMM ReferenceForce::periodicDifference(RealOpenMM val1, RealOpenMM val2, RealOpenMM period) {
RealOpenMM diff = val1-val2;
RealOpenMM base = floor(diff/period+0.5)*period;
RealOpenMM base = (RealOpenMM) (floor(diff/period+0.5)*period);
return diff-base;
}
......
......@@ -78,8 +78,8 @@ ReferenceLJCoulomb14::~ReferenceLJCoulomb14( ){
cutoff = true;
cutoffDistance = distance;
krf = pow(cutoffDistance, -3.0)*(solventDielectric-1.0)/(2.0*solventDielectric+1.0);
crf = (1.0/cutoffDistance)*(3.0*solventDielectric)/(2.0*solventDielectric+1.0);
krf = pow(cutoffDistance, -3.0f)*(solventDielectric-1.0f)/(2.0f*solventDielectric+1.0f);
crf = (1.0f/cutoffDistance)*(3.0f*solventDielectric)/(2.0f*solventDielectric+1.0f);
return ReferenceForce::DefaultReturn;
}
......@@ -202,7 +202,7 @@ int ReferenceLJCoulomb14::calculateBondIxn( int* atomIndices, RealOpenMM** atomC
RealOpenMM dEdR = parameters[1]*( twelve*sig6 - six )*sig6;
if (cutoff)
dEdR += parameters[2]*(inverseR-2.0*krf*r2);
dEdR += parameters[2]*(inverseR-2.0f*krf*r2);
else
dEdR += parameters[2]*inverseR;
dEdR *= inverseR*inverseR;
......
......@@ -80,8 +80,8 @@ ReferenceLJCoulombIxn::~ReferenceLJCoulombIxn( ){
cutoff = true;
cutoffDistance = distance;
neighborList = &neighbors;
krf = pow(cutoffDistance, -3.0)*(solventDielectric-1.0)/(2.0*solventDielectric+1.0);
crf = (1.0/cutoffDistance)*(3.0*solventDielectric)/(2.0*solventDielectric+1.0);
krf = pow(cutoffDistance, -3.0f)*(solventDielectric-1.0f)/(2.0f*solventDielectric+1.0f);
crf = (1.0f/cutoffDistance)*(3.0f*solventDielectric)/(2.0f*solventDielectric+1.0f);
return ReferenceForce::DefaultReturn;
}
......@@ -190,7 +190,7 @@ int ReferenceLJCoulombIxn::calculatePairIxn( int numberOfAtoms, RealOpenMM** ato
RealOpenMM* energyByAtom, RealOpenMM* totalEnergy ) const {
if (cutoff) {
for (int i = 0; i < neighborList->size(); i++) {
for (int i = 0; i < (int) neighborList->size(); i++) {
OpenMM::AtomPair pair = (*neighborList)[i];
calculateOneIxn(pair.first, pair.second, atomCoordinates, atomParameters, forces, energyByAtom, totalEnergy);
}
......@@ -290,7 +290,7 @@ int ReferenceLJCoulombIxn::calculatePairIxn( int numberOfAtoms, RealOpenMM** ato
RealOpenMM eps = atomParameters[ii][EpsIndex]*atomParameters[jj][EpsIndex];
RealOpenMM dEdR = eps*( twelve*sig6 - six )*sig6;
if (cutoff)
dEdR += atomParameters[ii][QIndex]*atomParameters[jj][QIndex]*(inverseR-2.0*krf*r2);
dEdR += atomParameters[ii][QIndex]*atomParameters[jj][QIndex]*(inverseR-2.0f*krf*r2);
else
dEdR += atomParameters[ii][QIndex]*atomParameters[jj][QIndex]*inverseR;
dEdR *= inverseR*inverseR;
......@@ -373,5 +373,6 @@ int ReferenceLJCoulombIxn::calculatePairIxn( int numberOfAtoms, RealOpenMM** ato
SimTKOpenMMLog::printMessage( message );
}
return ReferenceForce::DefaultReturn;
}
#ifndef OPENMM_REFERENCE_NEIGHBORLIST_H_
#define OPENMM_REFERENCE_NEIGHBORLIST_H_
#include "../SimTKUtilities/SimTKOpenMMRealType.h"
#include "internal/windowsExport.h"
#include <set>
#include <vector>
namespace OpenMM {
typedef RealOpenMM** AtomLocationList;
typedef unsigned int AtomIndex;
typedef std::pair<AtomIndex, AtomIndex> AtomPair;
typedef std::vector<AtomPair> NeighborList;
// Ridiculous O(n^2) version of neighbor list
// for pedagogical purposes and simplicity
// parameter neighborList is automatically clear()ed before
// neighbors are added
void OPENMM_EXPORT computeNeighborListNaive(
NeighborList& neighborList,
int nAtoms,
const AtomLocationList& atomLocations,
const std::vector<std::set<int> >& exclusions,
const RealOpenMM* periodicBoxSize,
double maxDistance,
double minDistance = 0.0,
bool reportSymmetricPairs = false
);
// O(n) neighbor list method using voxel hash data structure
// parameter neighborList is automatically clear()ed before
// neighbors are added
void OPENMM_EXPORT computeNeighborListVoxelHash(
NeighborList& neighborList,
int nAtoms,
const AtomLocationList& atomLocations,
const std::vector<std::set<int> >& exclusions,
const RealOpenMM* periodicBoxSize,
double maxDistance,
double minDistance = 0.0,
bool reportSymmetricPairs = false
);
} // namespace OpenMM
#endif // OPENMM_REFERENCE_NEIGHBORLIST_H_
......@@ -3,6 +3,7 @@
#include <map>
#include <cmath>
#include <iostream>
#include <cassert>
using namespace std;
......@@ -34,7 +35,7 @@ static double compPairDistanceSquared(const RealOpenMM* pos1, const RealOpenMM*
// Ridiculous O(n^2) version of neighbor list
// for pedagogical purposes and simplicity
void computeNeighborListNaive(
void OPENMM_EXPORT computeNeighborListNaive(
NeighborList& neighborList,
int nAtoms,
const AtomLocationList& atomLocations,
......@@ -50,9 +51,9 @@ void computeNeighborListNaive(
double maxDistanceSquared = maxDistance * maxDistance;
double minDistanceSquared = minDistance * minDistance;
for (AtomIndex atomI = 0; atomI < (nAtoms - 1); ++atomI)
for (AtomIndex atomI = 0; atomI < (AtomIndex) (nAtoms - 1); ++atomI)
{
for (AtomIndex atomJ = atomI + 1; atomJ < nAtoms; ++atomJ)
for (AtomIndex atomJ = atomI + 1; atomJ < (AtomIndex) nAtoms; ++atomJ)
{
double pairDistanceSquared = compPairDistanceSquared(atomLocations[atomI], atomLocations[atomJ], periodicBoxSize);
if ( (pairDistanceSquared <= maxDistanceSquared) && (pairDistanceSquared >= minDistanceSquared))
......@@ -97,9 +98,9 @@ public:
VoxelHash(double vsx, double vsy, double vsz, const RealOpenMM* periodicBoxSize) :
voxelSizeX(vsx), voxelSizeY(vsy), voxelSizeZ(vsz), periodicBoxSize(periodicBoxSize) {
if (periodicBoxSize != NULL) {
nx = floor(periodicBoxSize[0]/voxelSizeX+0.5);
ny = floor(periodicBoxSize[1]/voxelSizeY+0.5);
nz = floor(periodicBoxSize[2]/voxelSizeZ+0.5);
nx = (int) floor(periodicBoxSize[0]/voxelSizeX+0.5);
ny = (int) floor(periodicBoxSize[1]/voxelSizeY+0.5);
nz = (int) floor(periodicBoxSize[2]/voxelSizeZ+0.5);
}
}
......@@ -213,7 +214,7 @@ private:
// O(n) neighbor list method using voxel hash data structure
void computeNeighborListVoxelHash(
void OPENMM_EXPORT computeNeighborListVoxelHash(
NeighborList& neighborList,
int nAtoms,
const AtomLocationList& atomLocations,
......@@ -235,7 +236,7 @@ void computeNeighborListVoxelHash(
edgeSizeZ = periodicBoxSize[2]/floor(periodicBoxSize[2]/maxDistance);
}
VoxelHash voxelHash(edgeSizeX, edgeSizeY, edgeSizeZ, periodicBoxSize);
for (AtomIndex atomJ = 0; atomJ < nAtoms; ++atomJ) // use "j", because j > i for pairs
for (AtomIndex atomJ = 0; atomJ < (AtomIndex) nAtoms; ++atomJ) // use "j", because j > i for pairs
{
// 1) Find other atoms that are close to this one
const RealOpenMM* location = atomLocations[atomJ];
......
/* Portions copyright (c) 2006 Stanford University and Simbios.
* Contributors: Pande Group
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __SimTKOpenMMUtilities_H_
#define __SimTKOpenMMUtilities_H_
// class of shared, static utility methods
#include "SimTKOpenMMCommon.h"
#include "../sfmt/SFMT.h"
#include "internal/windowsExport.h"
#include <stdio.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <sstream>
// template is used to check if a string is integer, real, ...
template <class T>
bool checkString( T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&) ){
std::istringstream iss(s);
return !(iss >> f >> t).fail();
}
/**---------------------------------------------------------------------------------------
Class of static methods to be shared
Most methods are standalone 'utility' methods
--------------------------------------------------------------------------------------- */
class OPENMM_EXPORT SimTKOpenMMUtilities {
private:
static uint32_t _randomNumberSeed;
static bool _randomInitialized;
public:
// file flag enums
enum FileFlags { OpenDebugFile, WriteDebugFile, CloseDebugFile };
// dummy constructor/destructor
SimTKOpenMMUtilities(){};
~SimTKOpenMMUtilities(){};
/**---------------------------------------------------------------------------------------
Find distances**2 from a given atom (Simbios)
@param atomCoordinates atom coordinates
@param atomIndex atom index to find distances from
@param numberOfAtoms number of atoms
@param distances array of distances squared on @return; array size must be at least
numberOfAtoms
@param log if set, then print error messages to log file
@return distances
--------------------------------------------------------------------------------------- */
static int getDistanceSquaredFromSpecifiedAtom( RealOpenMM** atomCoordinates, int atomIndex,
int numberOfAtoms, RealOpenMM* distances,
FILE* log );
/**---------------------------------------------------------------------------------------
Find distances**2 from a given point (Simbios)
@param atomCoordinates atom coordinates
@param point point to find distances from
@param numberOfAtoms number of atoms
@param distances array of distances squared on @return; array size must be at least
numberOfAtoms
@param log if set, then print error messages to log file
@return distances
--------------------------------------------------------------------------------------- */
static int getDistanceSquaredFromSpecifiedPoint( RealOpenMM** atomCoordinates, RealOpenMM* point,
int numberOfAtoms, RealOpenMM* distances,
FILE* log );
/**---------------------------------------------------------------------------------------
Helper method to allocate RealOpenMM arrays (Simbios)
@param bufferIndex buffer index
@param allocatedSz array of allocated sizes
@param bufferArray array of allocated RealOpenMM arrays
@param requestedSize requested size
@param dataAction action flag: -1 = free memory \n
1 = zero memory
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
static int allocateRealOpenMMBufferArray( int bufferIndex, int* allocatedSz,
RealOpenMM** bufferArray,
int requestedSize, int dataAction );
/**---------------------------------------------------------------------------------------
Print atom coordinates, ...
@param numberAtoms numberAtoms
@param atomCoordinates atomCoordinates (may be NULL)
@param numberOf1Darrays number of 1-d arrays (may be 0)
@param oneDArrays 1-d arrays
@param idString id string to be printed if set
@param log print messages to log file
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
static int printCoordinateAnd1DArrays( int numberAtoms, RealOpenMM** atomCoordinates,
int numberOf1Darrays, RealOpenMM** oneDArrays,
const char* idString, FILE* log );
/**---------------------------------------------------------------------------------------
Free array of strings
@param arraySz atom index
@param arrayOfStrings array of strings
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
static int freeArrayOfStrings( int arraySz, char** arrayOfStrings );
/**---------------------------------------------------------------------------------------
Tab string in place
@param string string to tab; assume string is of at least length=tab + 1
@param tab tab length
--------------------------------------------------------------------------------------- */
static int tabStringInPlace( char* string, int tab );
/**---------------------------------------------------------------------------------------
Write debug fields (Simbios)
@param numberOfFields number of fields to print
@param fields fields
@param numberOfStringFields number of string fields to print
@param stringFields string fields
@param comment comment (optinal -- ignored if NULL)
@param debugFileName output debug file name
@param action 0 open file and @return w/o printing
1 open file and print
2 close file (no print)
@param debugFile debug file reference
@param log if set, then print error messages to log file
@return debugFile unless file is closed
stringFields printed after RealOpenMM fields
--------------------------------------------------------------------------------------- */
static FILE* writeDebugFile( int numberOfFields, const RealOpenMM* fields,
int numberOfStringFields, const StringVector& stringFields,
const char* comment, const char* debugFileName, int action,
FILE* debugFile, FILE* log );
/**---------------------------------------------------------------------------------------
Allocate 1D RealOpenMM array (Simbios)
array[i]
@param iSize i-dimension
@param array1D array (if null on entry allocated)
@param initialize if true, then initialize array
@param initialValue intitial value
@param idString id string
@return array
--------------------------------------------------------------------------------------- */
static RealOpenMM* allocateOneDRealOpenMMArray( int iSize, RealOpenMM* array1D, int initialize,
RealOpenMM initialValue,
const std::string& idString = std::string( "1DArray" ) );
/**---------------------------------------------------------------------------------------
Allocate 2D RealOpenMM array (Simbios)
array[i][j]
@param iSize i-dimension
@param jSize j-dimension
@param array2D array (if null on entry allocated)
@param initialize if true, then initialize array
@param initialValue intitial value
@param idString id string
@return array
--------------------------------------------------------------------------------------- */
static RealOpenMM** allocateTwoDRealOpenMMArray( int iSize, int jSize,
RealOpenMM** array2D, int initialize,
RealOpenMM initialValue,
const std::string& idString = std::string( "2DArray" ) );
/* ---------------------------------------------------------------------------------------
Free 2D RealOpenMM array (Simbios)
array[i][j]
@param array2D array (if null on entry allocated)
@param idString id string
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
static int freeOneDRealOpenMMArray( RealOpenMM* array1D,
const std::string& idString = std::string( "1DArray" ) );
/* ---------------------------------------------------------------------------------------
Free 2D RealOpenMM array (Simbios)
array[i][j]
@param array2D array (if null on entry allocated)
@param idString id string
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
static int freeTwoDRealOpenMMArray( RealOpenMM** array2D,
const std::string& idString = std::string( "2DArray" ) );
/**---------------------------------------------------------------------------------------
Initialize 2D RealOpenMM array (Simbios)
array[i][j]
@param iSize i-dimension
@param jSize j-dimension
@param array2D array (if null on entry allocated)
@param initialValue intitial value
@return array
--------------------------------------------------------------------------------------- */
static int initialize2DRealOpenMMArray( int iSize, int jSize,
RealOpenMM** array2D, RealOpenMM initialValue );
/**---------------------------------------------------------------------------------------
Malloc memory of size bytesToAllocate and zero
@param bytesToAllocate bytes to allocate
@return ptr to allocated memory; NULL if bytesToAllocate <= 0
--------------------------------------------------------------------------------------- */
static char* allocateAndZero( unsigned int bytesToAllocate );
/**---------------------------------------------------------------------------------------
Normalize 3-vector -- helper method
@param vector vector to normalize
--------------------------------------------------------------------------------------- */
static void normalizeVector3( RealOpenMM* vector );
/**---------------------------------------------------------------------------------------
Remove 3-vector -- helper method
@param vectorToRemove vector to remove
@param vector vector to from which 'vectorToRemove' is to be removed \n
vector is normalized after the component is subtracted out
--------------------------------------------------------------------------------------- */
static void removeVector3( RealOpenMM* vectorToRemove, RealOpenMM* vector );
/**---------------------------------------------------------------------------------------
Compute cross product of two 3-vectors and place in 3rd vector -- helper method
@param vectorZ = vectorX x vectorY
@param vectorX x-vector
@param vectorY y-vector
@param vectorZ z-vector
@return vector is vectorZ
--------------------------------------------------------------------------------------- */
static void crossProductVector3( RealOpenMM* vectorX, RealOpenMM* vectorY, RealOpenMM* vectorZ );
/**---------------------------------------------------------------------------------------
Compute matrix product of 3x3 matrix and 3-vector and place in 3rd vector -- helper method
@param vectorZ = matrixX . vectorY
@param matrixX matrixX
@param vectorY y-vector
@param vectorZ z-vector
@return vector is vectorZ
--------------------------------------------------------------------------------------- */
static void matrixProductVector3( RealOpenMM* matrixX, RealOpenMM* vectorY, RealOpenMM* vectorZ );
/**---------------------------------------------------------------------------------------
Compute cross product between two 3x3 matrices
@param vectorZ = matrixX . matrixY
@param matrixX matrixX
@param matrixY matrixY
@param vectorZ z-vector
@return vector is vectorZ
--------------------------------------------------------------------------------------- */
static void matrixCrossProductMatrix3( RealOpenMM* matrixX, RealOpenMM* matrixY, RealOpenMM* vectorZ );
/* ---------------------------------------------------------------------------------------
Centralized malloc/new
@param name ptr name
@param fileName file name
@param line file line no.
@param file line size in bytes to be allocated
@return ptr to allocated object
--------------------------------------------------------------------------------------- */
static void* Xmalloc( const char* name, char* fileName, int line, unsigned int size );
/* ---------------------------------------------------------------------------------------
Centralized free/delete
@param name ptr name
@param fileName file name
@param line file line no.
@param ptr ptr to be freed
--------------------------------------------------------------------------------------- */
static void Xfree( const char* name, char* fileName, int line, void* ptr );
/* ---------------------------------------------------------------------------------------
Format array of reals
@param message input string stream
@param realArray array of RealOpenMMs
@param numberOfFields number of fields (optional - defaults to 3)
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
static int formatRealStringStream( std::stringstream& message, const RealOpenMM* realArray,
int numberOfFields = 3, RealOpenMM factor = (RealOpenMM) 1.0f );
/**---------------------------------------------------------------------------------------
Tokenize a string (static method) (Simbios)
@param lineBuffer string to tokenize
@param tokenArray upon return vectory of tokens
@param delimiter token delimter
@return number of args
--------------------------------------------------------------------------------------- */
static int tokenizeString( char* lineBuffer, StringVector& tokenArray, const std::string delimiter = "\t\n " );
/**---------------------------------------------------------------------------------------
Tokenize a string (static method) (Simbios)
@param line string to tokenize
@param tokenVector upon return vector of tokens
@param delimiter token delimter
@param clearTokenVector if true, clear tokenVector
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
static int tokenizeString( const std::string& line, StringVector& tokenVector,
const std::string& delimiter, int clearTokenVector );
/**---------------------------------------------------------------------------------------
Local version of strncasecmp (missing in Windows) (static method) (Simbios)
@param string1 first string
@param string2 second string
@param matchLength match length
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
static int localStrncasecmp( const char *string1, const char *string2, int matchLength );
/**---------------------------------------------------------------------------------------
Check that string is valid integer
@param stringToCheck string to check
@return true if string is a valid integer
--------------------------------------------------------------------------------------- */
static bool isValidInteger( std::string stringToCheck );
/**---------------------------------------------------------------------------------------
Check that string is valid RealOpenMM
@param stringToCheck string to check
@return true if string is a valid RealOpenMM
--------------------------------------------------------------------------------------- */
static bool isValidRealOpenMM( std::string stringToCheck );
/**---------------------------------------------------------------------------------------
Read file into string vector (Simbios)
@param fileName file name
@param fileContents string vector containing file contents upon return
one string per line
@return SimTKOpenMMCommon::DefaultReturn unless file could not be opened
--------------------------------------------------------------------------------------- */
static int readFileIntoStringVector( const std::string& fileName, StringVector& fileContents );
/**---------------------------------------------------------------------------------------
Read file into string vector (Simbios)
@param charArray character array
@param arrayLength array length
@param arrayContents string vector containing array contents upon return
one string per line
@return SimTKOpenMMCommon::DefaultReturn unless file could not be opened
--------------------------------------------------------------------------------------- */
static int readCharacterArrayIntoStringVector( const char* charArray, int arrayLength,
StringVector& fileContents );
/**---------------------------------------------------------------------------------------
Replacement of sorts for strtok() (static method) (Simbios)
Used to parse parameter file lines
Should be moved to Utilities file
@param lineBuffer string to tokenize
@param delimiter token delimter
@return number of args; if return value equals maxTokens, then more tokens than allocated
--------------------------------------------------------------------------------------- */
static char* strsep( char** lineBuffer, const char* delimiter );
/**---------------------------------------------------------------------------------------
Write file (helper method) (Simbios)
@param lineVector line entries for file
@param inputFileName inputFileName
@return SimTKOpenMMCommon::ErrorReturn if error -- else SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
static int writeFile( const StringVector& lineVector, const std::string& fileName );
/**---------------------------------------------------------------------------------------
Get statistics on an array
@param numberOfEntries number of entries in array
@param array array
@param average average of array on output
@param stdDev std dev of array on output
@param minValue min value in array on output
@param minIndex index of min value in array on output
@param maxValue max value in array on output
@param maxIndex index of max value in array on output
if numberOfEntries <= 0, return 0 for all RealOpenMM values and -1 for index values
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
static int getArrayStatistics( int numberOfEntries, const RealOpenMM* array,
RealOpenMM* average, RealOpenMM* stdDev,
RealOpenMM* minValue, int* minIndex,
RealOpenMM* maxValue, int* maxIndex );
/**---------------------------------------------------------------------------------------
Get one 2D array to another
@param dimension1 first dimension
@param dimension2 second dimension
@param arrayToAdd array to add [dimension1][dimension2]
@param sumArray summed array to add [dimension1][dimension2]
@return SimTKOpenMMCommon::DefaultReturn
--------------------------------------------------------------------------------------- */
static int addTwoDimArray( int dimension1, int dimension2, RealOpenMM** arrayToAdd,
RealOpenMM** sumArray );
/**---------------------------------------------------------------------------------------
Get normally distributed random number
@return random value
--------------------------------------------------------------------------------------- */
static RealOpenMM getNormallyDistributedRandomNumber( void );
/**---------------------------------------------------------------------------------------
Get uniformly distributed random number in the range [0, 1)
@return random value
--------------------------------------------------------------------------------------- */
static RealOpenMM getUniformlyDistributedRandomNumber( void );
/**---------------------------------------------------------------------------------------
Get random number seed
@return random number seed
--------------------------------------------------------------------------------------- */
static uint32_t getRandomNumberSeed( void );
/**---------------------------------------------------------------------------------------
Set random number seed
@param seed new seed value
@return DefaultReturn
--------------------------------------------------------------------------------------- */
static void setRandomNumberSeed( uint32_t seed );
};
// ---------------------------------------------------------------------------------------
#endif // __SimTKOpenMMUtilities_H__
......@@ -13,7 +13,7 @@ void testNeighborList()
atomList[0] = new RealOpenMM[3];
atomList[1] = new RealOpenMM[3];
atomList[2] = new RealOpenMM[3];
atomList[0][0] = 13.6;
atomList[0][0] = 13.6f;
atomList[0][1] = 0;
atomList[0][2] = 0;
atomList[1][0] = 0;
......@@ -54,7 +54,7 @@ double distance2(RealOpenMM* pos1, RealOpenMM* pos2, const RealOpenMM* periodicB
}
void verifyNeighborList(NeighborList& list, int numAtoms, RealOpenMM** positions, const RealOpenMM* periodicBoxSize, double cutoff) {
for (int i = 0; i < list.size(); i++) {
for (int i = 0; i < (int) list.size(); i++) {
int atom1 = list[i].first;
int atom2 = list[i].second;
ASSERT(distance2(positions[atom1], positions[atom2], periodicBoxSize) <= cutoff*cutoff);
......@@ -75,9 +75,9 @@ void testPeriodic() {
init_gen_rand(0);
for (int i = 0; i <numAtoms; i++) {
atomList[i] = new RealOpenMM[3];
atomList[i][0] = genrand_real2()*periodicBoxSize[0]*3;
atomList[i][1] = genrand_real2()*periodicBoxSize[1]*3;
atomList[i][2] = genrand_real2()*periodicBoxSize[2]*3;
atomList[i][0] = (RealOpenMM) (genrand_real2()*periodicBoxSize[0]*3);
atomList[i][1] = (RealOpenMM) (genrand_real2()*periodicBoxSize[1]*3);
atomList[i][2] = (RealOpenMM) (genrand_real2()*periodicBoxSize[2]*3);
}
vector<set<int> > exclusions(numAtoms);
NeighborList neighborList;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment