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

ProteinFoldingResult, XYZ files and plotting of folded Proteins for ProteinFoldingProblem. #655

Merged
merged 136 commits into from
Jun 16, 2022

Conversation

MarcDrudis
Copy link
Contributor

@MarcDrudis MarcDrudis commented May 3, 2022

Summary
Implementation of the interpret method in ProteinFoldingProblem. ProteinFoldingResult created by this method is now functional and can return the turns encoding the shape of the protein, the Cartesian coordinates of each aminoacid, and generate a plot of the structure.
This PR solves issues #235 , #236 and #313.

Details and comments
Three new classes have been created and are arguments of ProteinFoldingResult.

  • ProteinDecoder: Takes the raw bitstring result and converts it into sequences of turns describing the shape of the protein.
  • ProteinXYZ: Takes the turn sequences from ProteinDecoder and the peptide from ProteinFoldingResult and generates a xyz file for the protein.
  • ProteinPlotter: Takes the xyz information from ProteinXYZ and generates a plot of the protein.

Usecase of how the class would work:

from qiskit_nature.problems.sampling.protein_folding.protein_folding_problem import (
    ProteinFoldingProblem,
)
from qiskit_nature.results.protein_folding_result import ProteinFoldingResult
from qiskit_nature.problems.sampling.protein_folding.interactions.miyazawa_jernigan_interaction import (
    MiyazawaJerniganInteraction,
)
from qiskit_nature.problems.sampling.protein_folding.peptide.peptide import Peptide

from qiskit_nature.problems.sampling.protein_folding.penalty_parameters import PenaltyParameters
from qiskit.utils import algorithm_globals

main_chain = "APRLR"
side_chains =  ["", "", "F", "Y", ""]

algorithm_globals.random_seed = 23
peptide = Peptide(main_chain, side_chains)
mj_interaction = MiyazawaJerniganInteraction()

penalty_back = 10
penalty_chiral = 10
penalty_1 = 10

penalty_terms = PenaltyParameters(penalty_chiral, penalty_back, penalty_1)

protein_folding_problem = ProteinFoldingProblem(peptide, mj_interaction, penalty_terms)
protein_folding_problem.qubit_op()

protein_folding_result = ProteinFoldingResult(protein_folding_problem, "0011011")


#Getting the turn sequences of the protein
print("This are the turns describing the main chain:",protein_folding_result.protein_decoder.get_main_turns())
print("This are the turns describing the side chain:",protein_folding_result.protein_decoder.get_side_turns())

#Generating the xyz file
protein_folding_result.protein_xyz.get_xyz_file( name = "NameForMyFile", output_data = True)

#Plotting the structure
protein_folding_result.plotstructure(ticks = True, grid = False)

This is how the plot looks like:
Protein

Note: Right now the xyz file is generated in the working directory.

Copy link
Contributor

@dlasecki dlasecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving a partial review.

qiskit_nature/results/protein_folding_result.py Outdated Show resolved Hide resolved
qiskit_nature/results/protein_folding_result.py Outdated Show resolved Hide resolved
qiskit_nature/results/protein_folding_result.py Outdated Show resolved Hide resolved
docs/tutorials/09_Protein_Folding.ipynb Outdated Show resolved Hide resolved
qiskit_nature/results/protein_folding_result.py Outdated Show resolved Hide resolved
docs/tutorials/09_Protein_Folding.ipynb Outdated Show resolved Hide resolved
Comment on lines +93 to +94
"""Returns a string that encodes a solution of the
:class:`~qiskit_nature.problems.sampling.protein_folding_problem.ProteinFoldingProblem`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this is enough for people to understand? Would an example of the string here with some further explanation help? You have more explanation in the tutorial right along with the example there. I just wonder if we are exposing this as part of the public API if things can be understood well enough from just from the docs here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the documentation. Now it looks like so:
image

Copy link
Contributor Author

@MarcDrudis MarcDrudis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, apparently I had to review the changes in order for my comments to be posted. You might see a lot of comments all of the sudden. Don't be concerned about them and just look at the last ones.

qiskit_nature/results/protein_folding_result.py Outdated Show resolved Hide resolved
qiskit_nature/results/protein_folding_result.py Outdated Show resolved Hide resolved
qiskit_nature/results/protein_folding_tools/protein_xyz.py Outdated Show resolved Hide resolved
qiskit_nature/results/protein_folding_result.py Outdated Show resolved Hide resolved
docs/tutorials/09_Protein_Folding.ipynb Outdated Show resolved Hide resolved
qiskit_nature/results/protein_folding_result.py Outdated Show resolved Hide resolved
docs/tutorials/09_Protein_Folding.ipynb Outdated Show resolved Hide resolved
Comment on lines +93 to +94
"""Returns a string that encodes a solution of the
:class:`~qiskit_nature.problems.sampling.protein_folding_problem.ProteinFoldingProblem`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the documentation. Now it looks like so:
image

