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

[ENH]: Adding option to export/return PDB as a raw string #112

Closed
hedderi4 opened this issue Jun 11, 2024 · 3 comments · Fixed by #113
Closed

[ENH]: Adding option to export/return PDB as a raw string #112

hedderi4 opened this issue Jun 11, 2024 · 3 comments · Fixed by #113
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@hedderi4
Copy link

Problem

It would be very useful to be able to return the cavities as a string in PDB format instead of immediately writing it to a file.
Thanks a lot!

Proposed solution

This should be done by editing the _export function, since the PDB string is anyways generated, right? Or are there any other possibilities that I am missing?

@hedderi4 hedderi4 added the enhancement New feature or request label Jun 11, 2024
@jvsguerra jvsguerra added the help wanted Extra attention is needed label Jun 11, 2024
@jvsguerra jvsguerra self-assigned this Jun 11, 2024
@jvsguerra
Copy link
Member

jvsguerra commented Jun 11, 2024

Hi @jbHedderich,

Thank you for your suggestion.

Are you interested in obtaining the coordinates of the cavity points from the string? If so, we shared a function (grid2coords) to export coordinates in a numpy.ndarray in this #110 (comment).

Please let us know if this meets your needs.

@jvsguerra jvsguerra changed the title Adding option to export/return PDB as a raw string [ENH]: Adding option to export/return PDB as a raw string Jun 11, 2024
@jvsguerra
Copy link
Member

jvsguerra commented Jun 11, 2024

I have implemented an option to export PDB as a raw string in pyKVFinder v0.6.14.

To use this feature, you can follow the examples below.

Example 1: Using full workflow (pyKVFinder.run_workflow) to detect cavities and export the cavity PDB-formatted file as a string. The pyKVFindeResults.export method now accepts None as an input for the output filename (output), returning the PDB-formatted data as a raw string instead of writing it to a file.

>>> import pyKVFinder
>>> pdb = os.path.join(os.path.dirname(pyKVFinder.__file__), 'data', 'tests', '1FMO.pdb')
>>> results = pyKVFinder.run_workflow(pdb)
>>> string = results.export(output=None)
>>> print(string)
ATOM     1  H   KAA     0       0.000   0.000   0.000  1.00  0.00
...
ATOM  1000  H   KAA     0       0.000   0.000   0.000  1.00  0.00
>>> string = results.export_all(output=None)
>>> print(string)
ATOM     1  H   KAA     0       0.000   0.000   0.000  1.00  0.00
...
ATOM  1000  H   KAA     0       0.000   0.000   0.000  1.00  0.00

Example 2: Using the stepwise workflow (pyKVFinder.read_pdb, pyKVFinder.get_vertices, pyKVFinder.detect) to detect cavities and export the cavity PDB-formatted file as a string. The pyKVFinder.export function now accepts None as an input for the output filename (fn), returning the PDB-formatted data as a raw string instead of writing it to a file.

>>> import pyKVFinder
>>> pdb = os.path.join(os.path.dirname(pyKVFinder.__file__), 'data', 'tests', '1FMO.pdb')
>>> atomic = pyKVFinder.read_pdb(pdb)
>>> vertices = pyKVFinder.get_vertices(atomic)
>>> ncav, cavities = pyKVFinder.detect(atomic, vertices)
>>> string = pyKVFinder.export(None, cavities, None, vertices)
>>> print(string)
ATOM     1  H   KAA     0       0.000   0.000   0.000  1.00  0.00
...
ATOM  1000  H   KAA     0       0.000   0.000   0.000  1.00  0.00

Please let me know if this meets your needs. If you encounter any further issues or have additional questions, feel free to ask for assistance.

@jvsguerra jvsguerra reopened this Jun 11, 2024
@hedderi4
Copy link
Author

Thanks, that helped a lot :)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants