Skip to content

OpenMMException error under MacOS #5

Description

@PatWalters

I made this change in line 1167 of helper_functions.py

from:
model_dict = torch.load(model_path)["model"]
to:
model_dict = torch.load(model_path,map_location=torch.device('cpu'))["model"]

However, when I try to run, I then get this OpenMMException.

---------------------------------------------------------------------------
OpenMMException                           Traceback (most recent call last)
[/var/folders/0n/pn_zp11569sfv4m2w6gzpwyr0000gp/T/ipykernel_13815/2831125247.py](http://localhost:8875/var/folders/0n/pn_zp11569sfv4m2w6gzpwyr0000gp/T/ipykernel_13815/2831125247.py) in ?()
      5 mol = Chem.MolFromSmiles('COCCO')
      6 mol = Chem.AddHs(mol)
      7 AllChem.EmbedMultipleConfs(mol, numConfs=128)
      8 
----> 9 minimized_mol, energies = minimize_mol(mol,"DMSO")
     10 entropies, free_energies = calculate_entropy(minimized_mol,"DMSO")

[~/software/GNNImplicitSolvent/Simulation/helper_functions.py](http://localhost:8875/~/software/GNNImplicitSolvent/Simulation/helper_functions.py) in ?(mol, solvent, model_path, solvent_dict, return_traj, tolerance, max_iterations, gnn_sim, return_gnn_sim, strides, cache, save_name, partial_charges, forcefield, constraints)
    989     num_iters = strides
    990     num_confs = num_rep // strides
    991 
    992     if gnn_sim is None:
--> 993         gnn_sim = get_gnn_sim(
    994             mol=mol,
    995             solvent=solvent,
    996             model_path=model_path,

[~/software/GNNImplicitSolvent/Simulation/helper_functions.py](http://localhost:8875/~/software/GNNImplicitSolvent/Simulation/helper_functions.py) in ?(mol, solvent, model_path, solvent_dict, cache, save_name, partial_charges, forcefield, constraints, num_confs)
   1164             constraints=constraints,
   1165         )
   1166     else:
   1167         model_dict = torch.load(model_path,map_location=torch.device('cpu'))["model"]
-> 1168         gnn_sim = create_gnn_sim(
   1169             smiles,
   1170             cache=cache,
   1171             num_confs=num_confs,

[~/software/GNNImplicitSolvent/Simulation/helper_functions.py](http://localhost:8875/~/software/GNNImplicitSolvent/Simulation/helper_functions.py) in ?(smiles, cache, num_confs, workdir, run_name, save_name, rdkit_mol, solvent_dict, solvent, num_solvents, model_dict, solvent_model, solvent_dielectric, partial_charges, forcefield, constraints)
    818         constraints=constraints,
    819     )
    820 
    821     gnn_sim._ref_system.platform = "GPU"
--> 822     gnn_sim.setup_replicates(only_check_first=True)
    823     return gnn_sim

[~/software/GNNImplicitSolvent/Simulation/Simulator.py](http://localhost:8875/~/software/GNNImplicitSolvent/Simulation/Simulator.py) in ?(self, only_check_first)
   1590         # test whether forces are equal
   1591         self._ref_system.create_system()
   1592         self._ref_system.create_simulation(self._datahandler.positions)
   1593         self._ref_system.platform = "GPU"
-> 1594         ref_single_forces = self._ref_system.calculate_forces()
   1595 
   1596         # Create copies of the system
   1597         m = Modeller(self._datahandler.topology, self._datahandler.positions)

[~/software/GNNImplicitSolvent/Simulation/Simulator.py](http://localhost:8875/~/software/GNNImplicitSolvent/Simulation/Simulator.py) in ?(self, adapt_values, use_NN)
    788             radii_and_charge_data[:, 1] = scale
    789             if adapt_values:
    790                 self.adapt_values(radii_and_charge_data)
    791 
--> 792         forces = self._simulation.context.getState(getForces=True).getForces()
    793         x_forces = np.array([force[0] for force in forces._value])
    794         y_forces = np.array([force[1] for force in forces._value])
    795         z_forces = np.array([force[2] for force in forces._value])

[~/miniforge3/envs/GNNImplicitSolvent_run/lib/python3.10/site-packages/openmm/openmm.py](http://localhost:8875/~/miniforge3/envs/GNNImplicitSolvent_run/lib/python3.10/site-packages/openmm/openmm.py) in ?(self, getPositions, getVelocities, getForces, getEnergy, getParameters, getParameterDerivatives, getIntegratorParameters, enforcePeriodicBox, groups)
   2407         if getParameterDerivatives:
   2408             types += State.ParameterDerivatives
   2409         if getIntegratorParameters:
   2410             types += State.IntegratorParameters
-> 2411         state = _openmm.Context_getState(self, types, enforcePeriodicBox, groups_mask)
   2412         return state

OpenMMException: The following operation failed in the TorchScript interpreter.
Traceback of TorchScript, serialized code (most recent call last):
  File "code[/__torch__/MachineLearning/GNN_Models/___torch_mangle_10.py", line 391](http://localhost:8875/__torch__/MachineLearning/GNN_Models/___torch_mangle_10.py#line=390), in forward
      size_i0 = _115[0]
    x = torch.cat([x_i0, x_j0, edge_attributes1], 1)
    _145 = torch.add(torch.matmul(x, CONSTANTS.c14), CONSTANTS.c15)
                     ~~~~~~~~~~~~ <--- HERE
    x0 = torch.silu(_145)
    _146 = torch.add(torch.matmul(x0, CONSTANTS.c16), CONSTANTS.c17)

Traceback of TorchScript, original code (most recent call last):
RuntimeError: expected m1 and m2 to have the same dtype, but got: double != float

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions