generatebio / chroma

A generative model for programmable protein design
Apache License 2.0
700 stars 90 forks source link

linking downloaded weight for offline chroma usage #52

Open peptidelinks opened 6 months ago

peptidelinks commented 6 months ago

Dear generatebio github, I have gpu node that is not connected to the internet and thus need to run chroma offline. Can you help me how to set up and call out the downloaded weight? I appreciate your help and guidance.

Dhruv-reviv commented 5 months ago

Hi @peptidelinks, Were you able to set it up for offline run?

peptidelinks commented 5 months ago

Yes I was able to run it. I will update this comment accordingly later to share the steps.

Dhruv-reviv commented 5 months ago

Thanks much @peptidelinks! Waiting to get it offline as soon as possible!

peptidelinks commented 4 months ago

First, download the 2G3N.cif file from the pdb database. (https://www.rcsb.org/structure/2g3n) Second, you want to add the following to provide the path for the 2G3N.cif file. In the "chroma/chroma/layers/structure/protein_graph.py" add the below. def _reference_stats(self, reference_pdb): file_path = f'/PATHto2G3N/2G3N.cif' protein = Protein.from_CIF(filepath) X, C, = protein.to_XCS() stats_dict = self._feature_stats(X, C) return stats_dict

Once these are accomplished, when you initiate chroma instance, you want to give the path to the weights. chroma = Chroma(weights_backbone='/PATHtoWEIGHTS/chroma_backbone_v1.0.pt', weights_design='/PATHtoWEIGHTS/chroma_design_v1.0.pt')

Dhruv-reviv commented 4 months ago

Hi @peptidelinks! I made the changes as per your instructions. However, I received the following value unpacking error, if you can have a look and let me know if there is anything you can help with?

Traceback (most recent call last): File "/home/ubuntu/chroma/test.py", line 3, in <module> chroma = Chroma(weights_backbone = 'chroma_weights/chroma_backbone_v1.0.pt', weights_design = 'chroma_weights/chroma_design_v1.0.pt') File "/home/ubuntu/chroma/chroma/models/chroma.py", line 84, in __init__ self.backbone_network = graph_backbone.load_model( File "/home/ubuntu/chroma/chroma/models/graph_backbone.py", line 405, in load_model return utility_load_model( File "/home/ubuntu/chroma/chroma/utility/model.py", line 110, in load_model model = model_class(**params["init_kwargs"]).to(device) File "/home/ubuntu/chroma/chroma/models/graph_backbone.py", line 114, in __init__ [ File "/home/ubuntu/chroma/chroma/models/graph_backbone.py", line 115, in <listcomp> BackboneEncoderGNN( File "/home/ubuntu/chroma/chroma/models/graph_design.py", line 1192, in __init__ self.feature_graph = protein_graph.ProteinFeatureGraph( File "/home/ubuntu/chroma/chroma/layers/structure/protein_graph.py", line 183, in __init__ self._load_centering_params(self.centered_pdb) File "/home/ubuntu/chroma/chroma/layers/structure/protein_graph.py", line 277, in _load_centering_params param_dictionary = self._reference_stats(reference_pdb) File "/home/ubuntu/chroma/chroma/layers/structure/protein_graph.py", line 300, in _reference_stats stats_dict = self._feature_stats(X, C) File "/home/ubuntu/chroma/chroma/layers/structure/protein_graph.py", line 327, in _feature_stats node_h = layer(X, edge_idx, C) File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/home/ubuntu/chroma/chroma/layers/structure/protein_graph.py", line 623, in forward outs = self.internal_coords(X, C=C, return_masks=True) File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/home/ubuntu/chroma/chroma/layers/structure/geometry.py", line 411, in forward _, X_CA, X_C, X_O = X.unbind(dim=2) ValueError: too many values to unpack (expected 4)

peptidelinks commented 4 months ago

can you try to give a full path to the weights?

cd123-cd commented 4 months ago

Hi @peptidelinks! I made the changes as per your instructions. However, I received the following value unpacking error, if you can have a look and let me know if there is anything you can help with?

Traceback (most recent call last): File "/home/ubuntu/chroma/test.py", line 3, in <module> chroma = Chroma(weights_backbone = 'chroma_weights/chroma_backbone_v1.0.pt', weights_design = 'chroma_weights/chroma_design_v1.0.pt') File "/home/ubuntu/chroma/chroma/models/chroma.py", line 84, in __init__ self.backbone_network = graph_backbone.load_model( File "/home/ubuntu/chroma/chroma/models/graph_backbone.py", line 405, in load_model return utility_load_model( File "/home/ubuntu/chroma/chroma/utility/model.py", line 110, in load_model model = model_class(**params["init_kwargs"]).to(device) File "/home/ubuntu/chroma/chroma/models/graph_backbone.py", line 114, in __init__ [ File "/home/ubuntu/chroma/chroma/models/graph_backbone.py", line 115, in <listcomp> BackboneEncoderGNN( File "/home/ubuntu/chroma/chroma/models/graph_design.py", line 1192, in __init__ self.feature_graph = protein_graph.ProteinFeatureGraph( File "/home/ubuntu/chroma/chroma/layers/structure/protein_graph.py", line 183, in __init__ self._load_centering_params(self.centered_pdb) File "/home/ubuntu/chroma/chroma/layers/structure/protein_graph.py", line 277, in _load_centering_params param_dictionary = self._reference_stats(reference_pdb) File "/home/ubuntu/chroma/chroma/layers/structure/protein_graph.py", line 300, in _reference_stats stats_dict = self._feature_stats(X, C) File "/home/ubuntu/chroma/chroma/layers/structure/protein_graph.py", line 327, in _feature_stats node_h = layer(X, edge_idx, C) File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/home/ubuntu/chroma/chroma/layers/structure/protein_graph.py", line 623, in forward outs = self.internal_coords(X, C=C, return_masks=True) File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/home/ubuntu/chroma/chroma/layers/structure/geometry.py", line 411, in forward _, X_CA, X_C, X_O = X.unbind(dim=2) ValueError: too many values to unpack (expected 4)

I guess you not comment out the line ` def _reference_stats(self, reference_pdb): file_path=f'/data2/bench/ga/chroma-main/pretrain/2g3n.cif' protein =Protein.from_CIF(filepath) X,C, =protein.to_XCS()

X, C, _ = Protein.from_PDBID(reference_pdb).to_XCS()

    stats_dict = self._feature_stats(X, C)
    return stats_dict

`

peptidelinks commented 3 months ago

yes, you want to keep the original reference_stats as well as add the line I mentioned above which is copied below; In the "chroma/chroma/layers/structure/protein_graph.py" add the below. def _reference_stats(self, reference_pdb): file_path = f'/PATHto2G3N/2G3N.cif' protein = Protein.from_CIF(filepath) X, C, = protein.to_XCS() stats_dict = self._feature_stats(X, C) return stats_dict

you may need to indent the code above

peptidelinks commented 3 months ago

@Dhruv-reviv did it work for you? If it worked, please let me know!

Dhruv-reviv commented 3 months ago

@peptidelinks I see! Actually I moved on to a different project. However, I will try it by end of the day and let you know!

Thanks!