BasisSelectionConfigurator.py 3.8 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 BasisSelection(IConfigurator):
    """
39
40
41
42
    This configurator allows to define a local basis per molecule. 
    
    For each molecule, the basis is defined using the coordinates of three atoms of the molecule. 
    These coordinates will respectively define the origin, the X axis and y axis of the basis, the 
43
    Z axis being latter defined in such a way that the basis is direct.     
44
45
46
47
48
49
50
    """
    
    type = 'basis_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'*, *'origin'*, *'x_axis'* and *'y_axis'* keys. *'molecule'* key is \
        the name of the molecule for which the axis selection will be performed and *'origin'*, *'x_axis'* and *'y_axis'* \
        keys are the names of three atoms of the molecule that will be used to define respectively the origin, the X and Y axis of the basis  
        #. 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
66
67
68
        :param value: the input value
        :type value: tuple or str 

        :note: this configurator depends on 'trajectory' configurator to be configured
        '''

69
        trajConfig = configuration[self._dependencies['trajectory']]
70
            
71
72
        if UD_STORE.has_definition(trajConfig["basename"],"basis_selection",value): 
            ud = UD_STORE.get_definition(trajConfig["basename"],"basis_selection",value)
73
            self.update(ud)
74
75
        else:
            self.update(value)
76
                
77
78
79
80
81
82
83
84
85
86
87
        e1 = find_atoms_in_molecule(trajConfig['instance'].universe,self['molecule'], self['origin'], True)
        e2 = find_atoms_in_molecule(trajConfig['instance'].universe,self['molecule'], self['x_axis'], True)
        e3 = find_atoms_in_molecule(trajConfig['instance'].universe,self['molecule'], self['y_axis'], True)
        
        self["value"] = value
        
        self['basis'] = zip(e1,e2,e3)      
        
        self['n_basis'] = len(self['basis'])

    def get_information(self):
88
        '''
89
        Returns some informations about this configurator.
90
91
92
93
        
        :return: the information about this configurator
        :rtype: str
        '''
94
95
        
        return "Basis vector:%s" % self["value"]