I have run make install, after that in include folder there was only
babelconfig.h, if other headers should have been appeared there? Everything
else seems to be quite well.

Here is my main.cpp, everything worked well until trying to find ForceField
by OBForceField* pFF = OBForceField::FindForceField(mmff94);

#include <iostream>
#include <cstdlib>
#include <openbabel/shared_ptr.h>

#include <openbabel/mol.h>
#include <openbabel/obconversion.h>

#include <openbabel/forcefield.h>

using namespace OpenBabel;

int main(int argc,char **argv)
{
        shared_ptr<OBMol> mol(new OBMol);
        
        const std::string input_filename = argv[1];
        OBConversion conv;
        OBFormat *format = conv.FormatFromExt(input_filename.c_str());
        if (!format || !conv.SetInFormat(format)) {
                std::cout << "Could not find input format for file " << 
input_filename
<< std::endl;
                return 0;
        }
        std::ifstream ifs(input_filename.c_str());

        if (!ifs) {
                std::cout << "Could not open " << input_filename << " for 
reading." <<
std::endl;
                return 0;
        }

        if (!conv.Read(mol.get(), &ifs)) {
                std::cout << "Could not read molecule from file " << 
input_filename <<
std::endl;
                return 0;
        }
        
        const std::string output_filename = argv[2];
        OBFormat *out_format = conv.FormatFromExt(output_filename.c_str());
        
        if (!out_format || !conv.SetOutFormat(out_format)) {
                std::cout << "Could not find output format for file " << 
output_filename
<< std::endl;
                return 0;
        }
        
        
        std::ofstream ofs(output_filename.c_str());
        if (!ofs) {
                std::cout << "Could not open " << output_filename << "for 
writing." <<
std::endl;
                return 0;
        }
        const std::string output2_filename = argv[3];
        OBFormat *out2_format = conv.FormatFromExt(output2_filename.c_str());

        if (!out2_format || !conv.SetOutFormat(out2_format)) {
                std::cout << "Could not find output format for file " << 
output2_filename
<< std::endl;
                return 0;
        }

        std::ofstream ofs2(output2_filename.c_str());
        if (!ofs2) {
                std::cout << "Could not open " << output2_filename << " for 
writing." <<
std::endl;
                return 0;
        }

        OBMol mol2(*mol.get());
        mol2.SetTorsion(mol2.GetAtom(1), mol2.GetAtom(2), mol2.GetAtom(4),
mol2.GetAtom(5), M_PI);

        if (!conv.Write(&mol2, &ofs)) {
                std::cout << "Could not write molecule to file." << std::endl;
                return 0;
        }

        if (!conv.Write(&mol2, &ofs2)) {
                std::cout << "Could not write molecule to file." << std::endl;
                return 0;
        }

        OBPlugin::List("forcefields");

        const std::string uff = "UFF";
        OBForceField* pFF = OBForceField::FindForceField(uff);

        if (pFF == NULL) {
                std::cout << "Invalid pointer" << std::endl;
                return 0;
        }

        if (!pFF->Setup(mol2)) {
            std::cout << "Could not setup forcefield" << std::endl;
        }

        OBFFConstraints constraints;
        FOR_ATOMS_OF_MOL(a, mol2) {
                if (!a->IsHydrogen()) {
                        constraints.AddAtomConstraint(a->GetIdx());
                }
        }

        pFF->SetConstraints(constraints);
        pFF->SteepestDescent(1000);
        ofs2.close();
    const std::string output3_filename = argv[4];
        OBFormat *out3_format = conv.FormatFromExt(output3_filename.c_str());

        if (!out3_format || !conv.SetOutFormat(out3_format)) {
                std::cout << "Could not find output format for file " << 
output3_filename
<< std::endl;
                return 0;
        }

        ofs2.open(output3_filename.c_str());
        if (!ofs2) {
                std::cout << "Could not open " << output3_filename << " for 
writing." <<
std::endl;
                return 0;
        }

        if (!conv.Write(&mol2, &ofs2)) {
                std::cout << "Could not write molecule to file." << std::endl;
                return 0;
        } 
        
        return 0;
}

And here is the makefile

CC = g++

CFLAGS = -c -I /home/adel/sources/openbabel-new/build/include

LDFLAGS = -lopenbabel -L /home/adel/sources/openbabel-new/build/lib

all: example

example: example.o
        $(CC) $(LDFLAGS) example.o -o example

example.o: example.cpp
        $(CC) $(CFLAGS) $(LDFLAGS) example.cpp

clean:
        rm -rf example.o example

I have set environment variable
BABEL_DATADIR to the folder with data by command export, isn't this enough?




--
View this message in context: 
http://forums.openbabel.org/Invalid-pointer-Force-Field-previous-solutions-don-t-help-tp4656645p4656650.html
Sent from the General discussion mailing list archive at Nabble.com.

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to