docs/tutorials/09_Protein_Folding.ipynb Outdated Show resolved Hide resolved
Copy link
Member

@mrossinek mrossinek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that this seems pretty much good to go, once the CI is fixed 👍

@woodsp-ibm
Copy link
Member

woodsp-ibm commented Jun 15, 2022

In regards of the depth shading the Axes 3DPlot has a parameter as to whether to do that or not.

depthshade: Whether or not to shade the scatter markers to give the appearance of depth. Default is True.

Is this what the query was about "I am not sure I understand. The plot needs to be "3D" even if it doesn't rotate since it represents the shape of the protein. How would we turn that off?"

I guess I was wondering if it would be worth on the plotter we have to allow a user to change the value via that logic. We allow grids to be on or off, this could be another parameter that was passed on down. But then I guess we don't expose a way to change colors that its uses either right, so maybe things are fine as they are and if the user wants/needs more they can plot it directly themselves.

@MarcDrudis
Copy link
Contributor Author

In regards of the depth shading the Axes 3DPlot has a parameter as to whether to do that or not.

depthshade: Whether or not to shade the scatter markers to give the appearance of depth. Default is True.

Is this what the query was about "I am not sure I understand. The plot needs to be "3D" even if it doesn't rotate since it represents the shape of the protein. How would we turn that off?"

I guess I was wondering if it would be worth on the plotter we have to allow a user to change the value via that logic. We allow grids to be on or off, this could be another parameter that was passed on down. But then I guess we don't expose a way to change colors that its uses either right, so maybe things are fine as they are and if the user wants/needs more they can plot it directly themselves.

Well, since we are retuning a matplotlip figure the user can change any of those features of the plot. Same way I have manually rotated the plots in the notebook.

Copy link
Member

@woodsp-ibm woodsp-ibm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work doing this. All looks good to me. I made a very minor last minute change to the reno (an and to a but).

