Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scientific Software
MDANSE
Commits
1472708f
Commit
1472708f
authored
Jul 09, 2015
by
eric pellegrini
Browse files
Small changes in a few configurators
parent
b8e1e865
Changes
3
Show whitespace changes
Inline
Side-by-side
MDANSE/Framework/Configurators/AtomsListConfigurator.py
View file @
1472708f
...
@@ -30,10 +30,6 @@ Created on Mar 30, 2015
...
@@ -30,10 +30,6 @@ Created on Mar 30, 2015
:author: Eric C. Pellegrini
:author: Eric C. Pellegrini
'''
'''
import
collections
import
numpy
from
MDANSE.Framework.UserDefinitionsStore
import
UD_STORE
from
MDANSE.Framework.UserDefinitionsStore
import
UD_STORE
from
MDANSE.Framework.Configurators.IConfigurator
import
IConfigurator
from
MDANSE.Framework.Configurators.IConfigurator
import
IConfigurator
from
MDANSE.MolecularDynamics.Trajectory
import
find_atoms_in_molecule
from
MDANSE.MolecularDynamics.Trajectory
import
find_atoms_in_molecule
...
@@ -98,72 +94,6 @@ class AtomsListConfigurator(IConfigurator):
...
@@ -98,72 +94,6 @@ class AtomsListConfigurator(IConfigurator):
self
[
'n_values'
]
=
len
(
self
[
'atoms'
])
self
[
'n_values'
]
=
len
(
self
[
'atoms'
])
@
staticmethod
def
find_parent
(
atom
,
level
):
'''
Retrieve recursively the parent of a given MMTK atom at a given level.
For example, a level of 1 will return the direct parent of the atom.
:note: this is a static method
:param atom: the atom for which the parent is searched for
:type atom: MMTK.Atom object
:param level: the level of the parent
:type level: int
'''
for
_
in
range
(
level
):
atom
=
atom
.
parent
return
atom
def
group
(
self
,
atoms
,
level
=
"atom"
):
'''
Group the selected atoms according to a given granularity and update
the configurator with the grouping results.
:param atoms: the atoms for
:type atoms: list of MMTK.Atom
:param level: the level of granularity at which the atoms should be grouped
:type level: str
'''
groups
=
collections
.
OrderedDict
()
for
at
in
atoms
:
lvl
=
LEVELS
[
level
][
at
.
topLevelChemicalObject
().
__class__
.
__name__
.
lower
()]
parent
=
self
.
find_parent
(
at
,
lvl
)
groups
.
setdefault
(
parent
,[]).
append
(
at
.
index
)
self
[
"groups"
]
=
groups
.
values
()
self
[
"n_groups"
]
=
len
(
self
[
"groups"
])
if
level
!=
"atom"
:
self
[
"elements"
]
=
[[
"dummy"
]]
*
self
[
"n_groups"
]
self
[
"level"
]
=
level
self
.
set_contents
()
def
set_contents
(
self
):
'''
Sets the contents of the atom selection.
'''
self
[
"contents"
]
=
collections
.
OrderedDict
()
self
[
'index_to_symbol'
]
=
collections
.
OrderedDict
()
for
i
,
group
in
enumerate
(
self
[
"elements"
]):
for
j
,
el
in
enumerate
(
group
):
self
[
"contents"
].
setdefault
(
el
,[]).
append
(
self
[
"groups"
][
i
][
j
])
self
[
'index_to_symbol'
][
self
[
"groups"
][
i
][
j
]]
=
el
for
k
,
v
in
self
[
"contents"
].
items
():
self
[
"contents"
][
k
]
=
numpy
.
array
(
v
,
dtype
=
numpy
.
int32
)
self
[
"n_atoms_per_element"
]
=
dict
([(
k
,
len
(
v
))
for
k
,
v
in
self
[
"contents"
].
items
()])
self
[
'n_selected_elements'
]
=
len
(
self
[
"contents"
])
def
get_information
(
self
):
def
get_information
(
self
):
'''
'''
Returns some informations the atom selection.
Returns some informations the atom selection.
...
@@ -172,13 +102,10 @@ class AtomsListConfigurator(IConfigurator):
...
@@ -172,13 +102,10 @@ class AtomsListConfigurator(IConfigurator):
:rtype: str
:rtype: str
'''
'''
if
not
self
.
has_key
(
"
n_selected_
atoms"
):
if
not
self
.
has_key
(
"atoms"
):
return
"No configured yet"
return
"No configured yet"
info
=
[]
info
=
[]
info
.
append
(
"Number of selected atoms:%d"
%
self
[
"n_selected_atoms"
])
info
.
append
(
"Number of selected %d-tuplets:%d"
%
(
self
.
_nAtoms
,
self
[
"n_values"
]))
info
.
append
(
"Level of selection:%s"
%
self
[
"level"
])
info
.
append
(
"Number of selected groups:%d"
%
self
[
"n_groups"
])
info
.
append
(
"Selected elements:%s"
%
self
[
"contents"
].
keys
())
return
"
\n
"
.
join
(
info
)
return
"
\n
"
.
join
(
info
)
\ No newline at end of file
MDANSE/Framework/Configurators/InterpolationOrderConfigurator.py
View file @
1472708f
...
@@ -50,9 +50,7 @@ class InterpolationOrderConfigurator(SingleChoiceConfigurator):
...
@@ -50,9 +50,7 @@ class InterpolationOrderConfigurator(SingleChoiceConfigurator):
_default
=
"no interpolation"
_default
=
"no interpolation"
orders
=
[
"no interpolation"
,
"1st order"
,
"2nd order"
,
"3rd order"
,
"4th order"
,
"5th order"
]
def
__init__
(
self
,
name
,
orders
=
None
,
**
kwargs
):
def
__init__
(
self
,
name
,
**
kwargs
):
'''
'''
Initializes the configurator.
Initializes the configurator.
...
@@ -60,7 +58,10 @@ class InterpolationOrderConfigurator(SingleChoiceConfigurator):
...
@@ -60,7 +58,10 @@ class InterpolationOrderConfigurator(SingleChoiceConfigurator):
:type name: str.
:type name: str.
'''
'''
SingleChoiceConfigurator
.
__init__
(
self
,
name
,
choices
=
InterpolationOrderConfigurator
.
orders
,
**
kwargs
)
if
orders
is
None
:
orders
=
[
"no interpolation"
,
"1st order"
,
"2nd order"
,
"3rd order"
,
"4th order"
,
"5th order"
]
SingleChoiceConfigurator
.
__init__
(
self
,
name
,
choices
=
orders
,
**
kwargs
)
def
configure
(
self
,
configuration
,
value
):
def
configure
(
self
,
configuration
,
value
):
'''
'''
...
...
MDANSE/Framework/Configurators/OutputFilesConfigurator.py
View file @
1472708f
...
@@ -63,7 +63,7 @@ class OutputFilesConfigurator(IConfigurator):
...
@@ -63,7 +63,7 @@ class OutputFilesConfigurator(IConfigurator):
IConfigurator
.
__init__
(
self
,
name
,
**
kwargs
)
IConfigurator
.
__init__
(
self
,
name
,
**
kwargs
)
self
.
_formats
=
formats
if
formats
is
not
None
else
[
"netcdf"
]
self
.
_formats
=
formats
if
formats
is
not
None
else
OutputFilesConfigurator
.
_default
[
2
]
def
configure
(
self
,
configuration
,
value
):
def
configure
(
self
,
configuration
,
value
):
'''
'''
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment