Code Monkey home page Code Monkey logo

Comments (2)

hodakamori avatar hodakamori commented on July 24, 2024 1

Thank you for your response.
In my case, the ERROR catch looks good!

from openff-interchange.

mattwthompson avatar mattwthompson commented on July 24, 2024

You've pretty much found the API points that I would recommend1; under the hood, ForceField.label_molecules pretty much does the same stuff as creating an Interchange object (namely filling out the the collection classes). This can be simple or tricky depending on the level of granularity you're after

  • Rough pass: just see if the element(s) are in the force field at all
  • Slightly more detailed pass: wrap your second code block into a function and error out in some particular cases`
    • This doesn't work for all parameter handlers; for example, throwing an error if len(matches['Bonds']) < topology.n_bonds is probably good, but the same logic for improper torsions would not work.
    • The logic within Interchange is around here
  • Depending on the application, it might be easiest to just go Grace Hopper style and ask for forgiveness instead of permission
try:
    force_field.create_interchange(...)
# there are a few different exceptions that can be thrown here - this base class captures if bond/angle/torsion parameters are missing
except (UnassignedValenceParameterException, ...):
    # deal with it here - log, re-raise exception, etc.

In the case of molecular iodine, it seems like the thrown error is pretty much getting what you're asking for. Are there other cases that are tricker to deal with?

Footnotes

  1. I planned to point you to this example, but it looks like you've already come across it

from openff-interchange.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.