choderalab / espaloma

Extensible Surrogate Potential of Ab initio Learned and Optimized by Message-passing Algorithm 🍹https://arxiv.org/abs/2010.01196
https://docs.espaloma.org/en/latest/
MIT License
202 stars 23 forks source link

SSL: CERTIFICATE_VERIFY_FAILED at "esp.get_model("latest")" step #215

Open beavenah opened 2 months ago

beavenah commented 2 months ago

Hi all,

I'm using a MacBook M3 and using mandatory Zscaler for security. I was able to install espaloma on my laptop, but when I get to the "esp.get_model("latest")" step, I get:

>>> import espaloma as esp
>>> from openff.toolkit.topology import Molecule
>>> molecule = Molecule.from_smiles("CN1C=NC2=C1C(=O)N(C(=O)N2C)C")
>>> molecule_graph = esp.Graph(molecule)
/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/site-packages/dgl/heterograph.py:92: DGLWarning: Recommend creating graphs by `dgl.graph(data)` instead of `dgl.DGLGraph(data)`.
  dgl_warning(
>>> espaloma_model = esp.get_model("latest")
Downloading: "https://github.com/choderalab/espaloma/releases/latest/download/espaloma-latest.pt" to /Users/abeaven/.cache/torch/hub/checkpoints/espaloma-latest.pt
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/http/client.py", line 1283, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/http/client.py", line 1329, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/http/client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/http/client.py", line 1038, in _send_output
    self.send(msg)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/http/client.py", line 976, in send
    self.connect()
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/http/client.py", line 1455, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/ssl.py", line 1104, in _create
    self.do_handshake()
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/ssl.py", line 1375, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:1007)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/site-packages/espaloma/utils/model_fetch.py", line 116, in get_model
    model = torch.utils.model_zoo.load_url(url, map_location="cpu")
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/site-packages/torch/hub.py", line 746, in load_state_dict_from_url
    download_url_to_file(url, cached_file, hash_prefix, progress=progress)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/site-packages/torch/hub.py", line 611, in download_url_to_file
    u = urlopen(req)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 557, in error
    result = self._call_chain(*args)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 749, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 557, in error
    result = self._call_chain(*args)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 749, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 519, in open
    response = self._open(req, data)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/urllib/request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:1007)>

It was recommended that I try pip3 install pip_system_certs --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host github.com in my conda base and espaloma conda, but I get the same SSL errors. Does anyone have a recommendation of what to do? Can I download the espaloma-latest.pt myself and use it instead of trying to pull it from GitHub in the python script? If so, how would I change the script?

Thanks again!

ijpulidos commented 2 months ago

@beavenah It seems like your network is doing something strange when trying to download the model.

The good news is that you can indeed download the model yourself and load it from a path using torch, it would be something like the following:

import torch
espaloma_model = torch.load("/path/to/espaloma-latest.pt")
espaloma_model.eval()

I hope this works!

beavenah commented 2 months ago

Thanks, @ijpulidos ! The suggestion seems to have worked (output below):