@mergify mergify bot merged commit d1ff719 into qiskit-community:main Jun 16, 2022
@MarcDrudis MarcDrudis deleted the ProteinFoldingInterpretMethod branch June 20, 2022 13:40
Anthony-Gandon pushed a commit to Anthony-Gandon/qiskit-nature that referenced this pull request May 25, 2023
…roteinFoldingProblem. (qiskit-community#655)

* Adding files modified. Dependencies not Checked

* Fixed one Dependency

* Passing ProteinFoldingProblem as attribute to ProteinFoldingResult. Also simplified some classes

* Some details

* Created more test cases in test_protein_folding_result

* Added comments in the unittest

* Quick changes

* Separated unittests, and small modifications

* Fixed bug side turns

* Added letters to the plotter

* Fixed format and documentation

* Added release note

* Corrected indentation and typos

* Changed legend location

* Updated header's date

* Updated header's date

* Update qiskit_nature/results/protein_folding_tools/__init__.py

Co-authored-by: dlasecki <[email protected]>

* Update qiskit_nature/results/protein_folding_result.py

Co-authored-by: dlasecki <[email protected]>

* Update qiskit_nature/results/protein_folding_tools/protein_decoder.py

Co-authored-by: dlasecki <[email protected]>

* Update qiskit_nature/results/protein_folding_tools/protein_decoder.py

Co-authored-by: dlasecki <[email protected]>

* Update qiskit_nature/results/protein_folding_tools/protein_plotter.py

Co-authored-by: dlasecki <[email protected]>

* Update qiskit_nature/results/protein_folding_result.py

Co-authored-by: dlasecki <[email protected]>

* Updated header's date

* Updated header's date

* Update protein_decoder.py

* Changed peptide getter docstring.

* Update qiskit_nature/results/protein_folding_result.py

Co-authored-by: dlasecki <[email protected]>

* Update qiskit_nature/results/protein_folding_result.py

Co-authored-by: dlasecki <[email protected]>

* Fixed multiple things

* Update qiskit_nature/results/protein_folding_tools/protein_xyz.py

Co-authored-by: dlasecki <[email protected]>

* Update qiskit_nature/results/protein_folding_tools/protein_xyz.py

Co-authored-by: dlasecki <[email protected]>

* Update releasenotes/notes/protein-folding-result-b344ac3c7f48e3ca.yaml

Co-authored-by: dlasecki <[email protected]>

* Update qiskit_nature/results/protein_folding_result.py

Co-authored-by: dlasecki <[email protected]>

* Update qiskit_nature/results/protein_folding_tools/protein_xyz.py

Co-authored-by: dlasecki <[email protected]>

* Modularized ProteinPlotter

* Changed documentation

* pylint

* Exposed main_turns

* Fixed make

* Fixed codeb

* Update qiskit_nature/results/protein_folding_result.py

Co-authored-by: dlasecki <[email protected]>

* Changed class description

* Reformated Unittests

* Refactored unittests

* Adding matplotlib

* Added Matplotlib requirement

* Accidentaly removed pylintdict

* Fixed circular import

* Update qiskit_nature/results/utils/protein_decoder.py

Co-authored-by: dlasecki <[email protected]>

* Update qiskit_nature/results/utils/protein_decoder.py

Co-authored-by: dlasecki <[email protected]>

* Update qiskit_nature/results/utils/protein_decoder.py

Co-authored-by: dlasecki <[email protected]>

* Update qiskit_nature/results/protein_folding_result.py

Co-authored-by: dlasecki <[email protected]>

* Fixed lint

* Refactored unittest

* best_sequence -> turns_sequence

* Update qiskit_nature/problems/sampling/protein_folding/protein_folding_problem.py

Co-authored-by: Max Rossmannek <[email protected]>

* Update test/results/test_protein_folding_result.py

Co-authored-by: Max Rossmannek <[email protected]>

* Update setup.py

Co-authored-by: Max Rossmannek <[email protected]>

* Update qiskit_nature/results/protein_folding_result.py

Co-authored-by: Max Rossmannek <[email protected]>

* Fixes

* black

* minor changes

* Fixed intentations

* Removed TODO comment

* minor changes

* Changed header XYZ file

* fixed style

* Return figure instead of plotting

* Removed files

* Returns in doc ploter

* Fixed codeblocks and reno

* RENO

* changed matplotlib requirements

* Added unittest for creating files

* Changed header xyz files

* changed direcotry name

* typo

* Make matplotlib optional

* Fixed comments

* Changed type hint

* typehint

* This version gives a circular import error. The reason is explained in a comment

* Attempts

* Fix errors

* Changed Documentation and get_figure

* Made more changes to RENO

* RENO

* reno

* Reno

* Fixed make html

* Fix sphinx

* Update releasenotes/notes/protein-folding-result-b344ac3c7f48e3ca.yaml

* Fixed bug with letters on plot

* Not plotting side chains when there are no side chains

* Fixed default values for plotting

* Make black

* Changed import order

* Fixes

* Apply suggestions from code review

Co-authored-by: Max Rossmannek <[email protected]>

* Fixed spelling and writing bug

* Changes in notebook

* Add .editorconfig (qiskit-community#685)

* Overwriting files

* Notebook

* Format

* Max's comments

* Fixed Notebook and changed name get_xyz_data()

* turn_sequence and tempfile

* Trailing Whitespace

* make black

* Changed notebook

* Documentation git_result...

* black

* Removed file

* Fixes

* Changed reno

* Changed capital letters on testfiles

* Update releasenotes/notes/protein-folding-result-b344ac3c7f48e3ca.yaml

Co-authored-by: dlasecki <[email protected]>
Co-authored-by: Max Rossmannek <[email protected]>
Co-authored-by: Steve Wood <[email protected]>
Co-authored-by: Manoel Marques <[email protected]>
Co-authored-by: Max Rossmannek <[email protected]>
Co-authored-by: woodsp-ibm <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants