mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-04 21:54:27 +08:00
* Start of GettingStartedInC++ documentation. * Changed GettingStartedInC++ from rst to markdown format. Added some more text. * Added Working with Molecules to GettingStartedInC++ * Expanded on behaviour of Kekulize wrt clearing aromatic flags on atoms and bonds. * Added section Modifying Molecules. * More plodding progress. * A load more documentation. * Undid change to global CMakeLists.txt * Minor editing of docs. * Changed examples so they use RDBASE to find test data rather than relative path. * Fixed use of -std=c++ in CMakeLists.txt. Extra waffling about memory. * Modifications to examples and documentation as requested. * Couple of minor changes. * Change to example11.cpp and associated text in docs.
57 lines
1.9 KiB
C++
57 lines
1.9 KiB
C++
//
|
|
// Writing molecules - example4.cpp
|
|
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <GraphMol/SmilesParse/SmilesParse.h>
|
|
#include <GraphMol/SmilesParse/SmilesWrite.h>
|
|
#include <GraphMol/FileParsers/FileParsers.h>
|
|
#include <GraphMol/GraphMol.h>
|
|
#include <GraphMol/MolOps.h>
|
|
#include <GraphMol/Depictor/RDDepictor.h>
|
|
#include <GraphMol/DistGeomHelpers/Embedder.h>
|
|
#include <GraphMol/ForceFieldHelpers/MMFF/MMFF.h>
|
|
|
|
int main( int argc , char **argv ) {
|
|
|
|
RDKit::ROMOL_SPTR mol1( RDKit::SmilesToMol( "C1CCC1" ) );
|
|
std::cout << RDKit::MolToMolBlock( *mol1 ) << std::endl;
|
|
|
|
mol1->setProp( "_Name" , "cyclobutane" );
|
|
std::cout << RDKit::MolToMolBlock( *mol1 ) << std::endl;
|
|
|
|
RDDepict::compute2DCoords( *mol1 );
|
|
std::cout << RDKit::MolToMolBlock( *mol1 ) << std::endl;
|
|
|
|
RDKit::ROMOL_SPTR mol2( RDKit::SmilesToMol( "C1CCC1" ) );
|
|
mol2->setProp( "_Name" , "cyclobutane3D" );
|
|
RDKit::DGeomHelpers::EmbedMolecule( *mol2 );
|
|
RDKit::MMFF::MMFFOptimizeMolecule( *mol2 , 1000 , "MMFF94s" );
|
|
std::cout << RDKit::MolToMolBlock( *mol2 ) << std::endl;
|
|
|
|
RDKit::ROMOL_SPTR mol3( RDKit::MolOps::addHs( *mol2 ) );
|
|
RDKit::MMFF::MMFFOptimizeMolecule( *mol3 , 1000 , "MMFF94s" );
|
|
std::cout << RDKit::MolToMolBlock( *mol3 ) << std::endl;
|
|
|
|
RDKit::RWMOL_SPTR mol4( new RDKit::RWMol( *mol3 ) );
|
|
RDKit::MolOps::addHs( *mol4 );
|
|
|
|
RDKit::ROMOL_SPTR mol3sp( RDKit::MolOps::addHs( *mol2 ) );
|
|
mol3sp->setProp( "_Name" , "cyclobutaneSP" );
|
|
RDKit::MMFF::MMFFOptimizeMolecule( *mol3sp , 1000 , "MMFF94s" );
|
|
std::cout << RDKit::MolToMolBlock( *mol3sp ) << std::endl;
|
|
|
|
|
|
RDKit::ROMOL_SPTR mol5( RDKit::MolOps::removeHs( *mol3 ) );
|
|
RDKit::MolOps::removeHs( *mol4 );
|
|
|
|
std::string file_root = getenv( "RDBASE" );
|
|
file_root += "/Docs/Book";
|
|
|
|
std::string mol_file = file_root + "/data/foo.mol";
|
|
std::ofstream ofs( mol_file.c_str() );
|
|
ofs << RDKit::MolToMolBlock( *mol5 );
|
|
|
|
}
|