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

SMIRNOFFElectrostaticsCollection.charges does not report cached charges #1052

Closed
mattwthompson opened this issue Sep 18, 2024 · 0 comments · Fixed by #1066
Closed

SMIRNOFFElectrostaticsCollection.charges does not report cached charges #1052

mattwthompson opened this issue Sep 18, 2024 · 0 comments · Fixed by #1066
Labels
bug Something isn't working

Comments

@mattwthompson
Copy link
Member

Using 0.4.0beta1, the .charges attribute does not properly route to the cached charges. I think this is due to a misconfiguration of the Pydantic model.

Run part of the README example:

In [1]: from openff.toolkit import ForceField, Molecule
   ...: from openff.units import unit
   ...:
   ...: from openff.interchange import Interchange
   ...:
   ...:
   ...: # Use the OpenFF Toolkit to generate a molecule object from a SMILES pattern
   ...: molecule = Molecule.from_smiles("CCO")
   ...:
   ...: # Generate a conformer to be used as atomic coordinates
   ...: molecule.generate_conformers(n_conformers=1)
   ...:
   ...: # Convert this molecule to a topology
   ...: topology = molecule.to_topology()
   ...:
   ...: # Define periodicity via box vectors
   ...: topology.box_vectors = unit.Quantity([4, 4, 4], unit.nanometer)
   ...:
   ...: # Load OpenFF 2.0.0 "Sage"
   ...: sage = ForceField("openff-2.0.0.offxml")
   ...:
   ...: # Create an Interchange object
   ...: out = Interchange.from_smirnoff(force_field=sage, topology=topology)
/Users/mattthompson/micromamba/envs/new-models/lib/python3.11/site-packages/foyer/forcefield.py:33: UserWarning: Module openff was already imported from None, but /Users/mattthompson/software/openff-interchange is being added to sys.path
  from pkg_resources import iter_entry_points, resource_filename
/Users/mattthompson/micromamba/envs/new-models/lib/python3.11/site-packages/mdtraj/formats/__init__.py:13: DeprecationWarning: 'xdrlib' is deprecated and slated for removal in Python 3.13
  from mdtraj.formats.trr import TRRTrajectoryFile

Look at the public and private attributes which report charges:

In [2]: out['Electrostatics'].charges
Out[2]: {}

In [3]: out['Electrostatics']._get_charges()
Out[3]:
{TopologyKey with atom indices (0,): -0.13610011111111114 <Unit('elementary_charge')>,
 TopologyKey with atom indices (1,): 0.12639988888888887 <Unit('elementary_charge')>,
 TopologyKey with atom indices (2,): -0.5998001111111111 <Unit('elementary_charge')>,
 TopologyKey with atom indices (3,): 0.04236688888888887 <Unit('elementary_charge')>,
 TopologyKey with atom indices (4,): 0.04236688888888887 <Unit('elementary_charge')>,
 TopologyKey with atom indices (5,): 0.04236688888888887 <Unit('elementary_charge')>,
 TopologyKey with atom indices (6,): 0.04319988888888887 <Unit('elementary_charge')>,
 TopologyKey with atom indices (7,): 0.04319988888888887 <Unit('elementary_charge')>,
 TopologyKey with atom indices (8,): 0.3959998888888889 <Unit('elementary_charge')>}

In [4]: out['Electrostatics'].charges
Out[4]: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant