本文整理汇总了C++中CpptrajFile类的典型用法代码示例。如果您正苦于以下问题:C++ CpptrajFile类的具体用法?C++ CpptrajFile怎么用?C++ CpptrajFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CpptrajFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: integerToString
/** For each point p, calculate function Kdist(p) which is the distance of
* the Kth nearest point to p.
*/
void Cluster_DBSCAN::ComputeKdist( int Kval, std::vector<int> const& FramesToCluster ) const {
std::vector<double> dists;
std::vector<double> Kdist;
dists.reserve( FramesToCluster.size() );
Kdist.reserve( FramesToCluster.size() );
std::string outfilename = k_prefix_ + "Kdist." + integerToString(Kval) + ".dat";
mprintf("\tDBSCAN: Calculating Kdist(%i), output to %s\n", Kval, outfilename.c_str());
for (std::vector<int>::const_iterator point = FramesToCluster.begin();
point != FramesToCluster.end();
++point)
{
// Store distances from this point
dists.clear();
for (std::vector<int>::const_iterator otherpoint = FramesToCluster.begin();
otherpoint != FramesToCluster.end();
++otherpoint)
dists.push_back( FrameDistances_.GetFdist(*point, *otherpoint) );
// Sort distances - first dist should always be 0
std::sort(dists.begin(), dists.end());
Kdist.push_back( dists[Kval] );
}
std::sort( Kdist.begin(), Kdist.end() );
CpptrajFile Outfile;
Outfile.OpenWrite(outfilename);
Outfile.Printf("%-8s %1i%-11s\n", "#Point", Kval,"-dist");
// Write out largest to smallest
unsigned int ik = 0;
for (std::vector<double>::reverse_iterator k = Kdist.rbegin();
k != Kdist.rend(); ++k, ++ik)
Outfile.Printf("%8u %12.4f\n", ik, *k);
Outfile.CloseFile();
}
示例2: WriteData
// DataIO_Std::WriteData()
int DataIO_Std::WriteData(FileName const& fname, DataSetList const& SetList)
{
int err = 0;
if (!SetList.empty()) {
// Open output file.
CpptrajFile file;
if (file.OpenWrite( fname )) return 1;
// Base write type off first data set dimension FIXME
if (SetList[0]->Group() == DataSet::CLUSTERMATRIX) {
// Special case of 2D - may have sieved frames.
err = WriteCmatrix(file, SetList);
} else if (SetList[0]->Ndim() == 1) {
if (group_ == NO_TYPE) {
if (isInverted_)
err = WriteDataInverted(file, SetList);
else
err = WriteDataNormal(file, SetList);
} else
err = WriteByGroup(file, SetList, group_);
} else if (SetList[0]->Ndim() == 2)
err = WriteData2D(file, SetList);
else if (SetList[0]->Ndim() == 3)
err = WriteData3D(file, SetList);
file.CloseFile();
}
return err;
}
示例3: ID_TrajFormat
/** \return true if TRR/TRJ file. */
bool Traj_GmxTrX::ID_TrajFormat(CpptrajFile& infile) {
// File must already be set up for read
if (infile.OpenFile()) return false;
bool istrx = IsTRX(infile);
infile.CloseFile();
return istrx;
}
示例4: ReadDihedrals
// Action_ClusterDihedral::ReadDihedrals()
int Action_ClusterDihedral::ReadDihedrals(std::string const& fname) {
CpptrajFile infile;
char buffer[256];
int a1, a2, a3, a4, bins;
double min;
if ( infile.OpenRead( fname ) ) return 1;
mprintf("\tReading dihedral information from %s\n", fname.c_str());
while (infile.Gets(buffer, 256)==0) {
// Expected line format: At#1 At#2 At#3 At#4 Bins Min
// ATOM NUMBERS SHOULD START FROM 1!
int nvals = sscanf(buffer, "%i %i %i %i %i %lf", &a1, &a2, &a3, &a4, &bins, &min);
if (nvals < 5) {
mprinterr("Error: Dihedral file %s: Expected at least 5 values, got %i\n",
fname.c_str(), nvals);
mprinterr("Error: Problem line: [%s]\n",buffer);
mprinterr("Error: Expected format: At#1 At#2 At#3 At#4 Bins [Min]\n");
return 1; // This should automatically close infile through destructor.
}
if (nvals < 6)
min = minimum_;
DCmasks_.push_back( DCmask(a1-1, a2-1, a3-1, a4-1, bins, min ) );
mprintf("\t\t(%i)-(%i)-(%i)-(%i) Bins=%i Min=%.3f\n",a1,a2,a3,a4,bins,min);
}
mprintf("\tRead %zu dihedrals.\n", DCmasks_.size());
infile.CloseFile();
return 0;
}
示例5: WriteNameToBuffer
// WriteNameToBuffer()
void DataIO_Std::WriteNameToBuffer(CpptrajFile& fileIn, std::string const& label,
int width, bool isLeftCol)
{
std::string temp_name = label;
// If left aligning, add '#' to name;
if (isLeftCol) {
if (temp_name[0]!='#') {
temp_name.insert(0,"#");
// Ensure that name will not be larger than column width.
if ((int)temp_name.size() > width)
temp_name.resize( width );
}
}
// Replace any spaces with underscores
for (std::string::iterator tc = temp_name.begin(); tc != temp_name.end(); ++tc)
if ( *tc == ' ' )
*tc = '_';
if (width >= (int)CpptrajFile::BUF_SIZE)
// Protect against CpptrajFile buffer overflow
fileIn.Write(temp_name.c_str(), temp_name.size());
else {
// Set up header format string
TextFormat::AlignType align;
if (isLeftCol)
align = TextFormat::LEFT;
else
align = TextFormat::RIGHT;
TextFormat header_format(TextFormat::STRING, width, align);
fileIn.Printf(header_format.fmt(), temp_name.c_str());
}
}
示例6: WriteGrid
int DataIO_OpenDx::WriteGrid(DataSet const& setIn, CpptrajFile& outfile) const {
DataSet_3D const& set = static_cast<DataSet_3D const&>( setIn );
Vec3 oxyz = set.Bin().GridOrigin();
if (gridWriteMode_ == BIN_CENTER)
// Origin needs to be shifted to center of bin located at 0,0,0
oxyz = set.Bin().Center(0,0,0);
// Print the OpenDX header
WriteDxHeader(outfile, set.NX(), set.NY(), set.NZ(), set.NX(), set.NY(), set.NZ(),
set.Bin().Ucell(), oxyz);
// Now print out the data.
size_t gridsize = set.Size();
if (gridsize == 1)
outfile.Printf("%g\n", set[0]);
else if (gridsize == 2)
outfile.Printf("%g %g\n", set[0], set[1]);
else if (gridsize > 2) {
// Data is already in row-major form (z-axis changes
// fastest), so no need to do any kind of data adjustment
for (size_t i = 0UL; i < gridsize - 2UL; i += 3UL)
outfile.Printf("%g %g %g\n", set[i], set[i+1], set[i+2]);
// Print out any points we may have missed
switch (gridsize % 3) {
case 2: outfile.Printf("%g %g\n", set[gridsize-2], set[gridsize-1]); break;
case 1: outfile.Printf("%g\n", set[gridsize-1]); break;
}
}
return 0;
}
示例7: ID_ParmFormat
bool Parm_CharmmPsf::ID_ParmFormat(CpptrajFile& fileIn) {
// Assumes already set up
if (fileIn.OpenFile()) return false;
std::string nextLine = fileIn.GetLine();
if (nextLine.empty()) return false;
bool isPSF = ( nextLine.compare(0, 3, "PSF") == 0 );
fileIn.CloseFile();
return isPSF;
}
示例8: WriteBuffer
void DataSet_GridDbl::WriteBuffer(CpptrajFile& outfile, SizeArray const& pIn) const {
size_t x = pIn[0];
size_t y = pIn[1];
size_t z = pIn[2];
if ( x >= grid_.NX() || y >= grid_.NY() || z >= grid_.NZ() )
outfile.Printf(format_.fmt(), 0.0);
else
outfile.Printf(format_.fmt(), grid_.element(x,y,z));
}
示例9: ID_DataFormat
bool DataIO_OpenDx::ID_DataFormat( CpptrajFile& infile ) {
bool isDX = false;
if (!infile.OpenFile()) {
std::string firstLine = infile.GetLine();
if (!firstLine.empty())
isDX = (firstLine.compare(0, 28, "object 1 class gridpositions") == 0);
infile.CloseFile();
}
return isDX;
}
示例10: ID_PDB
// PDBfile::ID_PDB()
bool PDBfile::ID_PDB(CpptrajFile& fileIn) {
// NOTE: ASSUME FILE SET UP FOR READ
if (fileIn.OpenFile()) return false;
std::string line1 = fileIn.GetLine();
std::string line2 = fileIn.GetLine();
fileIn.CloseFile();
if (!IsPDBkeyword( line1 )) return false;
if (!IsPDBkeyword( line2 )) return false;
return true;
}
示例11: WriteBuffer
// DataSet_Vector::WriteBuffer()
void DataSet_Vector::WriteBuffer(CpptrajFile &cbuffer, SizeArray const& pIn) const {
if (pIn[0] >= vectors_.size()) {
cbuffer.Printf(format_.fmt(), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // VXYZ OXYZ
} else {
Vec3 const& Vxyz = vectors_[pIn[0]];
Vec3 const& Oxyz = OXYZ(pIn[0]);
cbuffer.Printf(format_.fmt(), Vxyz[0], Vxyz[1], Vxyz[2],
Oxyz[0], Oxyz[1], Oxyz[2]);
}
}
示例12: calcIndex
void TriangleMatrix::Write2D( CpptrajFile& outfile, int xIn, int yIn ) {
size_t x = (size_t)xIn;
size_t y = (size_t)yIn;
if ( xIn==yIn || xIn < 0 || yIn < 0 || x >= nrows_ || y >= nrows_ )
outfile.Printf(data_format_, 0.0);
else {
size_t index = calcIndex(x, y);
outfile.Printf(data_format_, elements_[index]);
}
}
示例13: integerToString
// TODO: Accept const ArgList so arguments are not reset?
CpptrajFile* DataFileList::AddCpptrajFile(FileName const& nameIn,
std::string const& descrip,
CFtype typeIn, bool allowStdout)
{
// If no filename and stdout not allowed, no output desired.
if (nameIn.empty() && !allowStdout) return 0;
FileName name;
CpptrajFile* Current = 0;
int currentIdx = -1;
if (!nameIn.empty()) {
name = nameIn;
// Append ensemble number if set.
if (ensembleNum_ != -1)
name.Append( "." + integerToString(ensembleNum_) );
// Check if filename in use by DataFile.
DataFile* df = GetDataFile(name);
if (df != 0) {
mprinterr("Error: Text output file name '%s' already in use by data file '%s'.\n",
nameIn.full(), df->DataFilename().full());
return 0;
}
// Check if this filename already in use
currentIdx = GetCpptrajFileIdx( name );
if (currentIdx != -1) Current = cfList_[currentIdx];
}
// If no CpptrajFile associated with name, create new CpptrajFile
if (Current==0) {
switch (typeIn) {
case TEXT: Current = new CpptrajFile(); break;
case PDB: Current = (CpptrajFile*)(new PDBfile()); break;
}
Current->SetDebug(debug_);
// Set up file for writing.
//if (Current->SetupWrite( name, debug_ ))
if (Current->OpenWrite( name ))
{
mprinterr("Error: Setting up text output file %s\n", name.full());
delete Current;
return 0;
}
cfList_.push_back( Current );
cfData_.push_back( CFstruct(descrip, typeIn) );
} else {
// If Current type does not match typeIn do not allow.
if (typeIn != cfData_[currentIdx].Type()) {
mprinterr("Error: Cannot change type of text output for '%s'.\n", Current->Filename().full());
return 0;
}
Current->SetDebug(debug_);
// Update description
if (!descrip.empty())
cfData_[currentIdx].UpdateDescrip( descrip );
}
return Current;
}
示例14: MapCharsValid
// DataIO_CCP4::ID_DataFormat()
bool DataIO_CCP4::ID_DataFormat( CpptrajFile& infile ) {
bool isCCP4 = false;
if (!infile.OpenFile()) {
unsigned char MAP[4];
if (infile.Seek(52 * wSize) == 0) {
infile.Read( MAP, wSize );
isCCP4 = MapCharsValid( MAP );
}
infile.CloseFile();
}
return isCCP4;
}
示例15: mprinterr
// DataIO_CCP4::WriteData()
int DataIO_CCP4::WriteData(FileName const& fname, DataSetList const& setList)
{
// Open output file
CpptrajFile outfile;
if (outfile.OpenWrite(fname)) {
mprinterr("Error: Could not open CCP4 output file '%s'.\n", fname.full());
return 1;
}
// Warn about writing multiple sets
if (setList.size() > 1)
mprintf("Warning: %s: Writing multiple 3D sets in CCP4 format not supported.\n"
"Warning: Only writing first set.\n", fname.full());
return WriteSet3D( setList.begin(), outfile );
}