Coder Social home page Coder Social logo

mm's People

Contributors

franciscoadasme avatar

Watchers

 avatar

mm's Issues

Relax type restriction on ParameterSet#<<

The type restriction on the method ParameterSet#<<(Array(DihedralType)) should be changed to Enumerable(DihedralType), otherwise Array::View(DihedralType) (returned by ParameterSet#dihedrals) doesn't work. This will require to transform the argument to an array via #to_a before adding it to the internal array of dihedrals.

Missing parameters does not work properly

In the promp.cr module, the prompt_matching_param requiere two changes. To erase the puts at the end of the function and to change the return_type from Array(DihedralType) to Array::View(DihedralType) those are the changes:

module MM
  {% for type in %w(bond angle dihedral improper).map(&.id) %}
    {% return_type = type == "dihedral" ? Array::View(DihedralType) : "#{type.camelcase}Type".id %}
    def self.prompt_matching_param(
      params : ParameterSet,
      conn : Chem::{{type.camelcase}}
    ) : {{return_type}}?
      printf "Missing %s between %s [%s]\n",
        conn.class.name.split("::").last.underscore.split('_').first,
        conn.atoms.join(", "),
        conn.atoms.join('-', &.type),

      matching_params = params.fuzzy_search(conn)
      case matching_params.size
      when 0
        puts "No matching paramater found"
        prompt_exit
      when 1
        param = matching_params[0]
        param = param[0] unless param.is_a?(MM::ParameterType)
        puts "Found match #{param.typenames.join('-')}"
        matching_params[0]
      else
        prompt_match(matching_params)
      end
      #puts
    end
  {% end %}
end

Improve handling of missing parameters

Right now, it's cumbersome to find and add missing parameters due to the type system, for instance, the following example doesn't compile due to type mismatch for typenames:

conns = params.detect_missing(topology)
conns.each do |conn|
  if params = MM.prompt_matching_param(params, conn)
    params << param.copy_with(typenames: conn.atoms.map(&.type.not_nil!))
  end
end

One solution to circumvent the compiler check is to enumerate all valid possibilities via a case statement:

conns = params.detect_missing(topology)
conns.each do |conn|
  case {param = MM.prompt_matching_param(params, conn), conn}
  when {MM::BondType, Chem::Bond}
    params << param.copy_with(typenames: conn.atoms.map(&.type.not_nil!))
  when {MM::AngleType, Chem::Angle}
    params << param.copy_with(typenames: conn.atoms.map(&.type.not_nil!))
  when {Enumerable(MM::DihedralType), Chem::Dihedral}
    params << param.map(&.copy_with(typenames: conn.atoms.map(&.type.not_nil!)))
  when {MM::ImproperType, Chem::Improper}
    params << param.copy_with(typenames: conn.atoms.map(&.type.not_nil!))
  end
end

There should be a easier alternative to do the above.

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.