AxisSelectionConfigurator.py 3.46 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: Bachir Aoun and Eric C. Pellegrini
31
32
'''

33
from MDANSE.Framework.UserDefinitionStore import UD_STORE
34
35
36
37
38
from MDANSE.Framework.Configurators.IConfigurator import IConfigurator
from MDANSE.MolecularDynamics.Trajectory import find_atoms_in_molecule
        
class AxisSelection(IConfigurator):
    """
39
40
41
    This configurator allows to define a local axis per molecule. 
    
    For each molecule, the axis is defined using the coordinates of two atoms of the molecule. 
42
    
43
    :note: this configurator depends on 'trajectory' configurator to be configured.
44
45
46
47
48
49
50
    """
    
    type = "axis_selection"
    
    _default = None

    def configure(self, configuration, value):
51
        '''
52
53
54
        Configure an input value. 
        
        The value can be:
55
        
56
57
58
59
        #. a dict with *'molecule'*, *'endpoint1'* and *'endpoint2'* keys. *'molecule'* key \
        is the name of the molecule for which the axis selection will be performed and *'endpoint1'* \
        and *'endpoint2'* keys are the names of two atoms of the molecule along which the axis will be defined  
        #. str: the axis selection will be performed by reading the corresponding user definition.
60
61
        
        :param configuration: the current configuration
62
        :type configuration: MDANSE.Framework.Configurable.Configurable
63
64
65
        :param value: the input value
        :type value: tuple or str 
        '''
66
67
68
        
        trajConfig = configuration[self._dependencies['trajectory']]
                
69
70
        if UD_STORE.has_definition(trajConfig["basename"],"axis_selection",value): 
            ud = UD_STORE.get_definition(trajConfig["basename"],"axis_selection",value)
71
            self.update(ud)
72
73
        else:
            self.update(value)
74
75
76
77
78
79
80
81
82
83
84

        e1 = find_atoms_in_molecule(trajConfig['instance'].universe,self['molecule'], self['endpoint1'], True)
        e2 = find_atoms_in_molecule(trajConfig['instance'].universe,self['molecule'], self['endpoint2'], True)

        self["value"] = value
          
        self['endpoints'] = zip(e1,e2)      
        
        self['n_axis'] = len(self['endpoints'])

    def get_information(self):
85
        '''
86
        Returns some informations about this configurator.
87
88
89
90
        
        :return: the information about this configurator
        :rtype: str
        '''
91
92
        
        return "Axis vector:%s" % self["value"]