float ProteinEntropy::check_residue(Residue * residue, vector<Atom*> ligand_atoms) { vector<Atom*> res_atoms = residue->getAtoms(); Distances dist; dist.calculate(res_atoms,ligand_atoms,true); vector<vector<float> > dists = dist.getResult(); //is any ligand atom closer than threshold to any residue atom? bool close = false; for(unsigned int r=0; r<res_atoms.size(); r++) if (res_atoms[r]->element != "H") // disregard hydrogen if (find(backbone_atoms.begin(), backbone_atoms.end(), res_atoms[r]->name ) == backbone_atoms.end()) //disregard back bone atoms for(unsigned int l=0; l<ligand_atoms.size(); l++) if(dists[r][l] < threshold) close = true; //what is the entropy loss of this residue? float res = 0; if(close) { if(method == "count") res = 1; else if(method == "abagyan") res = abagyan[residue->residueType]; else { res = 1; printf("Warning: Invalid method '%s' in Protein Entropy\n",method.c_str()); } } return res; }
size_t index_distances_gcd(const NgramIndexes &indexes) { Distances distances; // Transform vector of indexes into the vector of distances for (size_t x=0; x < (indexes.size() - 1); x++) for (size_t y=x+1; y < indexes.size(); y++) distances.push_back(indexes[y] - indexes[x]); return distances_gcd(distances); }
size_t distances_gcd(const Distances &distances) { if (distances.size() == 0) return 0; if (distances.size() == 1) return distances[0]; size_t prev = binary_gcd(distances[0], distances[1]); for (size_t x = 2; x < distances.size(); x++) prev = binary_gcd(prev, distances[x]); return prev; }
int main () { std::cout << "Graph example program " << " - find shortest path in a directed graph." << std::endl; static const char pendleton[] = "Pendleton"; static const char pensacola[] = "Pensacola"; static const char peoria[] = "Peoria"; static const char phoenix[] = "Phoenix"; static const char pierre[] = "Pierre"; static const char pittsburgh[] = "Pittsburgh"; static const char princeton[] = "Princeton"; static const char pueblo[] = "Pueblo"; Cities cityMap; cityMap[pendleton][phoenix] = 4; cityMap[pendleton][pueblo] = 8; cityMap[pensacola][phoenix] = 5; cityMap[peoria][pittsburgh] = 5; cityMap[peoria][pueblo] = 3; cityMap[phoenix][peoria] = 4; cityMap[phoenix][pittsburgh] = 10; cityMap[phoenix][pueblo] = 3; cityMap[pierre][pendleton] = 2; cityMap[pittsburgh][pensacola] = 4; cityMap[princeton][pittsburgh] = 2; cityMap[pueblo][pierre] = 3; Distances dist; shortestDistance (cityMap, pierre, dist); Distances::iterator where; std::cout << "Find the shortest path from : " << pierre << '\n'; for (where = dist.begin (); where != dist.end (); ++where) std::cout << " Distance to: " << (*where).first << ":" << (*where).second << '\n'; std::cout << "End of graph example program" << '\n'; return 0; }
Neighbors find_neighbors_bruteforce_impl(const RandomAccessIterator& begin, const RandomAccessIterator& end, Callback callback, IndexType k) { timed_context context("Distance sorting based neighbors search"); typedef std::pair<RandomAccessIterator, ScalarType> DistanceRecord; typedef std::vector<DistanceRecord> Distances; Neighbors neighbors; neighbors.reserve(end-begin); for (RandomAccessIterator iter=begin; iter!=end; ++iter) { Distances distances; for (RandomAccessIterator around_iter=begin; around_iter!=end; ++around_iter) distances.push_back(std::make_pair(around_iter, callback.distance(iter,around_iter))); std::nth_element(distances.begin(),distances.begin()+k+1,distances.end(), distances_comparator<DistanceRecord>()); LocalNeighbors local_neighbors; local_neighbors.reserve(k); for (typename Distances::const_iterator neighbors_iter=distances.begin(); neighbors_iter!=distances.begin()+k+1; ++neighbors_iter) { if (neighbors_iter->first != iter) local_neighbors.push_back(neighbors_iter->first - begin); } neighbors.push_back(local_neighbors); } return neighbors; }
AllPairsSortedDag(InputHypergraph const& hg, Distances& distances, KeepFn keepFn = KeepFn(), ArcWtFn arcWtFn = ArcWtFn(), Weight const& oneWeight = Weight::one(), Weight const& zeroWeight = Weight::zero(), std::vector<StateId>* maxEnd = 0) : ArcWtFn(arcWtFn) , KeepFn(keepFn) , hg(hg) , distances(distances) , nStates((StateId)distances.getNumRows()) , oneWeight(oneWeight) , zeroWeight(zeroWeight) , maxEnd(maxEnd) { // if (!hg.isFsm() || !hg.storesOutArcs()) // SDL_THROW_LOG(Hypergraph, ConfigException, // "Current AllPairsSortedDag implementation needs " SDL_ALL_PAIRS_REQUIRES_SORTED_DAG); if (distances.getNumCols() != nStates) SDL_THROW_LOG(Hypergraph, IndexException, "AllPairsSortedDag stores distances into a square matrix. yours wasn't"); compute(); }
bool remove_outliers(void) { minc::MNK_Gauss_Polinomial pol_x(order); minc::MNK_Gauss_Polinomial pol_y(order); minc::MNK_Gauss_Polinomial pol_z(order); distances.resize(ideal.size()); tag_points::const_iterator j=measured.begin(); tag_points::const_iterator i=ideal.begin(); fittings::const_iterator bx=basis_x.begin(); int k=0; int max_k=-1; int cnt=0; max_distance=0.0; sd=0.0; basis_vector bas_x(order); for(;i!=ideal.end();i++, j++, k++) { if(cache_basis) { bas_x=*bx; } else { fun_x.generate_basis(bas_x,order,*i); } cnt++; tag_point moved; moved[0]=pol_x.fit(bas_x, coeff[0]); moved[1]=pol_y.fit(bas_x, coeff[1]); moved[2]=pol_z.fit(bas_x, coeff[2]); double d=(*j).SquaredEuclideanDistanceTo(moved); distances[k]=d; if(!mask[k]&&d>max_distance) { max_distance=d; max_k=k;} if(cache_basis) { bx++; } } max_distance=sqrt(max_distance); build_index(); sd=evaluate_distance(keep); if(verbose) cout<<sd<<":"<<max_distance<<"\t"; return true; }
bool remove_outliers(void) { /* minc::MNK_Gauss < tag_point, basis_functions_x> pol_x(order); minc::MNK_Gauss < tag_point, basis_functions_y> pol_y(order); minc::MNK_Gauss < tag_point, basis_functions_z> pol_z(order);*/ minc::MNK_Gauss_Polinomial pol_x(order); minc::MNK_Gauss_Polinomial pol_y(order); minc::MNK_Gauss_Polinomial pol_z(order); distances.resize(ideal.size()); tag_points::const_iterator j=measured.begin(); tag_points::const_iterator i=ideal.begin(); fittings::const_iterator bx=basis_x.begin(); fittings::const_iterator by=basis_y.begin(); fittings::const_iterator bz=basis_z.begin(); int k=0; int max_k=-1; int cnt=0; max_distance=0.0; sd=0.0; for(;i!=ideal.end();i++, j++, k++, bx++, by++, bz++) { //if(mask[k]) continue; cnt++; tag_point moved; moved[0]=pol_x.fit(*bx, coeff[0]); moved[1]=pol_y.fit(*by, coeff[1]); moved[2]=pol_z.fit(*bz, coeff[2]); double d=(*j).SquaredEuclideanDistanceTo(moved); distances[k]=d; //sd+=d; if(!mask[k]&&d>max_distance) { max_distance=d; max_k=k;} } max_distance=sqrt(max_distance); build_index(); sd=evaluate_distance(keep); if(verbose) cout<<sd<<":"<<max_distance<<"\t"; return true; }
static void shortestDistance (Cities &city_map, const std::string &start_city, Distances &dist) { // Process a priority queue of distances to nodes. std::priority_queue<DistancePair, std::vector<DistancePair, std::allocator<DistancePair> >, std::greater<DistancePair> > que; que.push (DistancePair (0, start_city)); while (! que.empty ()) { // Pull nearest city from queue. int distance = que.top ().first; std::string city = que.top ().second; que.pop (); // If we haven't seen it already, process it. if (0 == dist.count (city)) { // Then add it to shortest distance map. dist[city] = distance; // And put values into queue. const Distances& cities = city_map[city]; Distances::const_iterator start = cities.begin (); Distances::const_iterator stop = cities.end (); for (; start != stop; ++start) que.push (DistancePair (distance + (*start).second, (*start).first)); } } }