>>> import torch
>>> import espaloma as esp
>>> from openff.toolkit.topology import Molecule
>>> molecule = Molecule.from_smiles("CN1C=NC2=C1C(=O)N(C(=O)N2C)C")
>>> molecule_graph = esp.Graph(molecule)
/opt/homebrew/Caskroom/mambaforge/base/envs/espaloma/lib/python3.10/site-packages/dgl/heterograph.py:92: DGLWarning: Recommend creating graphs by `dgl.graph(data)` instead of `dgl.DGLGraph(data)`.
  dgl_warning(
>>> espaloma_model = torch.load("/Users/abeaven/Downloads/espaloma-latest.pt")
>>> espaloma_model.eval()
Sequential(
  (0): Sequential(
    (f_in): Sequential(
      (0): Linear(in_features=114, out_features=128, bias=True)
      (1): Tanh()
    )
    (_sequential): _Sequential(
      (d0): GN(
        (gn): SAGEConv(
          (feat_drop): Dropout(p=0.1, inplace=False)
          (fc_self): Linear(in_features=128, out_features=512, bias=False)
          (fc_neigh): Linear(in_features=128, out_features=512, bias=False)
        )
      )
      (o2): Dropout(p=0.1, inplace=False)
      (d3): GN(
        (gn): SAGEConv(
          (feat_drop): Dropout(p=0.1, inplace=False)
          (fc_self): Linear(in_features=512, out_features=512, bias=False)
          (fc_neigh): Linear(in_features=512, out_features=512, bias=False)
        )
      )
      (o5): Dropout(p=0.1, inplace=False)
      (d6): GN(
        (gn): SAGEConv(
          (feat_drop): Dropout(p=0.1, inplace=False)
          (fc_self): Linear(in_features=512, out_features=512, bias=False)
          (fc_neigh): Linear(in_features=512, out_features=512, bias=False)
        )
      )
      (o8): Dropout(p=0.1, inplace=False)
    )
  )
  (1): JanossyPooling(
    (sequential_2): _Sequential(
      (d0): Linear(in_features=1024, out_features=512, bias=True)
      (o2): Dropout(p=0.1, inplace=False)
      (d3): Linear(in_features=512, out_features=512, bias=True)
      (o5): Dropout(p=0.1, inplace=False)
      (d6): Linear(in_features=512, out_features=512, bias=True)
      (o8): Dropout(p=0.1, inplace=False)
      (d9): Linear(in_features=512, out_features=512, bias=True)
      (o11): Dropout(p=0.1, inplace=False)
    )
    (f_out_2_to_log_coefficients): Linear(in_features=512, out_features=2, bias=True)
    (sequential_3): _Sequential(
      (d0): Linear(in_features=1536, out_features=512, bias=True)
      (o2): Dropout(p=0.1, inplace=False)
      (d3): Linear(in_features=512, out_features=512, bias=True)
      (o5): Dropout(p=0.1, inplace=False)
      (d6): Linear(in_features=512, out_features=512, bias=True)
      (o8): Dropout(p=0.1, inplace=False)
      (d9): Linear(in_features=512, out_features=512, bias=True)
      (o11): Dropout(p=0.1, inplace=False)
    )
    (f_out_3_to_log_coefficients): Linear(in_features=512, out_features=2, bias=True)
    (sequential_4): _Sequential(
      (d0): Linear(in_features=2048, out_features=512, bias=True)
      (o2): Dropout(p=0.1, inplace=False)
      (d3): Linear(in_features=512, out_features=512, bias=True)
      (o5): Dropout(p=0.1, inplace=False)
      (d6): Linear(in_features=512, out_features=512, bias=True)
      (o8): Dropout(p=0.1, inplace=False)
      (d9): Linear(in_features=512, out_features=512, bias=True)
      (o11): Dropout(p=0.1, inplace=False)
    )
    (f_out_4_to_k): Linear(in_features=512, out_features=6, bias=True)
    (sequential_1): _Sequential(
      (d0): Linear(in_features=512, out_features=512, bias=True)
      (o2): Dropout(p=0.1, inplace=False)
      (d3): Linear(in_features=512, out_features=512, bias=True)
      (o5): Dropout(p=0.1, inplace=False)
      (d6): Linear(in_features=512, out_features=512, bias=True)
      (o8): Dropout(p=0.1, inplace=False)
      (d9): Linear(in_features=512, out_features=512, bias=True)
      (o11): Dropout(p=0.1, inplace=False)
    )
    (f_out_1_to_s): Linear(in_features=512, out_features=1, bias=True)
    (f_out_1_to_e): Linear(in_features=512, out_features=1, bias=True)
  )
  (2): JanossyPoolingWithSmirnoffImproper(
    (sequential_n4_improper): _Sequential(
      (d0): Linear(in_features=2048, out_features=512, bias=True)
      (o2): Dropout(p=0.1, inplace=False)
      (d3): Linear(in_features=512, out_features=512, bias=True)
      (o5): Dropout(p=0.1, inplace=False)
      (d6): Linear(in_features=512, out_features=512, bias=True)
      (o8): Dropout(p=0.1, inplace=False)
      (d9): Linear(in_features=512, out_features=512, bias=True)
      (o11): Dropout(p=0.1, inplace=False)
    )
    (f_out_n4_improper_to_k): Linear(in_features=512, out_features=2, bias=True)
  )
  (3): ExpCoefficients()
  (4): ChargeEquilibrium()
  (5): LinearMixtureToOriginal()
)
>>> espaloma_model(molecule_graph.heterograph)
Graph(num_nodes={'g': 1, 'n1': 24, 'n2': 50, 'n3': 86, 'n4': 108, 'n4_improper': 48, 'nonbonded': 324, 'onefour': 92},
      num_edges={('g', 'g_has_n1', 'n1'): 24, ('g', 'g_has_n2', 'n2'): 50, ('g', 'g_has_n3', 'n3'): 86, ('g', 'g_has_n4', 'n4'): 108, ('g', 'g_has_n4_improper', 'n4_improper'): 48, ('g', 'g_has_nonbonded', 'nonbonded'): 324, ('g', 'g_has_onefour', 'onefour'): 92, ('n1', 'n1_as_0_in_n2', 'n2'): 50, ('n1', 'n1_as_0_in_n3', 'n3'): 86, ('n1', 'n1_as_0_in_n4', 'n4'): 108, ('n1', 'n1_as_0_in_n4_improper', 'n4_improper'): 48, ('n1', 'n1_as_0_in_nonbonded', 'nonbonded'): 324, ('n1', 'n1_as_0_in_onefour', 'onefour'): 92, ('n1', 'n1_as_1_in_n2', 'n2'): 50, ('n1', 'n1_as_1_in_n3', 'n3'): 86, ('n1', 'n1_as_1_in_n4', 'n4'): 108, ('n1', 'n1_as_1_in_n4_improper', 'n4_improper'): 48, ('n1', 'n1_as_1_in_nonbonded', 'nonbonded'): 324, ('n1', 'n1_as_1_in_onefour', 'onefour'): 92, ('n1', 'n1_as_2_in_n3', 'n3'): 86, ('n1', 'n1_as_2_in_n4', 'n4'): 108, ('n1', 'n1_as_2_in_n4_improper', 'n4_improper'): 48, ('n1', 'n1_as_3_in_n4', 'n4'): 108, ('n1', 'n1_as_3_in_n4_improper', 'n4_improper'): 48, ('n1', 'n1_in_g', 'g'): 24, ('n1', 'n1_neighbors_n1', 'n1'): 50, ('n2', 'n2_as_0_in_n3', 'n3'): 86, ('n2', 'n2_as_0_in_n4', 'n4'): 108, ('n2', 'n2_as_1_in_n3', 'n3'): 86, ('n2', 'n2_as_1_in_n4', 'n4'): 108, ('n2', 'n2_as_2_in_n4', 'n4'): 108, ('n2', 'n2_has_0_n1', 'n1'): 50, ('n2', 'n2_has_1_n1', 'n1'): 50, ('n2', 'n2_in_g', 'g'): 50, ('n3', 'n3_as_0_in_n4', 'n4'): 108, ('n3', 'n3_as_1_in_n4', 'n4'): 108, ('n3', 'n3_has_0_n1', 'n1'): 86, ('n3', 'n3_has_0_n2', 'n2'): 86, ('n3', 'n3_has_1_n1', 'n1'): 86, ('n3', 'n3_has_1_n2', 'n2'): 86, ('n3', 'n3_has_2_n1', 'n1'): 86, ('n3', 'n3_in_g', 'g'): 86, ('n4', 'n4_has_0_n1', 'n1'): 108, ('n4', 'n4_has_0_n2', 'n2'): 108, ('n4', 'n4_has_0_n3', 'n3'): 108, ('n4', 'n4_has_1_n1', 'n1'): 108, ('n4', 'n4_has_1_n2', 'n2'): 108, ('n4', 'n4_has_1_n3', 'n3'): 108, ('n4', 'n4_has_2_n1', 'n1'): 108, ('n4', 'n4_has_2_n2', 'n2'): 108, ('n4', 'n4_has_3_n1', 'n1'): 108, ('n4', 'n4_in_g', 'g'): 108, ('n4_improper', 'n4_improper_has_0_n1', 'n1'): 48, ('n4_improper', 'n4_improper_has_1_n1', 'n1'): 48, ('n4_improper', 'n4_improper_has_2_n1', 'n1'): 48, ('n4_improper', 'n4_improper_has_3_n1', 'n1'): 48, ('n4_improper', 'n4_improper_in_g', 'g'): 48, ('nonbonded', 'nonbonded_has_0_n1', 'n1'): 324, ('nonbonded', 'nonbonded_has_1_n1', 'n1'): 324, ('nonbonded', 'nonbonded_in_g', 'g'): 324, ('onefour', 'onefour_has_0_n1', 'n1'): 92, ('onefour', 'onefour_has_1_n1', 'n1'): 92, ('onefour', 'onefour_in_g', 'g'): 92},
      metagraph=[('g', 'n1', 'g_has_n1'), ('g', 'n2', 'g_has_n2'), ('g', 'n3', 'g_has_n3'), ('g', 'n4', 'g_has_n4'), ('g', 'n4_improper', 'g_has_n4_improper'), ('g', 'nonbonded', 'g_has_nonbonded'), ('g', 'onefour', 'g_has_onefour'), ('n1', 'n2', 'n1_as_0_in_n2'), ('n1', 'n2', 'n1_as_1_in_n2'), ('n1', 'n3', 'n1_as_0_in_n3'), ('n1', 'n3', 'n1_as_1_in_n3'), ('n1', 'n3', 'n1_as_2_in_n3'), ('n1', 'n4', 'n1_as_0_in_n4'), ('n1', 'n4', 'n1_as_1_in_n4'), ('n1', 'n4', 'n1_as_2_in_n4'), ('n1', 'n4', 'n1_as_3_in_n4'), ('n1', 'n4_improper', 'n1_as_0_in_n4_improper'), ('n1', 'n4_improper', 'n1_as_1_in_n4_improper'), ('n1', 'n4_improper', 'n1_as_2_in_n4_improper'), ('n1', 'n4_improper', 'n1_as_3_in_n4_improper'), ('n1', 'nonbonded', 'n1_as_0_in_nonbonded'), ('n1', 'nonbonded', 'n1_as_1_in_nonbonded'), ('n1', 'onefour', 'n1_as_0_in_onefour'), ('n1', 'onefour', 'n1_as_1_in_onefour'), ('n1', 'g', 'n1_in_g'), ('n1', 'n1', 'n1_neighbors_n1'), ('n2', 'n3', 'n2_as_0_in_n3'), ('n2', 'n3', 'n2_as_1_in_n3'), ('n2', 'n4', 'n2_as_0_in_n4'), ('n2', 'n4', 'n2_as_1_in_n4'), ('n2', 'n4', 'n2_as_2_in_n4'), ('n2', 'n1', 'n2_has_0_n1'), ('n2', 'n1', 'n2_has_1_n1'), ('n2', 'g', 'n2_in_g'), ('n3', 'n4', 'n3_as_0_in_n4'), ('n3', 'n4', 'n3_as_1_in_n4'), ('n3', 'n1', 'n3_has_0_n1'), ('n3', 'n1', 'n3_has_1_n1'), ('n3', 'n1', 'n3_has_2_n1'), ('n3', 'n2', 'n3_has_0_n2'), ('n3', 'n2', 'n3_has_1_n2'), ('n3', 'g', 'n3_in_g'), ('n4', 'n1', 'n4_has_0_n1'), ('n4', 'n1', 'n4_has_1_n1'), ('n4', 'n1', 'n4_has_2_n1'), ('n4', 'n1', 'n4_has_3_n1'), ('n4', 'n2', 'n4_has_0_n2'), ('n4', 'n2', 'n4_has_1_n2'), ('n4', 'n2', 'n4_has_2_n2'), ('n4', 'n3', 'n4_has_0_n3'), ('n4', 'n3', 'n4_has_1_n3'), ('n4', 'g', 'n4_in_g'), ('n4_improper', 'n1', 'n4_improper_has_0_n1'), ('n4_improper', 'n1', 'n4_improper_has_1_n1'), ('n4_improper', 'n1', 'n4_improper_has_2_n1'), ('n4_improper', 'n1', 'n4_improper_has_3_n1'), ('n4_improper', 'g', 'n4_improper_in_g'), ('nonbonded', 'n1', 'nonbonded_has_0_n1'), ('nonbonded', 'n1', 'nonbonded_has_1_n1'), ('nonbonded', 'g', 'nonbonded_in_g'), ('onefour', 'n1', 'onefour_has_0_n1'), ('onefour', 'n1', 'onefour_has_1_n1'), ('onefour', 'g', 'onefour_in_g')])
>>> openmm_system = esp.graphs.deploy.openmm_system_from_graph(molecule_graph)
>>> print(openmm_system)
<openmm.openmm.System; proxy of <Swig Object of type 'OpenMM::System *' at 0x1d7fbe160> >
beavenah commented 2 months ago

I have one more question -- let me know if I should open a new issue... Seems basic, but I haven't been able to get it to work out. I want to write the force field information in GROMACS format, which I figure should be done via Interchange.

>>> import torch
>>> import espaloma as esp
>>> from openff.toolkit import Molecule, Topology, ForceField
>>> from openff.interchange import Interchange

>>> molecule = Molecule.from_smiles("CN1C=NC2=C1C(=O)N(C(=O)N2C)C")
>>> topology = Topology.from_molecules([molecule])
>>> molecule_graph = esp.Graph(molecule)
>>> espaloma_model = torch.load("/Users/abeaven/Downloads/espaloma-latest.pt")
>>> espaloma_model.eval()
>>> espaloma_model(molecule_graph.heterograph)
>>> openmm_system = esp.graphs.deploy.openmm_system_from_graph(molecule_graph)

**>>> Interchange.from_openmm()
>>> Interchange.to_gro(topology, ...)
>>> Interchange.to_top(topology, ...)**

I'm unsure of what I should do to correctly Interchange here. Thanks again for all of the help!

mikemhenry commented 2 months ago

@mattwthompson might have the answer

mattwthompson commented 2 months ago

Hey @beavenah,

It looks like you're on the right track, but

beavenah commented 2 months ago

Thank you, @mikemhenry and @mattwthompson! It appears that I have a functional script based on other GitHub discussions I've seen... But, I'll still plan to open a new discussion at the openFF GitHub. I'll just check a few more things on my end first.