AxisSelectionConfigurator.py 3.67 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 and Bachir Aoun
31
32
'''

33
from MDANSE.Framework.UserDefinitionsStore import UD_STORE, UserDefinitionsStoreError
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
    To Build an axis selection from the GUI you have to :
44
45
46
47
    
    * Create a workspace based on a mmtk_trajectory data,
    * Drag a molecular viewer on it,
    * Drag into the Molecular Viewer the Axis selection plugin
48
49

    :note: this configurator depends on 'trajectory' configurator to be configured
50
51
52
53
54
55
56
    """
    
    type = "axis_selection"
    
    _default = None

    def configure(self, configuration, value):
57
        '''
58
59
60
        Configure an input value. 
        
        The value can be:
61
62
        
        * a dict with 'molecule', 'endpoint1' and 'endpoint2' keys. 'molecule' key 
63
64
65
        is the molecule name 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  
66
        * str: the axis selection will be performed by reading the corresponding user definition
67
68
69
70
71
72
        
        :param configuration: the current configuration
        :type configuration: a MDANSE.Framework.Configurable.Configurable object
        :param value: the input value
        :type value: tuple or str 
        '''
73
74
75
        
        trajConfig = configuration[self._dependencies['trajectory']]
                
76
77
78
        try: 
            ud = UD_STORE[trajConfig["basename"],"axis_selection",value]
        except UserDefinitionsStoreError:
79
            self.update(value)
80
81
        else:
            self.update(ud)
82
83
84
85
86
87
88
89
90
91
92

        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):
93
        '''
94
        Returns some informations about this configurator.
95
96
97
98
        
        :return: the information about this configurator
        :rtype: str
        '''
99
100
        
        return "Axis vector:%s" % self["value"]