Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make OpenBabel read pymatgen format #2675

Open
correaa opened this issue Feb 27, 2024 · 0 comments
Open

Make OpenBabel read pymatgen format #2675

correaa opened this issue Feb 27, 2024 · 0 comments

Comments

@correaa
Copy link

correaa commented Feb 27, 2024

Is your feature request related to a problem? Please describe.

The new Materials Project API (https://next-gen.materialsproject.org/api) seems to only report structures in the pymatgen format only.

For example a REST request of this type "https://api.materialsproject.org/materials/summary/?material_ids=mp-66&_fields=structure",headers={"X-API-KEY": MP_API_KEY}" returns

{"data":[{"structure":{"@module":"pymatgen.core.structure","@class":"Structure","charge":0,"lattice":{"matrix":[[2.18050236,0.0,1.25891346],[0.72683412,2.05579703,1.25891346],[-0.0,0.0,2.51782692]],"pbc":[true,true,true],"a":2.5178271667719256,"b":2.5178269134954783,"c":2.51782692,"alpha":59.99999991454224,"beta":60.00000324214051,"gamma":59.9999988338285,"volume":11.286587893379405},"properties":{},"sites":[{"species":[{"element":"C","occu":1}],"abc":[0.875,0.875,0.875],"xyz":[2.54391942,1.7988224012499998,4.40619711],"properties":{"magmom":0.0},"label":"C"},{"species":[{"element":"C","occu":1}],"abc":[0.125,0.125,0.125],"xyz":[0.36341706,0.25697462875,0.62945673],"properties":{"magmom":0.0},"label":"C"}]}}],"meta":{"api_version":"0.63.2","time_stamp":"2024-02-27T03:47:28.940648","total_doc":1,"max_limit":1000,"default_fields":["material_id"]}}

Describe the solution you'd like

The following should generate a "molecule" from the string above (or a substring, after "structure:").

#include <iostream>

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

int main(int argc,char **argv)
{
  OBConversion obconversion;
  obconversion.SetInFormat("pymatgen");
  OBMol mol;

  bool notatend = obconversion.Read(&mol, ... string above ... );
}

Describe alternatives you've considered

The Python pymatgen library can read this format, and thanks to its own OpenBabel binding, it can covert to other file formats.

(see example here: https://matgenb.materialsvirtuallab.org/2013/01/01/Molecule.html)

However, this requires the use of Python and can't be done directly with C++.

Additional context

Here it is a full python request using the new Materials Project API to download the structure of the material labeled "mp-66":

>>> import os
>>> import requests

>>> MP_API_KEY="12qlK7tT5WoqaXXXJjKKuPBHZ1ByEG3"

>>> print(requests.get("https://api.materialsproject.org/materials/summary/?material_ids=mp-66&_fields=structure",he
aders={"X-API-KEY": MP_API_KEY}).text)
{"data":[{"structure":{"@module":"pymatgen.core.structure","@class":"Structure","charge":0,"lattice":{"matrix":[[2.18050236,0.0,1.25891346],[0.72683412,2.05579703,1.25891346],[-0.0,0.0,2.51782692]],"pbc":[true,true,true],"a":2.5178271667719256,"b":2.5178269134954783,"c":2.51782692,"alpha":59.99999991454224,"beta":60.00000324214051,"gamma":59.9999988338285,"volume":11.286587893379405},"properties":{},"sites":[{"species":[{"element":"C","occu":1}],"abc":[0.875,0.875,0.875],"xyz":[2.54391942,1.7988224012499998,4.40619711],"properties":{"magmom":0.0},"label":"C"},{"species":[{"element":"C","occu":1}],"abc":[0.125,0.125,0.125],"xyz":[0.36341706,0.25697462875,0.62945673],"properties":{"magmom":0.0},"label":"C"}]}}],"meta":{"api_version":"0.63.2","time_stamp":"2024-02-27T03:47:28.940648","total_doc":1,"max_limit":1000,"default_fields":["material_id"]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant