void BigInt::removeNumbersFromNumbers(const ContainerType& subtrahendNumbers, ContainerType& minuendNumbers) const { for (int currentRank = 0; currentRank < subtrahendNumbers.size(); currentRank++) { int minuendDigit = minuendNumbers[currentRank]; int subtrahendDigit = subtrahendNumbers[currentRank]; if (minuendDigit < subtrahendDigit) { minuendDigit += kBaseValue; int floatRank = currentRank + 1; do { if (minuendNumbers[floatRank]) { minuendNumbers[floatRank]--; break; } else { minuendNumbers[floatRank] = kBaseValue - 1; } floatRank++; } while (floatRank < minuendNumbers.size()); if (floatRank == minuendNumbers.size() - 1 && 0 == minuendNumbers[floatRank]) { minuendNumbers.pop_back(); } } minuendNumbers[currentRank] = minuendDigit - subtrahendDigit; } }
void processResData_ByRotID( const std::string& resName, ContainerType& data, RotamerLibrary& _RotLib ) { // Sort the data to increase efficiency below std::stable_sort( data.begin(), data.end(), sortPsi); std::stable_sort( data.begin(), data.end(), sortPhi); std::stable_sort( data.begin(), data.end(), sortRotID); ContainerType subdata; while( true ) { if( data.size() > 0 && (subdata.size() == 0 || subdata[0].rotID.compare( data.back().rotID,0,4,0 )) ) { subdata.push_back( data.back() ); data.erase(data.end()-1); // rob the end, not the start (ContainerType<> perfomance reasons!) } else { ASSERT( data.size() == (36*36), ParseException, "Assumption error!"); ASSERT( data[0].phi == -180.0 && data[0].psi == -180.0, ParseException, "Wrong phi/psi"); for( size_t j = 1; j < data.size(); j++ ) { ASSERT( data[j].phi == (-180.0+(j/36)*10) && data[j].psi == (-180.0+(j%36)*10), ParseException, "Wrong phi/psi"); } processData( resName, subdata, _RotLib, 40.0 ); // 40 degree tollerance delta from data[0] subdata.clear(); if( data.size() == 0 ) { return; } } } }
void Animation_writeChannel(const std::string &channelString, ChannelType *pChannel, Output &fw) { fw.indent() << channelString.c_str() << " {" << std::endl; fw.moveIn(); fw.indent() << "name \"" << pChannel->getName() << "\"" << std::endl; fw.indent() << "target \"" << pChannel->getTargetName() << "\"" << std::endl; // fw.indent() << "weight " << pChannel->getWeight() << std::endl; ContainerType *kfc = pChannel->getSamplerTyped()->getKeyframeContainerTyped(); if (kfc) { fw.indent() << "Keyframes " << kfc->size() << " {" << std::endl; fw.moveIn(); for (unsigned int k = 0; k < kfc->size(); k++) { fw.indent() << "key " << (*kfc)[k].getTime() << " " << (*kfc)[k].getValue() << std::endl; } fw.moveOut(); fw.indent() << "}" << std::endl; fw.moveOut(); fw.indent() << "}" << std::endl; } }
void processData( const std::string& resName, ContainerType& data, RotamerLibrary& _RotLib, double tollerance ) { std::vector<double> averagedChis = data[0].chis; if( averagedChis[0] < 0.0 ) averagedChis[0] += 360.0; for( size_t j = 1; j < data.size(); j++ ) { while( data[0].chis.size() > data[j].chis.size() ) { // Chi count disagreement: Unfortunatly some, due to being 0.0 are not read in. Just pad it... data[j].chis.push_back(0.0); } for( size_t k = 0; k < data[0].chis.size(); k++ ) { double d1 = data[0].chis[k]; double d2 = data[j].chis[k]; double delta = d1 - d2; if( delta < 0.0 ) delta = -delta; if( delta > 180.0 ) delta = 360.0 - delta; if( delta != 0.0 ) { // We have to allow a +-tollerance wobble, as some are *a little* different depending on the exact phi/psi! ASSERT( tollerance > delta, ParseException, "Internal data correlation mismatch (Chi)"); } if( d2 < 0.0 ) d2 += 360.0; // assure all are +ve averagedChis[k] += d2; } } for( size_t i = 0; i < averagedChis.size(); i++ ) { averagedChis[i] = averagedChis[i] / (double)data.size(); averagedChis[i] = torsionalRangeDegrees( averagedChis[i] ); averagedChis[i] = Maths::DegToRad(averagedChis[i]); } ProbabilityByPhiPsiMap map( 36 ); // 10 degree for( size_t j = 0; j < data.size(); j++ ) { map.assignFrom( Maths::DegToRad(data[j].phi), Maths::DegToRad(data[j].psi), Maths::DegToRad(data[j].probability) ); } _RotLib.addRotamer( resName, averagedChis, map ); return; }
void BigInt::addNumbers(const ContainerType& numbers) { for (int currentRank = 0; currentRank < numbers.size(); currentRank++) { if (currentRank < _numbers.size()) { int firstDigit = _numbers[currentRank]; int secondDigit = numbers[currentRank]; _numbers[currentRank] = (firstDigit + secondDigit) % kBaseValue; int floatRank = currentRank + 1; int valueInFloatRank = firstDigit + secondDigit; while (valueInFloatRank / kBaseValue > 0) { if (floatRank < _numbers.size()) { valueInFloatRank = _numbers[floatRank] + 1; _numbers[floatRank] = valueInFloatRank % kBaseValue; floatRank++; } else { valueInFloatRank = 1; _numbers.push_back(valueInFloatRank); } } } else { _numbers.push_back(numbers[currentRank]); } } }
bool BigInt::isBiggerThenNumbers(const ContainerType& numbers) const { bool result = _numbers.size() > numbers.size(); if (_numbers.size() == numbers.size()) { for (int index = _numbers.size()-1; index >= 0; index--) { if (_numbers[index] != numbers[index]) { result = _numbers[index] > numbers[index]; break; } } } return result; }
void BigInt::makeMultiplicationWithNumbersAndDigit(const ContainerType& numbers, RankType digit, ContainerType& result) { result.clear(); result.push_back(0); if (0 == digit) { return; } else if (1 == digit) { result = numbers; } else { for (int rankIndex = 0; rankIndex < numbers.size(); rankIndex++) { RankType multiplication = numbers[rankIndex] * digit; if (result.size() == rankIndex) { result.push_back(multiplication % kBaseValue); } else { result[rankIndex] += multiplication % kBaseValue; } if (result[rankIndex] / kBaseValue) { result[rankIndex] %= kBaseValue; result.push_back(1); } if (multiplication / kBaseValue) { if (result.size() == rankIndex + 1) { result.push_back(multiplication / kBaseValue); } else { result[rankIndex + 1] += multiplication / kBaseValue; } } } } }
ContainerType<ReturnValueType> mapContainer(ContainerType<ArgumentType> input, std::function<ReturnValueType(ArgumentType)> f) { ContainerType<ReturnValueType> mapped; for(int i=0;i<input.size();i++){ mapped.append(f(input[i])); } return mapped; }
void processResData_ByChis( const std::string& resName, ContainerType& data, RotamerLibrary& _RotLib ) { const double tollerance = 12.0; // Ensure full chi arrays size_t largestSoFar = data[0].chis.size(); for( size_t i = 1; i < data.size(); i++ ) { if( data[i].chis.size() > largestSoFar ) { largestSoFar = data[i].chis.size(); i = 0; // reset } while( data[i].chis.size() < largestSoFar ) { data[i].chis.push_back(0.0); } } size_t done = 0; std::vector<bool> taken(data.size()); while( data.size() > done ) { ContainerType subdata; bool on = false; for( int i = (int)data.size()-1; i >= 0; i-- ) { if( taken[i] != true && (!on || equalChis( subdata[0], data[i], tollerance ) ) ) { subdata.push_back( data[i] ); taken[i] = true; on = true; done++; } } processData( resName, subdata, _RotLib, tollerance ); subdata.clear(); } data.clear(); }
bool BigInt::isEqualToNumbers(const ContainerType& numbers) const { bool result = _numbers.size() == numbers.size(); if (result) { for (int index = 0; index < _numbers.size(); index++) { if (_numbers[index] != numbers[index]) { result = false; break; } } } return result; }
int lowess(const ContainerType& x, const ContainerType& y, double frac, // parameter f int nsteps, ValueType delta, ContainerType& ys, ContainerType& resid_weights, // vector rw ContainerType& weights // vector res ) { bool fit_ok; size_t ns, n(x.size()); if (n < 2) { ys[0] = y[0]; return 1; } // how many points around estimation point should be used for regression: // at least two, at most n points size_t tmp = (size_t)(frac * (double)n); ns = std::max(std::min(tmp, n), (size_t)2); // robustness iterations for (int iter = 1; iter <= nsteps + 1; iter++) { // start of array in C++ at 0 / in FORTRAN at 1 // last: index of prev estimated point // i: index of current point size_t i(0), last(-1), nleft(0), nright(ns -1); // Fit all data points y[i] until the end of the array do { // Identify the neighborhood around the current x[i] // -> get the nearest ns points update_neighborhood(x, n, i, nleft, nright); // Calculate weights and apply fit (original lowest function) fit_ok = lowest(x, y, n, x[i], ys[i], nleft, nright, weights, (iter > 1), resid_weights); // if something went wrong during the fit, use y[i] as the // fitted value at x[i] if (!fit_ok) ys[i] = y[i]; // If we skipped some points (because of how delta was set), go back // and fit them by linear interpolation. if (last < i - 1) { interpolate_skipped_fits(x, i, last, ys); } // Update the last fit counter to indicate we've now fit this point. // Find the next i for which we'll run a regression. update_indices(x, n, delta, i, last, ys); } while (last < n - 1); // compute current residuals for (i = 0; i < n; i++) { weights[i] = y[i] - ys[i]; } // compute robustness weights except last time if (iter > nsteps) break; calculate_residual_weights(n, weights, resid_weights); } return 0; }
void truncate_entries() { while(entries.size() > entries_max) { entries.pop_back(); } }
explicit array_view(ContainerType & container) noexcept : m_pointer{ container.data() } , m_size_in_items{ container.size() } { }
ordered_adaptor_iterator(const ContainerType * container, ValueCompare const & cmp): container(container), current_index(container->size()), unvisited_nodes(compare_by_heap_value(container, ValueCompare())) {}
void DataTest::testColumnList() { typedef std::list<int> ContainerType; typedef Column<ContainerType> ColumnType; MetaColumn mc(0, "mc", MetaColumn::FDT_DOUBLE, 2, 3, true); assert (mc.name() == "mc"); assert (mc.position() == 0); assert (mc.length() == 2); assert (mc.precision() == 3); assert (mc.type() == MetaColumn::FDT_DOUBLE); assert (mc.isNullable()); ContainerType* pData = new ContainerType; pData->push_back(1); pData->push_back(2); pData->push_back(3); pData->push_back(4); pData->push_back(5); ColumnType c(mc, pData); assert (c.rowCount() == 5); assert (c[0] == 1); assert (c[1] == 2); assert (c[2] == 3); assert (c[3] == 4); assert (c[4] == 5); assert (c.name() == "mc"); assert (c.position() == 0); assert (c.length() == 2); assert (c.precision() == 3); assert (c.type() == MetaColumn::FDT_DOUBLE); try { int i; i = c[100]; // to silence gcc fail ("must fail"); } catch (RangeException&) { } ColumnType c1 = c; assert (c1.rowCount() == 5); assert (c1[0] == 1); assert (c1[1] == 2); assert (c1[2] == 3); assert (c1[3] == 4); assert (c1[4] == 5); ColumnType c2(c1); assert (c2.rowCount() == 5); assert (c2[0] == 1); assert (c2[1] == 2); assert (c2[2] == 3); assert (c2[3] == 4); assert (c2[4] == 5); ContainerType vi; vi.assign(c.begin(), c.end()); assert (vi.size() == 5); ContainerType::const_iterator it = vi.begin(); ContainerType::const_iterator end = vi.end(); for (int i = 1; it != end; ++it, ++i) assert (*it == i); c.reset(); assert (c.rowCount() == 0); assert (c1.rowCount() == 0); assert (c2.rowCount() == 0); ContainerType* pV1 = new ContainerType; pV1->push_back(1); pV1->push_back(2); pV1->push_back(3); pV1->push_back(4); pV1->push_back(5); ContainerType* pV2 = new ContainerType; pV2->push_back(5); pV2->push_back(4); pV2->push_back(3); pV2->push_back(2); pV2->push_back(1); Column<ContainerType> c3(mc, pV1); Column<ContainerType> c4(mc, pV2); Poco::Data::swap(c3, c4); assert (c3[0] == 5); assert (c3[1] == 4); assert (c3[2] == 3); assert (c3[3] == 2); assert (c3[4] == 1); assert (c4[0] == 1); assert (c4[1] == 2); assert (c4[2] == 3); assert (c4[3] == 4); assert (c4[4] == 5); std::swap(c3, c4); assert (c3[0] == 1); assert (c3[1] == 2); assert (c3[2] == 3); assert (c3[3] == 4); assert (c3[4] == 5); assert (c4[0] == 5); assert (c4[1] == 4); assert (c4[2] == 3); assert (c4[3] == 2); assert (c4[4] == 1); }
void RotLibConvert_Dunbrack_BBDep::readLib( const std::string& _LibraryFilename, RotamerLibrary& _RotLib ) { StringBuilder sb; std::ifstream* p_torsionFile; try { if( _RotLib.isFinalised() ) throw ProcedureException("readLib() is not allowed, the rotamer library has been finalised, no further import can occur"); // Mappings for things like HIS -> HIE HID HIP _RotLib.addIonisationAliasWorkingDefaults(); // Make sure Alanine and Glycine are defined non-rotamer residues (the library itself ignores them) _RotLib.addAsBlankRotamer("ALA"); _RotLib.addAsBlankRotamer("GLY"); p_torsionFile = new std::ifstream(_LibraryFilename.c_str(), std::ifstream::in); std::ifstream& torsionFile = *p_torsionFile; if( !torsionFile.is_open() ) throw(IOException( "Dunbrack BB-independent torsional definition file not found: '" + _LibraryFilename + "'!" )); ParseData pd; ContainerType data; StringBuilder prevResName(3); StringBuilder currResName(4); StringBuilder cacheLine; while( true ) { if( cacheLine.size() > 0 ) { sb.setTo(cacheLine); cacheLine.clear(); } else if( !(sb << torsionFile) ) { break; } sb.Trim(); if( sb.size() == 0 ) continue; // blank line currResName.setTo(sb,0,3); if( prevResName.size() == 0 ) { prevResName.setTo( currResName ); ASSERT( pd.parse( sb ), ParseException, "Malformed line"); data.push_back( pd ); } else if( prevResName.compare( currResName, 0, 3, 0 ) ) { // Woooo - we found one :-D ASSERT( pd.parse( sb ), ParseException, "Malformed line"); data.push_back( pd ); } else { if( data.size() > 0 ) { processResData( prevResName.toString(), data, _RotLib, switchImportMode ); ASSERT( data.size() == 0, CodeException, "CodeFail"); } prevResName.setTo( currResName ); cacheLine.setTo( sb ); // we havent actually processed the current line! Store it. } } if( data.size() > 0 ) { processResData( prevResName.toString(), data, _RotLib, switchImportMode ); ASSERT( data.size() == 0, CodeException, "CodeFail"); } // Ensure file-handle cleanup p_torsionFile->close(); delete p_torsionFile; } catch( ExceptionBase ex ) { // Ensure file-handle cleanup p_torsionFile->close(); delete p_torsionFile; throw ex; } }
size_type size() const { return _buffer.size(); }