Git Product home page Git Product logo

Comments (3)

Luthaf avatar Luthaf commented on June 10, 2024

I am a bit reluctant to change the strings in PERIODIC_INFORMATION, as they come from an external source of data (https://svn.code.sf.net/p/bodr/code/trunk/bodr/elements/elements.xml). At the same time, this information should not change often ^^

Maybe normalizing strings to an "Atom Case" before searching would be enough? c => C, ZN => Zn, ...

from chemfiles.

pgbarletta avatar pgbarletta commented on June 10, 2024

Something like this

  //! Set the atom type
    void set_type(std::string type) { 
      if (type.length() == 2) {
        type[0] = toupper(type[0]);
        type[1] = tolower(type[1]);
      }
      type_ = std::move(type); 
    }
  • In Atom.hpp ?
  • In the Atom constructor from Atom.cpp ?
  • or read_ATOM from PDB.cpp ?

I was thinking of including it in set_type from Atom.hpp and moving the definition of the function to Atom.cpp, since the Atom constructor uses a nice intialization list to set the type variable. It also allows to construct Atom objects using the capitalization the user prefers, without overriding it. I don't know if this is a desired feature.

Again, sorry for taking so long for such a few lines of code.

from chemfiles.

Luthaf avatar Luthaf commented on June 10, 2024

In Atom.hpp ?
In the Atom constructor from Atom.cpp ?
or read_ATOM from PDB.cpp ?

I would prefer not to modify the types stored in Atom, but rather the matching function. Replacing all the lines like this in Atom.cpp

auto periodic = PERIODIC_INFORMATION.find(type_);

With something like this:

optional<ElementData> find_periodic_information(const std::string& type) {
    auto normalized_type = type;    
    if (normalized_type.length() == 2) {
        normalized_type[0] = toupper(normalized_type[0]);
        normalized_type[1] = tolower(normalized_type[1]);
    }
    // Do the search
};


// ...

auto periodic = find_periodic_information(type_);

With maybe some more clever tricks to prevent the copies. Using a custom comparison function may do the trick, we should try.

from chemfiles.

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.