// This example shows how to access the vertex and edge set, // the properties that maps from each (atoms and bonds), // the adjacent atoms and the incident bonds. // Suppose that we are streaming in a smiles: // i.e. from the command line: "accessing_props < smile.smi" // --- std inclusions : #include // --- morpho inclusions : #include #include using namespace morpho::cdl; using namespace std; int main() { typedef molecule<> molecule_t; // let go through all stream : while( !std::cin.eof() ) { // get the molecule : nail_juice<> juice; get_juice_from_stream(std::cin, juice, 0, smiles_formatT()); // Now we construct the molecule: molecule_t mol(juice); // First access the vertex Set : // declare the iterators : molecule_t::vertex_iterator vi, vi_end; // get the iteretors of the molecule : tie(vi,vi_end)=mol.vertices(); while(vi,vi_end) { // print the vertex descriptor : cout << "==========================\n"; cout << " Vertex : " << *vi << endl; cout << "==========================\n"; // access the adjacent vertices : molecule_t::adjacency_iterator adjacent_i, adjacent_i_end; tie(adjacent_i,adjacent_i_end)=mol.adjacent_vertices(*vi); cout << "-- adjacent vertices --\n"; while(adjacent_i!=adjacent_i_end) { cout << " " << *adjacent_i << " "; ++adjacent_i; } cout << endl; // access the incident edges : molecule_t::out_edge_iterator inc_e_i, inc_e_i_end; tie(inc_e_i,inc_e_i_end)= mol.incident_edges(*vi); cout << "-- incident edges --\n"; while(inc_e_i!=inc_e_i_end) { cout << " source : " << mol.source(*inc_e_i) << ", target: " << mol.target(*inc_e_i) << endl; ++inc_e_i; } cout << endl; // Now get the properties that this vertex maps to : molecule_t::atom_type& atom = mol.get_atom(*vi); // Now print one of the members : cout << " Atomic property: atomic number : " << AtomProperty::get(atom) << endl; cout << endl; ++vi; } // Now let's access the edges : molecule_t::edge_iterator ei, ei_end; tie(ei,ei_end)=mol.edges(); while(ei,ei_end) { cout << "==========================\n"; cout << " Edge : (" << mol.source(*ei) << "," << mol.target(*ei) << ")" << endl; cout << "==========================\n"; // Get the bond that maps to this edge : molecule_t::bond_type& bond = mol.get_bond(*ei); // Print a property of the bond : cout << " is bond type : " << BondProperty::get(bond) << endl; ++ei; } cout << endl; // Now let's access the atom set : molecule_t::atom_iterator ai, ai_end; tie(ai,ai_end)=mol.atoms(); while(ai!=ai_end) { cout << "==========================\n"; cout << " Atom of symbol : " << AtomProperty::get(*ai) << endl; cout << "==========================\n"; // get the incident bonds : molecule_t::incident_bond_iterator ibi, ibi_end; tie(ibi,ibi_end)=mol.incident_bonds(ai); while(ibi!=ibi_end) { cout << " has incident bond of type : " << BondProperty::get(*ibi) << endl; ++ibi; } ++ai; } } // while() return 0; }