Hello,

I have been working in a format for openbabel. I can compile, install and
run the plugin. The format is
http://www.lpmd.cl/index.php/documentation/the-lpmd-format

My problem is that the plugin run fine, for one molecule, but for multiple
molecules, this doesn't work fine ... or at least I think so. I build my
plugins based on the xyzformat.cpp and the exampleformat.cpp.

For example I have a xyz file with two configs :

$ cat test.xyz
2
AA
Si 0 0 0
Si 5 0 0
2
BB
Si 0 0 1
Si 0 5 0

So I can convert the xyz to a pdb using :

$ obabel -ixyz test.xyz -opdb -Otest.pdb
2 molecules converted

But when I run with my format (example attached here) :

$ obabel -ilpmd multiconfig.lpmd -opdb -Omulticonfig.pdb
1 molecule converted
jperaltac@baco:~/Projects/lpmd/06/lpmd/examples/lpmd-format$

However the mentioned above, I can do this :

$obabel multiconfig.lpmd -Otest*.pdb
5 molecules converted
5 files output. The first is test1.pdb

So, I don't understand why I can't convert directly in one single file. The
ReadMolecule method is :

bool LpmdFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
 OBMol* pmol = pOb->CastAndClear<OBMol>();
 if(pmol==NULL)   return false;
 N=0;
 std::istream &ifs = *pConv->GetInStream();
 OBMol &mol = *pmol;

 if(!ifs) return false;
 //read the header only once.
 if(file_line==0)
 {
  if ( ! ReadHeader( ifs, mol ) ) return false;
 }
 std::stringstream ErrMsg;
 //Read the cell vectors.
 double ax=0.0e0,ay=0.0e0,az=0.0e0;
 double bx=0.0e0,by=0.0e0,bz=0.0e0;
 double cx=0.0e0,cy=0.0e0,cz=0.0e0;
 //Reading the number of atoms.
 ifs.getline(buffer,BUFF_SIZE);
 file_line++;
 tokenize(tokens, buffer, " ");
 if(tokens.size()!=1)
 {
  obErrorLog.ThrowError(__FUNCTION__,"The number of atoms line was not
correctly readed",obError);
 }
 from_string<int>(N, tokens.at(0), std::dec);

 tokens.clear();
 ifs.getline(buffer,BUFF_SIZE);
 file_line++;
 tokenize(tokens, buffer, " ");
 line=buffer;
 from_string<double>(ax, tokens.at(0), std::dec);
 from_string<double>(ay, tokens.at(1), std::dec);
 from_string<double>(az, tokens.at(2), std::dec);
 from_string<double>(bx, tokens.at(3), std::dec);
 from_string<double>(by, tokens.at(4), std::dec);
 from_string<double>(bz, tokens.at(5), std::dec);
 from_string<double>(cx, tokens.at(6), std::dec);
 from_string<double>(cy, tokens.at(7), std::dec);
 from_string<double>(cz, tokens.at(8), std::dec);

 vector3 vx = vector3(ax,ay,az);
 vector3 vy = vector3(bx,by,bz);
 vector3 vz = vector3(cx,cy,cz);
 // Add the Unit Cell to the molecule
 OBUnitCell * unitcell = new OBUnitCell();
 unitcell->SetData( vx, vy, vz );

 mol.BeginModify();
 mol.SetData( unitcell );
 /** Parse the input stream and use the OpenBabel API to populate the OBMol
**/

 for(int i=0 ; i<N ; ++i)
 {
  OBAtom *atom  = mol.NewAtom();
  ifs.getline(buffer,BUFF_SIZE);
  file_line++;
  line = buffer;
  tokenize(tokens, buffer, " ");
  if(int(headers.size()-1)!=tokens.size())
  {
   ErrMsg << "There was a problem reading an atomic configuration,  "
          << "the line # " << file_line << " doesn't have the number "
  << "of columns indicated in the HDR (second line). ";
   obErrorLog.ThrowError(__FUNCTION__, ErrMsg.str(), obError);
  }
  double X=0.0,Y=0.0,Z=0.0;
  std::string symbol = "Xx";
  for(int i=1 ; i < headers.size() ; ++i) //the first element is HDR
  {
   //Basic information position and atomic symbol.
   if(headers.at(i).compare("X")==0) from_string<double>(X, tokens.at(i-1),
std::dec);
   if(headers.at(i).compare("Y")==0) from_string<double>(Y, tokens.at(i-1),
std::dec);
   if(headers.at(i).compare("Z")==0) from_string<double>(Z, tokens.at(i-1),
std::dec);
   if(headers.at(i).compare("SYM")==0) symbol = tokens.at(i-1);
  }
  atom->SetVector(X,Y,Z);
  int atomicNum = etab.GetAtomicNum(symbol.c_str());
  atom->SetAtomicNum(atomicNum);
 }

 if (!pConv->IsOption("b",OBConversion::INOPTIONS))
    mol.ConnectTheDots();
 if (!pConv->IsOption("s",OBConversion::INOPTIONS) &&
!pConv->IsOption("b",OBConversion::INOPTIONS))
    mol.PerceiveBondOrders();

 mol.EndModify();
 return true;
}


What could be the problem?

On the other hand, when I feel confident with the plugin, I have to submit
using subversion, or I'll need to e-mail this to someone?

Any help is welcome.

Best Regards
Joaquin Peralta

-- 
JoaquĆ­n Peralta C.
Postdoctoral Research Associate
Materials Science and Engineering
Iowa State University
3326 Hoover Hall
Ames, IA 50011
Phone Lab: 515-294-9547
http://www.lpmd.cl/jperalta
http://www.gnm.cl
-----------------------------------------------
*In a world without frontiers,
who needs Gates and Windows?.*

Attachment: multiconfig.lpmd
Description: Binary data

------------------------------------------------------------------------------
Got visibility?
Most devs has no idea what their production app looks like.
Find out how fast your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219671;13503038;y?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________
OpenBabel-discuss mailing list
OpenBabel-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss

Reply via email to