Layne-Huang / PMDM

74 stars 17 forks source link

checkpoint file for testing #7

Closed wenchangzhou-qtx closed 2 months ago

wenchangzhou-qtx commented 3 months ago

Hey @Layne-Huang,

Great work!

I'm trying to follow by testing a few example commands in the repo, for example the first command under "Inference", python -u sample_batch.py --ckpt <checkpoint> --num_samples <number of samples> --sampling_type generalized, is there a checkpoint file I need to provide?

I tried without it but I got error here below:

Entropy of n_nodes: H[N] -1.3862943649291992
Traceback (most recent call last):
  File "~/softwares/mambaforge3/envs/pmdm/lib/python3.9/site-packages/torch/serialization.py", line 541, in _check_seekable
    f.seek(f.tell())
AttributeError: 'NoneType' object has no attribute 'seek'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/softwares/PMDM/sample_batch.py", line 130, in <module>
    ckpt = torch.load(args.ckpt)
  File "~/softwares/mambaforge3/envs/pmdm/lib/python3.9/site-packages/torch/serialization.py", line 998, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "~/softwares/mambaforge3/envs/pmdm/lib/python3.9/site-packages/torch/serialization.py", line 450, in _open_file_like
    return _open_buffer_reader(name_or_buffer)
  File "~/softwares/mambaforge3/envs/pmdm/lib/python3.9/site-packages/torch/serialization.py", line 435, in __init__
    _check_seekable(buffer)
  File "~/softwares/mambaforge3/envs/pmdm/lib/python3.9/site-packages/torch/serialization.py", line 544, in _check_seekable
    raise_err_msg(["seek", "tell"], e)
  File "~/softwares/mambaforge3/envs/pmdm/lib/python3.9/site-packages/torch/serialization.py", line 537, in raise_err_msg
    raise type(e)(msg)
AttributeError: 'NoneType' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.
Layne-Huang commented 3 months ago

Yes, the checkpoint (500.pt) could be found in Zenodo.

wenchangzhou-qtx commented 3 months ago

Thnaks! @Layne-Huang

I continued the test on sample_for_pdb.py, the command I used is (which is the same as in the repo) python -u sample_for_pdb.py --ckpt data/500.pt --pdb_path receptor.4amber.pdb --num_atom 50 --num_samples 2 --sampling_type generalized Somehow I need to provide another sdf file, which I did not find from the python -u sample_for_pdb.py -h, can you explain what this file should be? Thanks! The error I got is down below:

Traceback (most recent call last):
  File "~/softwares/PMDM/sample_for_pdb.py", line 292, in <module>
    data = pdb_to_pocket_data(args.pdb_path, sdf_file)
  File "~/softwares/PMDM/sample_for_pdb.py", line 186, in pdb_to_pocket_data
    ligand_data = torchify_dict(parse_sdf_file(sdf_path))
  File "~/softwares/PMDM/sample_for_pdb.py", line 55, in parse_sdf_file
    rdmol = next(iter(Chem.SDMolSupplier(path, removeHs=False, sanitize=False)))
OSError: File error: Bad input file ./ref_1.sdf
Layne-Huang commented 3 months ago

If you do not have the reference molecule for comparison, you could ignore them by commenting the relevant code.

I have also updated the sample_for_pdb file which I convert the sdf_file as an argument. You could also utilize the newest file.

Thank you very much for the feedback. It indeed helps improves this project!

wenchangzhou-qtx commented 3 months ago

Thanks! @Layne-Huang I tried the newest file, seems there is still one more place to modify, see the error message I got below:

Traceback (most recent call last):
  File "~/softwares/PMDM/sample_for_pdb.py", line 294, in <module>
    data = pdb_to_pocket_data(args.pdb_path, args.sdf_file)
AttributeError: 'Namespace' object has no attribute 'sdf_file'
Layne-Huang commented 3 months ago

It could work now.

FeilongWuHaa commented 3 months ago

If you do not have the reference molecule for comparison, you could ignore them by commenting the relevant code.

I have also updated the sample_for_pdb file which I convert the sdf_file as an argument. You could also utilize the newest file.

Thank you very much for the feedback. It indeed helps improves this project!

Hi, author.

when I used command: "python -u sample_for_pdb.py \ --ckpt ./500.pt \ --pdb_path 3WZE/pocket.pdb \ --num_atom 32 \ --num_samples 100 \ --sampling_type generalized" to generate molecules for custom pocket,

But, I got a error, "pocket_pos_center = pocket_pos - scatter_mean(ligand_pos, ligand_batch, dim=0)[pocket_batch] IndexError: index is out of bounds for dimension with size 0".

It seems like that the "sdf_path" argument is necessary.

Beside, even with "sdf_path" argument, a new error was shown: Traceback (most recent call last): File "/home/PMDM/PMDM/sample_for_pdb.py", line 345, in pos_gen, pos_gen_traj, atom_type, atom_traj = model.langevin_dynamics_sample( File "/home/PMDM/PMDM/models/epsnet/MDM_pocket_coor_shared.py", line 790, in langevin_dynamics_sample net_out = self.net( File "/home/PMDM/PMDM/models/epsnet/MDM_pocket_coor_shared.py", line 478, in net node_attr_global, pos_attr_global = self.encoder_global( File "/home/anaconda3/envs/PMDM/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl return self._call_impl(*args, kwargs) File "/home/anaconda3/envs/PMDM/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl return forward_call(*args, *kwargs) File "/home/PMDM/PMDM/models/encoders/egnn.py", line 478, in forward x = layer(x, edge_index, edge_attr, batch=batch, ligand_batch=ligand_batch, size=bsize, linker_mask=linker_mask) File "/home/PMDM/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl return self._call_impl(args, kwargs) File "/home/anaconda3/envs/PMDM/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl return forward_call(*args, **kwargs) File "/home/PMDM/PMDM/models/encoders/egnn.py", line 215, in forward hidden_out, coors_out = self.propagate(edge_index, x=feats, edge_attr=edge_attr_feats, ValueError: too many values to unpack (expected 2)

I have check the code, and I found the code have error: the "self.propagate(edge_index, x=feats, edge_attr=edge_attr_feats,)" fuction return a tensor with shape of torch.Size([10432, 128])

could you help us to fix code ?

ps: I use the lastest version code ( updated in 2024.04.02)

Layne-Huang commented 3 months ago

Hi,

I have uploaded sample_for_pdb.py with the related files models/encoders/egnn.py and utils/sample.py to support generation without reference ligand.

For this error: the "self.propagate(edge_index, x=feats, edge_attr=edge_attr_feats,)", please degrade your torch_geometry version to 2.4.0.

Please let me know if there is any other issue.

FeilongWuHaa commented 3 months ago

Thanks! @Layne-Huang