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

command-line tool #53

Open
UnixJunkie opened this issue Jul 5, 2023 · 8 comments
Open

command-line tool #53

UnixJunkie opened this issue Jul 5, 2023 · 8 comments
Labels
question Further information is requested

Comments

@UnixJunkie
Copy link

Hello,

Is there a way to have a command-line tool for this use case:

  • I am in a terminal
  • I want to create a 2D picture (as a grid) of all molecules in the input file
  • as a .png or .pdf, or ("a la rigueur") as a .html file.

I am not under jupyter or what not.

My input files are either .sdf, .mol2 or .smi (and in a SMILES file, the SMILES string are the first field/column).

Thanks a lot,
Francois.

@cbouy
Copy link
Owner

cbouy commented Jul 5, 2023

Hi Francois,

  • There's no CLI in mols2grid but you could just make a simple script to emulate that.
  • You can generate the complete grid of molecules (as opposed to the paginated document) by specifying template="table" (see below). Please refer to the documentation for more info on the other arguments that you can supply.
  • You can save an HTML doc by using mols2grid.save(input, output="document.html", template="table", <your other args>) instead of mols2grid.display. The HTML document will have a special attribute inside (page-break-inside: avoid) which prevents page breaks if you decide to then convert that HTML to a PDF with multiple pages. There are some CLI utilities to do that conversion to pdf and images (wkhtmltopdf among others) or most browsers and OS have a print-to-pdf functionality.

Feel free to close the issue if it answers your question.

Hope this helps,
Cédric

@cbouy cbouy added the question Further information is requested label Jul 5, 2023
@UnixJunkie
Copy link
Author

Thanks, I'll give it a try.
I'm trying to get rid of the mview proprietary tool.

@UnixJunkie
Copy link
Author

Sometimes, I would like mols2grid to just be able to visualize some molecules in a browser.
Either the molecules are SMILES in a file; or in a mol2 or sdf file.
I still think a basic CLI to visualize a bunch of molecules, not requiring any Python programming from the end-user would be nice.

@UnixJunkie UnixJunkie reopened this Jun 20, 2024
@UnixJunkie
Copy link
Author

If you know mview from chemaxon, than that's what I'd like but in open-source.

@UnixJunkie
Copy link
Author

UnixJunkie commented Jun 20, 2024

I had written one in the past, as you suggested, but it is now broken:
https://github.com/UnixJunkie/molenc/blob/master/bin/molenc_mview.py

mols2grid.save(mols, output='caff.html', template="table", prerender=True)

Gives me:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In [4], line 1
----> 1 mols2grid.save(mols, output='caff.html', template="table", prerender=True)

File ~/usr/miniconda/lib/python3.11/functools.py:909, in singledispatch.<locals>.wrapper(*args, **kw)
    905 if not args:
    906     raise TypeError(f'{funcname} requires at least '
    907                     '1 positional argument')
--> 909 return dispatch(args[0].__class__)(*args, **kw)

File ~/usr/miniconda/lib/python3.11/site-packages/mols2grid/dispatch.py:298, in _(mols, **kwargs)
    294 @save.register(Series)
    295 @save.register(list)
    296 @save.register(tuple)
    297 def _(mols, **kwargs):
--> 298     template, kwargs, render_kwargs = _prepare_kwargs(kwargs, "save")
    299     output = kwargs.pop("output")
    300     return MolGrid.from_mols(mols, **kwargs).save(
    301         output, template=template, **render_kwargs
    302     )

File ~/usr/miniconda/lib/python3.11/site-packages/mols2grid/dispatch.py:24, in _prepare_kwargs(kwargs, kind)
     20 """Separate kwargs for the init and render methods of MolGrid"""
     21 template = kwargs.pop("template", _SIGNATURE["render"]["template"].default)
     22 render_kwargs = {
     23     param: kwargs.pop(param, sig.default)
---> 24     for param, sig in _SIGNATURE[f"to_{template}"].items()
     25 }
     26 if kind == "display":
     27     render_kwargs.update(
     28         {
     29             param: kwargs.pop(param, sig.default)
     30             for param, sig in _SIGNATURE["display"].items()
     31         }
     32     )

KeyError: 'to_table'

@UnixJunkie
Copy link
Author

Software that was working in the past, but doesn't anymore makes me feel very sad.

@cbouy
Copy link
Owner

cbouy commented Jun 20, 2024

For the KeyError, that's because there were some breaking changes (here the renaming of the possible values for template from pages/table to interactive/static) between v1 and v2. You can either:

  • pin your dependencies to mols2grid<2 and keep your code as is,
  • or mols2grid>=2,<3 but using template=static,
  • or don't pin anything and use either template=table or template=static depending on the version of mols2grid installed with mols2grid.__version__.

For the CLI, yeah I can see some use case for it, but I have some other priorities for this package and rarely enough time to spare unfortunately. I remember you opening PR #54, apologies for not giving feedback on that. If you're still up for it I can make some suggestions and guide you to integrate it as an actual CLI tool.

@UnixJunkie
Copy link
Author

I could repair molenc_mview.py, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants