Code Monkey home page Code Monkey logo

Comments (10)

ctk3b avatar ctk3b commented on July 3, 2024

I think an easy way would be to add an optional flag to this that dictates whether elements should be assigned or the name taken as is.

from foyer.

summeraz avatar summeraz commented on July 3, 2024

It could be as easy as changing
element = elem.Element.getBySymbol(mb_particle.name)
to

try:
    element = elem.Element.getBySymbol(mb_particle.name)
except KeyError:
    element = mb_particle.name

From some quick testing it looks that openmm Atoms can have arbitrary element names.

from foyer.

ctk3b avatar ctk3b commented on July 3, 2024

True, but we don't want to fail silently.

from foyer.

summeraz avatar summeraz commented on July 3, 2024

We could include a flag in the except block that raises a warning after the topology has been built that warns the user that the element names for some particles could not be interpreted

from foyer.

ctk3b avatar ctk3b commented on July 3, 2024

That should also be ok. Make sure you actually create a new OpenMM Atom object though instead of just using the string.

Also I would recommend adding a little cache like here so that the user doesn't get spammed with warnings for every instance of a missing atom name.

from foyer.

summeraz avatar summeraz commented on July 3, 2024

Right, I was planning on just providing a single warning after the topology has been built.

from foyer.

summeraz avatar summeraz commented on July 3, 2024

Any ideas on how to load a force field with atomtypes that contain non-periodic table element names? I think I've almost got it working if I can figure that part out.

It looks like atomtypes are loaded using this function, which calls a function of the same name in OpenMM. Currently if an atomtype is not one of those in the periodic table, then a KeyError is generated when a periodic table look-up is attempted by OpenMM.

My current line of thinking is doing something like this

def registerAtomType(self, parameters):
    actual_element = parameters['element']
    parameters['element'] = 'H'
    super(Forcefield, self).registerAtomType(parameters)
    # Somehow access the atomtype we just loaded in and change the element name to actual_element

I'm just not sure how to access the atomtype that has just been loaded to change the element name.

from foyer.

ctk3b avatar ctk3b commented on July 3, 2024

This is the OpenMM function where that happens. You can either replicate this function entirely on our end and remove the super() or see if you can edit self._atomTypes and change the name of the specific one after creation.

from foyer.

summeraz avatar summeraz commented on July 3, 2024

Cool, yeah it looks like editing self._atomTypes[parameters['name']].element should do the trick

from foyer.

ctk3b avatar ctk3b commented on July 3, 2024

Preliminarily implemented

from foyer.

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.