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

crystal(.cif,.pdb.etc)covert to print 3d format .stl ,open babel cannot cov #2679

Open
SteelDominic opened this issue Mar 8, 2024 · 8 comments

Comments

@SteelDominic
Copy link

it's clear,when you try to convert a molecular to 3D format ,open babel cannot give correct response.
stl
cif

Copy link

welcome bot commented Mar 8, 2024

Thanks for opening your first issue here! Be sure to follow the issue template!

@nbehrnd
Copy link
Contributor

nbehrnd commented Mar 8, 2024

@SteelDominic In its current form, it is not clear what you want to achieve with an export to .stl except (now guessing:) perhaps some sort of 3D print with some properties. But which one?

There are instances a molecular surface around an individual molecule is good enough, e.g. for packing models and the .stl format provides enough information. There are instances where an additional information is provided, encoded in color, on an isosurface, e.g.

b818330a-f12

(Mark A. Spackman and Dylan Jayatilaka, CrystEngComm, 2009, 11, 19-32)

for which an .obj file (for the surface) and .mtl file (for the color) is an acceptable format for 3D printing. (Though .obj files can contain color information, and .vrml files are an other acceptable data container format.)


Else, do you want to generate a 3D print with either a single molecule on a plinth?

single_mol

Or a crystal packing of a unit cell?

cell

concretization.zip

@SteelDominic
Copy link
Author

@SteelDominic In its current form, it is not clear what you want to achieve with an export to .stl except (now guessing:) perhaps some sort of 3D print with some properties. But which one?

There are instances a molecular surface around an individual molecule is good enough, e.g. for packing models and the .stl format provides enough information. There are instances where an additional information is provided, encoded in color, on an isosurface, e.g.

b818330a-f12 b818330a-f12

(Mark A. Spackman and Dylan Jayatilaka, CrystEngComm, 2009, 11, 19-32)

for which an .obj file (for the surface) and .mtl file (for the color) is an acceptable format for 3D printing. (Though .obj files can contain color information, and .vrml files are an other acceptable data container format.)

Else, do you want to generate a 3D print with either a single molecule on a plinth?

single_mol

Or a crystal packing of a unit cell?

cell

concretization.zip

THANKs for your reply!
My target is tring to convert molecule format(like .cif) to 3Dmesh format(.obj).But I check openbabel usage document,it seems openbabel doesn't support this transformation.So i try to use .stl format as a bridge to achieve my target.I try to use openbabel convert .cif to .stl,and then i can use trimesh to convert .stl to .obj.
i use the following command to convert molecule format to .stl.
obabel -icif xxx.cif to -O xxx.stl
i also try to use other molecule format (e.g. .pdb .mol2),they all cannot give me desired response.
when i use vesta,I can export my desired response data.the following are instances.
AABHTZ_vesta
AACMHX10_vesta
when i use openbabel,i can only get these response
AACMHX10_openbabel
ACETAC07_openbabel
Because i want to transform a lot of data,so i cannot use vesta to hand all the data.
My question is I want to use openbabel to convert a lot data to .stl format and get my desired response.

@fredrikw
Copy link
Contributor

I'm not 100% sure of your desired outcome, but if you choose to go via the .pov-format instead of stl you have the possibility to have the output as ball-and-stick instead of space-filling (you choose the ball-and-stick type with -xm BAS but it is also the default). I believe there are plenty of converters to go from .pov to .obj.

@nbehrnd
Copy link
Contributor

nbehrnd commented Mar 11, 2024

@SteelDominic I think OpenBabel is not the right tool for this. Before trying to convert batches of molecules for 3D print (similar to NIH's 3d print exchange, or CCDC's printing contests), one better would define if one wants a ball-and-stick model, or one of van der Waals-spheres; if the model is about individual molecules, or a packing; if the object should be free and isolated, or on a plinth; if the result is good enough in as a structure (where a .stl is enough), or requires colour (.obj, .vmrl).

Note, Scalfani et al. address a similar a task with Jmol and data by the COD in their open access publication Programmatic conversion of crystal structures into 3D printable files using Jmol (link). The authors equally mention cif2vrml by Werner Kaminsky as an executable for the Windows operating system, too. Both approaches target vrml (VRML V2.0 utf8) as output format, though Jmol alternatively can provide .obj, or .stl files as well. Jmol's documentation compiles some additional hints on its wiki (link).

# name   : Jmol3DP.spt
# source : Scalfani et al, J Cheminform 8, 66 (2016). https://doi.org/10.1186/s13321-016-0181-z
# purpose: convert with Jmol individual .cif into .vrml97 suitable for 3D printing
#
# "G:/CIF files"  # indicate the folder containing the list of cif to process
var alist=load("CIF_list_filenames.txt").lines
for (var i = 1; i < alist.length;i++)  {
  try{
    load @{alist[i]} {1 1 1}
    info = getProperty("moleculeInfo")
    nmax = getProperty(info, "nAtoms").max
    m = getProperty(info, "[select (number) where nAtoms == nmax]")[1]
    print {molecule=m}
    select on molecule=m
    delete molecule !=m
    axes OFF
    set exportScale  (10.0)
    write @{alist[i]+".wrl"}
    }  catch (e)  {jm
    print e;
    var a = e + "\n"+load(alist[i]);
    write inline @a @{alist[i]+".error"};
    }
 }

With an additional entry in ~/.bashrc of

alias jm="java -jar ~/.../.../Jmol.jar -L"

it suffices to cd into the folder with the list of cif files to process and to launch Jmol without a header

$ jm -ions ./Jmol3DP.spt

The paper announces https://chemapps.stolaf.edu/jmol/3dprint as a repository of 30k+ VRML/stl files; however somewhere between 2016 and today the page's address was changed, merged into an other interface, or the repository was retired (perhaps the public mailing list contains some info, or request help with a mail to jmol-users@lists.sourceforge.net).

Interestingly, blender became useful for 3D printing of molecules, too, but I can't say if it is efficient for batch conversions. See for instance atomic blender, and publications in JChemEduc (example, and an other just found by keyword blender for this journal alone).

@nbehrnd
Copy link
Contributor

nbehrnd commented Mar 11, 2024

@fredrikw

I believe there are plenty of converters to go from .pov to .obj.

This would be awesome because so far, I didn't find one to provide / reconstruct both the geometry as well as color of the objects of the scene.

@ghutchis
Copy link
Member

I haven't seen a .pov => .obj converter. That's why I've used VRML (via Python) and as needed, used Blender for the final OBJ or STL conversion.

@fredrikw
Copy link
Contributor

OK, I may have been a bit fast on that. I just did a search and found a bunch of online offerings so I assumed that there would be converters to be found. But I haven't really looked at them nor tried to find one for myself.

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

4 participants