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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# The standard imports.
import abc
import ast
import collections
import operator
import os
import re
import subprocess
import time
# The numpy imports.
import numpy
from Scientific.IO.NetCDF import NetCDFFile
from Scientific.Geometry import Vector
# The mmtk imports.
from MMTK.Trajectory import Trajectory, TrajectorySet
# The nmoldyn imports.
from nMOLDYN import ELEMENTS, LOGGER, PLATFORM, PREFERENCES, REGISTRY, USER_DEFINITIONS
from nMOLDYN.Core.Error import Error
from nMOLDYN.Core.Platform import PlatformError
from nMOLDYN.Framework.ExtendableObject import ExtendableObject
from nMOLDYN.Framework.Selectors.Selectors import SelectionParser
from nMOLDYN.Framework.UserDefinable.UserDefinable import UserDefinitionsError
from nMOLDYN.Mathematics.Arithmetic import ComplexNumber
from nMOLDYN.Mathematics.Signal import INTERPOLATION_ORDER
from nMOLDYN.Utilities.MolecularDynamics import find_atoms_in_molecule
LEVELS = collections.OrderedDict()
LEVELS["atom"] = {"atom" : 0, "atomcluster" : 0, "molecule" : 0, "nucleotidechain" : 0, "peptidechain" : 0, "protein" : 0}
LEVELS["group"] = {"atom" : 0, "atomcluster" : 1, "molecule" : 1, "nucleotidechain" : 1, "peptidechain" : 1, "protein" : 1}
LEVELS["residue"] = {"atom" : 0, "atomcluster" : 1, "molecule" : 1, "nucleotidechain" : 2, "peptidechain" : 2, "protein" : 2}
LEVELS["chain"] = {"atom" : 0, "atomcluster" : 1, "molecule" : 1, "nucleotidechain" : 3, "peptidechain" : 3, "protein" : 3}
LEVELS["molecule"] = {"atom" : 0, "atomcluster" : 1, "molecule" : 1, "nucleotidechain" : 3, "peptidechain" : 3, "protein" : 4}
class ConfigurationError(Error):
pass
class ConfiguratorError(Error):
def __init__(self, message, configurator=None):
self._message = message
self._configurator = configurator
def __str__(self):
if self._configurator is not None:
self._message = "%r --> %s" % (self._configurator.name,self._message)
return self._message
@property
def configurator(self):
return self._configurator
# class Configuration(object):
#
# def __init__(self, configurators):
#
# self._configurators = configurators
#
# self._parameters = None
#
# self._state = {}
#
# def __getitem__(self, name):
#
# if self._configurators.has_key(name):
# return self._state.setdefault(name,{})
#
# raise ConfigurationError("The item %r is not registered in the configuration." % name)
#
# @property
# def configurators(self):
# return self._configurators
#
# def configure(self):
#
# if self._parameters is None:
# raise ConfigurationError("The configuration parameters was not set")
#
# LOGGER('')
#
# LOGGER('Setting up configuration ...')
#
# toBeConfigured = set(self._configurators.keys())
# configured = set()
#
# while toBeConfigured != configured:
#
# progress = False
#
# for name,conf in self._configurators.items():
#
# if name in configured:
# continue
#
# if conf.check_dependencies(configured):
#
# conf.configure(self,self._parameters.get(name,conf.default))
#
# LOGGER("Successfully configured: %s" % name)
#
# configured.add(name)
#
# progress = True
#
# if not progress:
# raise ConfigurationError("Circular or unsatisfiable dependencies when setting up configuration.")
#
# LOGGER('')
#
# def format(self, title=None, prefix='', suffix='', sep="=", join=False):
# """
# format the job parameters info in a string, used in logger.\n
# :Parameters:
# #. title (str): The job info title.
# #. prefix (str): The info prefix.
# #. suffix (str): The info suffix.
# #. sep (str): The info separator.
# #. join (str): Flag to join infos.
# :Returns:
# #. info (string): The job info.\n
# """
#
# maxLength = max([len(k) for k in self._parameters.keys()])
#
# info = ['%s%-*s %s %s' % (prefix,maxLength,k,sep,v) for k,v in self._parameters.items()]
#
# if title is not None:
# info.insert(0,'%s%s' % (prefix,title))
#
# if join:
# info = suffix.join(info)
#
# return str(info)
#
# def get_configurators(self):
#
# return self._configurators
#
# def get_parameters(self):
#
# return self._parameters
#
# @property
# def parameters(self):
#
# return self._parameters
#
# @parameters.setter
# def parameters(self,parameters=None):
#
# self.set_parameters(parameters)
#
# def reset(self):
#
# self._parameters = {}
# self._state = {}
#
# def set_parameters(self,parameters=None):
#
# self.reset()
#
# if parameters is None:
# parameters = {}
#
# if isinstance(parameters,dict):
# for k,v in self._configurators.items():
# self._parameters[k] = parameters.get(k,v.default)
# else:
# raise ConfigurationError("Invalid type for configuration parameters")
class Configurator(dict):
__metaclass__ = ExtendableObject
_default = None
_doc_ = "undocumented"
type = None
def __init__(self, name, dependencies=None, default=None, label=None, widget=None):
self._name = name
self._dependencies = dependencies if dependencies is not None else {}
self._default = default if default is not None else self.__class__._default
self._label = label if label is not None else " ".join(name.split('_')).strip()
self._widget = widget if widget is not None else self.type
@property
def default(self):
return self._default
@property
def dependencies(self):
return self._dependencies
@property
def label(self):
return self._label
@property
def name(self):
return self._name
@property
def widget(self):
return self._widget
@abc.abstractmethod
def configure(self, configuration, value):
pass
def add_dependency(self, name, conf):
if self._dependencies.has_key(name):
raise ConfiguratorError("The configurator %s already has %s dependency" % (self._name,name))
def check_dependencies(self, configured):
for c in self._dependencies.values():
if c not in configured:
return False
return True
@abc.abstractmethod
def get_information(self):
pass
class InputDirectoryConfigurator(Configurator):
"""
This Configurator allows to set as input an (existing) directory.
"""
type = "input_directory"
_default = PREFERENCES["working_directory"]
def configure(self, configuration, value):
value = PLATFORM.get_path(value)
if not os.path.exists(value):
raise ConfiguratorError('Invalid type for input value', self)
self['value'] = value
def get_information(self):
return "Input directory: %r" % self['value']
class OutputDirectoryConfigurator(Configurator):
"""
This Configurator allows to set an output directory.
"""
type = "output_directory"
_default = PREFERENCES["working_directory"]
def __init__(self, name, new=False, **kwargs):
Configurator.__init__(self, name, **kwargs)
self._new = new
def configure(self, configuration, value):
value = PLATFORM.get_path(value)
if self._new:
if os.path.exists(value):
raise ConfiguratorError("The output directory must not exist", self)
self['value'] = value
@property
def new(self):
return self._new
def get_information(self):
return "Output directory: %r" % self['value']
class PythonObjectConfigurator(Configurator):
"""
This Configurator allows to input any kind of basic python object.
"""
type = 'python_object'
_default = '""'
def configure(self, configuration, value):
value = ast.literal_eval(repr(value))
self['value'] = value
def get_information(self):
return "Python object: %r" % self['value']
class StringConfigurator(Configurator):
"""
This Configurator allows to input a String Value (sequence of unicode char).
"""
type = 'string'
_default = ""
def __init__(self, name, evalType=None, acceptNullString=True, **kwargs):
Configurator.__init__(self, name, **kwargs)
self._evalType = evalType
self._acceptNullString = acceptNullString
def configure(self, configuration, value):
value = str(value)
if not self._acceptNullString:
if not value:
raise ConfiguratorError("Null string not accepted", self)
if self._evalType is not None:
value = ast.literal_eval(value)
if not isinstance(value,self._evalType):
raise ConfiguratorError("Invalid type for the evaluated string", self)
self['value'] = value
@property
def acceptNullString(self):
return self._acceptNullString
@property
def evalType(self):
return self._evalType
def get_information(self):
return "Value: %r" % self['value']
class BooleanConfigurator(Configurator):
"""
This Configurator allows to input a Boolean Value (True or False).
"""
type = 'boolean'
_default = False
_shortCuts = {"true" : True, "yes" : True, "y" : True, "t" : True, "1" : True,
"false" : False, "no" : False, "n" : False, "f" : False, "0" : False}
def configure(self, configuration, value):
if hasattr(value,"lower"):
value = value.lower()
if not self._shortCuts.has_key(value):
raise ConfiguratorError('Invalid boolean string', self)
value = bool(value)
self['value'] = value
def get_information(self):
return "Value: %r" % self['value']
class SingleChoiceConfigurator(Configurator):
"""
This Configurator allows to select a single item among multiple choices.
"""
type = "single_choice"
_default = []
def __init__(self, name, choices=None, **kwargs):
Configurator.__init__(self, name, **kwargs)
self._choices = choices if choices is not None else []
def configure(self, configuration, value):
try:
self["index"] = self._choices.index(value)
except ValueError:
raise ConfiguratorError("%r item is not a valid choice" % value, self)
else:
self["value"] = value
@property
def choices(self):
return self._choices
def get_information(self):
return "Selected item: %r" % self['value']
class MultipleChoicesConfigurator(Configurator):
"""
This Configurator allows to select several items among multiple choices.
"""
type = "multiple_choices"
_default = []
def __init__(self, name, choices=None, nChoices=None, **kwargs):
Configurator.__init__(self, name, **kwargs)
self._choices = choices if choices is not None else []
self._nChoices = nChoices
def configure(self, configuration, value):
if self._nChoices is not None:
if len(value) != self._nChoices:
raise ConfiguratorError("Invalid number of choices.", self)
indexes = []
for v in value:
try:
indexes.append(self._choices.index(v))
except ValueError:
raise ConfiguratorError("%r item is not a valid choice" % v, self)
self["indexes"] = indexes
self["choices"] = [self._choices[i] for i in indexes]
self["value"] = self["choices"]
@property
def choices(self):
return self._choices
@property
def nChoices(self):
return self._nChoices
def get_information(self):
return "Selected items: %r" % self['choices']
class ComplexConfigurator(Configurator):
"""
This Configurator allows to input a Complex Value a + bi,
where a and b are real numbers and i is the imaginary unit.
"""
type = 'complex'
_default = 0
def __init__(self, name, mini=None, maxi=None, choices=None, **kwargs):
# The base class constructor.
Configurator.__init__(self, name, **kwargs)
self._mini = ComplexNumber(mini) if mini is not None else None
self._maxi = ComplexNumber(maxi) if maxi is not None else None
self._choices = choices if choices is not None else []
def configure(self, configuration, value):
value = ComplexNumber(value)
if self._choices:
if not value in self._choices:
raise ConfiguratorError('The input value is not a valid choice.', self)
if self._mini is not None:
if value.modulus() < self._mini.modulus():
raise ConfiguratorError("The input value is lower than %r." % self._mini, self)
if self._maxi is not None:
if value.modulus() > self._maxi.modulus():
raise ConfiguratorError("The input value is higher than %r." % self._maxi, self)
self['value'] = value
@property
def mini(self):
return self._mini
@property
def maxi(self):
return self._maxi
@property
def choices(self):
return self._choices
def get_information(self):
return "Value: %r" % self['value']
class FloatConfigurator(Configurator):
"""
This Configurator allows to input a Floating point Value.
"""
type = 'float'
_default = 0
def __init__(self, name, mini=None, maxi=None, choices=None, **kwargs):
# The base class constructor.
Configurator.__init__(self, name, **kwargs)
self._mini = float(mini) if mini is not None else None
self._maxi = float(maxi) if maxi is not None else None
self._choices = choices if choices is not None else []
def configure(self, configuration, value):
try:
value = float(value)
except (TypeError,ValueError) as e:
raise ConfiguratorError(e)
if self._choices:
if not value in self._choices:
raise ConfiguratorError('The input value is not a valid choice.', self)
if self._mini is not None:
if value < self._mini:
raise ConfiguratorError("The input value is lower than %r." % self._mini, self)
if self._maxi is not None:
if value > self._maxi:
raise ConfiguratorError("The input value is higher than %r." % self._maxi, self)
self['value'] = value
@property
def mini(self):
return self._mini
@property
def maxi(self):
return self._maxi
@property
def choices(self):
return self._choices
def get_information(self):
return "Value: %r" % self['value']
class QVectorsConfigurator(Configurator):
"""
This Configurator allows to set reciprocal vectors for a given system.
"""
type = "q_vectors"
_default = ("spherical_lattice",{"shells":(0,5,0.1), "width" : 0.1, "n_vectors" : 50})
def configure(self, configuration, value):
trajConfig = configuration[self._dependencies['trajectory']]
target = trajConfig["basename"]
# Check whether the input corresponds to a valid Q vector Uuser definition
try:
definition = USER_DEFINITIONS.check_and_get(target, "q_vectors", value)
self["parameters"] = definition['parameters']
self["type"] = definition['generator']
self["is_lattice"] = definition['is_lattice']
self["q_vectors"] = definition['q_vectors']
# Otherwise compute the Q vector based on the input value
except UserDefinitionsError:
generator, parameters = value
generator = REGISTRY["qvectors"][generator](trajConfig["instance"].universe)
generator.configure(parameters)
data = generator.run()
if not data:
raise ConfiguratorError("No Q vectors could be generated", self)
self["parameters"] = parameters
self["type"] = generator.type
self["is_lattice"] = generator.is_lattice
self["q_vectors"] = data
finally:
self["shells"] = self["q_vectors"].keys()
self["n_shells"] = len(self["q_vectors"])
self["value"] = self["q_vectors"]
def get_information(self):
info = ["%d Q shells generated\n" % self["n_shells"]]
for (qValue,qVectors) in self["q_vectors"].items():
info.append("Shell %s: %d Q vectors generated\n" % (qValue,len(qVectors)))
return "".join(info)
class VectorConfigurator(Configurator):
"""
This Configurator allows to input a 3D vector, by giving its 3 components
"""
type = "vector"
_default = [1.0,0.0,0.0]
def __init__(self, name, valueType=int, normalize=False, notNull=False, **kwargs):
# The base class constructor.
Configurator.__init__(self, name, **kwargs)
self._valueType = valueType
self._normalize = normalize
self._notNull = notNull
def configure(self, configuration, value):
vector = Vector(numpy.array(value,dtype=self._valueType))
if self._normalize:
vector = vector.normal()
if self._notNull:
if vector.length() == 0.0:
raise ConfiguratorError("The vector is null", self)
self['vector'] = vector
self['value'] = vector
@property
def valueType(self):
return self._valueType
@property
def normalize(self):
return self._normalize
@property
def notNull(self):
return self._notNull
def get_information(self):
return "Value: %r" % self["value"]
class InputFileConfigurator(Configurator):
"""
This Configurator allows to set as input any existing file.
"""
type = 'input_file'
_default = ""
def __init__(self, name, checkExistence=True, wildcard="All files|*.*", **kwargs):
# The base class constructor.
Configurator.__init__(self, name, **kwargs)
self._checkExistence = checkExistence
self._wildcard = wildcard
def configure(self, configuration, value):
if self.checkExistence:
value = PLATFORM.get_path(value)
if not os.path.exists(value):
raise ConfiguratorError("The input file %r does not exist." % value, self)
self["value"] = value
self["filename"] = value
@property
def checkExistence(self):
return self._checkExistence
@property
def wildcard(self):
return self._wildcard
def get_information(self):
return "Input file: %r" % self["value"]
class IntegerConfigurator(Configurator):
"""
This Configurator allow to input an Integer Value.
"""
type = 'integer'
_default = 0
def __init__(self, name, mini=None, maxi=None, choices=None, **kwargs):
# The base class constructor.
Configurator.__init__(self, name, **kwargs)
self._mini = int(mini) if mini is not None else None
self._maxi = int(maxi) if maxi is not None else None
self._choices = choices if choices is not None else []
def configure(self, configuration, value):
try:
value = int(value)
except (TypeError,ValueError) as e:
raise ConfiguratorError(e)
if self._choices:
if not value in self._choices:
raise ConfiguratorError('The input value is not a valid choice.', self)
if self._mini is not None:
if value < self._mini:
raise ConfiguratorError("The input value is lower than %r." % self._mini, self)
if self._maxi is not None:
if value > self._maxi:
raise ConfiguratorError("The input value is higher than %r." % self._maxi, self)
self['value'] = value
@property
def mini(self):
return self._mini
@property
def maxi(self):
return self._maxi
@property
def choices(self):
return self._choices
def get_information(self):
return "Value: %r" % self["value"]
class NetCDFInputFileConfigurator(InputFileConfigurator):
"""
This configurator allows to input a NetCDF file.
"""
type = 'netcdf_input_file'
_default = ''
def __init__(self, name, variables=None, **kwargs):
# The base class constructor.
InputFileConfigurator.__init__(self, name, **kwargs)
self._variables = variables if variables is not None else []
def configure(self, configuration, value):
InputFileConfigurator.configure(self, configuration, value)
if self.checkExistence:
try:
self['instance'] = NetCDFFile(self['value'], 'r')
except IOError:
raise ConfiguratorError("Can not open %r NetCDF file for reading" % self['value'])
for v in self._variables:
try:
self[v] = self['instance'].variables[v]
except KeyError:
raise ConfiguratorError("The variable %r was not found in %r NetCDF file" % (v,self["value"]))
@property
def variables(self):
return self._variables
def get_information(self):
return "NetCDF input file: %r" % self["value"]
class MMTKNetCDFTrajectoryConfigurator(InputFileConfigurator):
"""
MMTK trajectory file is a NetCDF file that store various data related to
molecular dynamics : atomic positions, velocities, energies, energy gradients etc.
"""
type = 'mmtk_trajectory'
_default = ''
def configure(self, configuration, value):
InputFileConfigurator.configure(self, configuration, value)
inputTraj = REGISTRY["inputdata"]["mmtk_trajectory"](self['value'])
self['instance'] = inputTraj.trajectory
self["filename"] = PLATFORM.get_path(inputTraj.filename)
self["basename"] = os.path.basename(self["filename"])
self['length'] = len(self['instance'])
try:
self['md_time_step'] = self['instance'].time[1] - self['instance'].time[0]
except IndexError:
self['md_time_step'] = 1.0
self["universe"] = inputTraj.universe
self['has_velocities'] = 'velocities' in self['instance'].variables()
def get_information(self):
info = ["MMTK input trajectory: %r\n" % self["filename"]]
info.append("Number of steps: %d\n") % self["length"]
info.append("Size of the universe: %d\n" % self["universe"].numberOfAtoms())
if (self['has_velocities']):
info.append("The trajectory contains atomic velocities\n")
return "".join(info)
class OutputFilesConfigurator(Configurator):
"""
The output file configurator allow to select : the output directory,
the basename, and the format of the file resulting from the analysis.
"""
type = 'output_files'
_default = (PREFERENCES['working_directory'], "output", ["netcdf"])
def __init__(self, name, formats=None, **kwargs):
Configurator.__init__(self, name, **kwargs)
self._formats = formats if formats is not None else ["netcdf"]
def configure(self, configuration, value):
dirname, basename, formats = value
if not dirname:
dirname = os.getcwd()
if not basename:
raise ConfiguratorError("Empty basename for the output file.", self)
root = os.path.join(dirname, basename)
try:
PLATFORM.create_directory(dirname)
except PlatformError:
raise ConfiguratorError("The directory %r is not writable" % dirname)
if not formats:
raise ConfiguratorError("No output formats specified", self)
for fmt in formats:
if not fmt in self._formats:
raise ConfiguratorError("The output file format %r is not a valid output format" % fmt, self)
if not REGISTRY["format"].has_key(fmt):
raise ConfiguratorError("The output file format %r is not registered as a valid file format." % fmt, self)
self["root"] = root
self["formats"] = formats
self["files"] = ["%s%s" % (root,REGISTRY["format"][f].extension) for f in formats]
@property
def formats(self):
return self._formats
def get_information(self):
info = ["Input files:\n"]
for f in self["files"]:
info.append(f)
info.append("\n")
return "".join(info)
class ProjectionConfigurator(Configurator):
"""
This configurator allows to define a projection axis.
"""
type = 'projection'
_default = None
def configure(self, configuration, value):
if value is None:
value = ('none',None)
try:
mode, axis = value
except (TypeError,ValueError) as e:
raise ConfiguratorError(e)
if not isinstance(mode,basestring):
raise ConfiguratorError("Invalid type for projection mode: must be a string")
mode = mode.lower()
try:
self["projector"] = REGISTRY['projector'][mode]()
except KeyError:
raise ConfiguratorError("The projector %r is unknow" % mode)
else:
self["projector"].set_axis(axis)
self["axis"] = self["projector"].axis
def get_information(self):
return "Projection along %r axis:" % self["axis"]
class InterpolationOrderConfigurator(IntegerConfigurator):
"""
This configurator allows to set as input the order of the interpolation apply when deriving velocities
from atomic coordinates to the atomic trajectories.