criosx / molgroups

Composition space modeling for scattering data analysis
MIT License
2 stars 0 forks source link

General refactoring: numpy arrays for calculation, and intermediate composite nSLDObj class #20

Closed hoogerheide closed 3 years ago

hoogerheide commented 3 years ago

Two major refactors here:

  1. All calculations now use numpy arrays on the entire area, nSL and nSLD profile. This results in a speed-up of about a factor of 30 for a raw call to a wrapper function for a BLM model.
  2. A CompositenSLDObj class was created as a base class for headgroups and bilayer models. A call in init to fnFindSubgroups now populates the object with subgroups which are automatically probed for their profiles, which are combined into the composite object profile. This change results in about 1/3 the code length for these objects.

From an email to @criosx : There are four major changes that we need to be aware of:

  1. In the init for the BLM models, there’s now a new “fnFindSubgroups” that populates an internal list with subgroups. It’s a little hackish right now and could maybe be improved in the future.
  2. For all nSLDObj, init can take a “name” variable. This is now used in writing the parameter data to the data file. In other words, the name of each group is stored in its object. In the init of the BLM models, for example, you’d have self.headgroup1 = PCm(name=’headgroup1’), and then every time that data are written for headgroup1, it uses the name (‘headgroup1’) as the group to be written. Note that a scheme like this would also allow us to have a description (i.e. “inner leaflet headgroup”) that could be used for pretty plotting. The "groups" attribute is no longer required after this change (thanks @mmeowo for the underlying idea).
  3. fnWriteProfile now takes z (a vector of all z positions to evaluate at, not necessarily evenly spaced) as an argument. If you optionally pass it aArea or anSL, it will add to them.
  4. I have modified Box2Err so that bProtonExchange remains False until nSL2 is set through fnSetnSL. If nSL2 is never set, proton exchange remains turned off. The upshot here is that to turn on proton exchange, all you have to do is set nSL2; all other groups remain unchanged by bulknsld (which is nonetheless passed to all of them).

Also: the speed_tests folder can be removed in a future change; it wasn't intended to end up here.

hoogerheide commented 3 years ago

I resolved the merge conflicts with the main branch so this should be good to go. Probably worth double-checking the PC headgroup geometry, though.

hoogerheide commented 3 years ago

I checked the PC definition and it looks consistent with main.