InterpolationOrderConfigurator.py 3.61 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#MDANSE : Molecular Dynamics Analysis for Neutron Scattering Experiments
#------------------------------------------------------------------------------------------
#Copyright (C)
#2015- Eric C. Pellegrini Institut Laue-Langevin
#BP 156
#6, rue Jules Horowitz
#38042 Grenoble Cedex 9
#France
#pellegrini[at]ill.fr
#goret[at]ill.fr
#aoun[at]ill.fr
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Lesser General Public
#License as published by the Free Software Foundation; either
#version 2.1 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#Lesser General Public License for more details.
#
#You should have received a copy of the GNU Lesser General Public
#License along with this library; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

''' 
Created on Mar 30, 2015

30
:author: Eric C. Pellegrini
31
32
33
'''

from MDANSE.Framework.Configurators.IConfigurator import ConfiguratorError
34
from MDANSE.Framework.Configurators.SingleChoiceConfigurator import SingleChoiceConfigurator
35
            
36
class InterpolationOrderConfigurator(SingleChoiceConfigurator):
37
    """
38
    This configurator allows to input the interpolation order to be applied when deriving velocities from atomic coordinates.
39

40
41
    The allowed value are *'no interpolation'*,*'1st order'*,*'2nd order'*,*'3rd order'*,*'4th order'* or *'5th order'*, the 
    former one will not interpolate the velocities from atomic coordinates but will directly use the velocities stored in the trajectory file.
eric pellegrini's avatar
eric pellegrini committed
42
    
43
44
    :attention: it is of paramount importance for the trajectory to be sampled with a very low time \
    step to get accurate velocities interpolated from atomic coordinates. 
eric pellegrini's avatar
eric pellegrini committed
45
46

    :note: this configurator depends on 'trajectory' configurator to be configured.
47
48
49
50
    """
    
    type = "interpolation_order"
    
51
    _default = "no interpolation"
52
53
        
    def __init__(self, name, orders=None,**kwargs):
54
55
56
        '''
        Initializes the configurator.
        
57
        :param name: the name of the configurator as it will appear in the configuration.
58
59
        :type name: str.
        '''
60
61
62

        if orders is None:
            orders = ["no interpolation","1st order","2nd order","3rd order","4th order","5th order"] 
63
                
64
        SingleChoiceConfigurator.__init__(self, name, choices=orders, **kwargs)
65
66

    def configure(self, configuration, value):
67
68
69
70
        '''
        Configure the input interpolation order.
                
        :param configuration: the current configuration.
71
        :type configuration: MDANSE.Framework.Configurable.Configurable
72
        :param value: the interpolation order to be configured.
73
        :type value: str one of *'no interpolation'*,*'1st order'*,*'2nd order'*,*'3rd order'*,*'4th order'* or *'5th order'*.
74
        '''
75
        
76
        SingleChoiceConfigurator.configure(self, configuration, value)
77
        
78
        if value == "no interpolation":
79
80
81
82
83
84
85
86
87
88

            trajConfig = configuration[self._dependencies['trajectory']]

            if not "velocities" in trajConfig['instance'].variables():
                raise ConfiguratorError("the trajectory does not contain any velocities. Use an interpolation order higher than 0", self)
            
            self["variable"] = "velocities"
            
        else:

89
            self["variable"] = "configuration"