Esempio n. 1
0
def inputFileRead(filename):
    """
    read and process an input file
    """
    keywords = [
        'trajectory', 'output_files', 'title', 'time_info', 'time_steps',
        'frequency_points', 'q_vector_set', 'deuter', 'projection_vector',
        'reference', 'rotation_coefficients', 'ft_window', 'groups', 'weights',
        'atoms', 'units_length', 'units_frequency', 'log_file', 'groups_code',
        'atoms_code', 'filter_window', 'results_file', 'atoms_pdb',
        'differentiation', 'verbose', 'symbols', 'ar_order', 'ar_precision'
    ]
    newvars = {}
    file_text = Utility.readURL(filename)
    exec file_text in vars(sys.modules['__builtin__']), newvars
    input = Quidam()
    for key in keywords:
        if newvars.has_key(key): setattr(input, key, newvars[key])
        else: setattr(input, key, None)

    import os
    print os.getcwd()
    print input.trajectory
    #
    # general settings
    #
    if input.trajectory:
        if len(input.trajectory) == 1:
            traj = Trajectory(None, input.trajectory[0], 'r')
            if traj.variables().count('quaternion') > 0:
                traj = qTrajectory(None, input.trajectory[0], 'r')
        elif len(input.trajectory) > 1:
            traj = TrajectorySet(None, input.trajectory)

        if not input.units_length: input.units_length = Units.nm
        if not input.units_frequency:
            input.units_frequency = Units.tera * Units.Hz

        types = getTypes(traj.universe)
        if input.q_vector_set is None:
            input.q_vector_set = (N.arange(0., 100., 2.), 1., 50)  # default
        if input.time_info is None: input.time_info = (0, len(traj), 1)
        qVectors = qVectorGenerator(input.q_vector_set, traj)
        #
        # Substitute Hydrogen atoms with Deuter?
        #
        if input.deuter:
            collection = Collection()
            for i in input.deuter.keys():
                for ia in input.deuter[i]:
                    gj = getChemicalObjects({i: types[i]}, {i: ia})
                    collection.addObject(gj)
            h2d = collection.atomList()
            print 'number of Deuter atoms: ', len(h2d)
        #
        # Atom selection related keywords
        # atoms selected in a different way are stored together
        # and filtered at the end (if there're repetitions only
        # atoms which occur many times are stored and passed to
        # further calculations, else all atoms are passed)
        #
        if input.atoms:
            print 'processing atom selection:\n\t', input.atoms
            collection = []
            for i in input.atoms.keys():
                for ia in input.atoms[i]:
                    typs = {}
                    typs[i] = types[i]
                    vlst = {}
                    vlst[i] = ia
                    gj = getChemicalObjects(typs, vlst)
                    collection = collection + gj.atomList()
            input.atoms = collection
            print '\t...done\n\tstored ', len(input.atoms), ' atoms\n'
        if input.atoms_pdb:
            print 'processing atom selection from a PDB file\n\t(',
            print input.atoms_pdb, '):'
            atoms_add = parsePDBAtomSelection(input.atoms_pdb, traj)
            print '\t...done\n\tstored ', len(atoms_add.atomList()), ' atoms\n'
            if input.atoms: input.atoms = input.atoms + atoms_add.atomList()
            else: input.atoms = atoms_add.atomList()
        if input.atoms_code:
            print 'processing atom selection hardcoded in Python'
            # syntax:
            # def atoms_code(traj,nothing,dummy_a='gj')
            #     # a python code here
            #     return Collection(atom_list)
            #
            # atoms_code is a function object whose first argument is
            # a Trajectory object and which returns a Collection object.
            print '...done\n\tstored ', len(input.atoms_code(traj).atomList()),
            print ' atoms'
            if input.atoms:
                input.atoms = input.atoms + input.atoms_code(traj).atomList()
            else:
                input.atoms = input.atoms_code(traj).atomList()
        if not input.atoms:
            print ' No atom selection found, taking everything... just in case'
            input.atoms = traj.universe
        else:
            input.atoms = Collection(input.atoms)
        input.atoms = ghostBusters(input.atoms)
        print ' # atoms in selection: ', len(input.atoms.atomList())
        #
        # Group selection
        #
        if input.groups:
            input.groups, input.reference = parseGroupSelection(
                types, input.groups, input.reference, verbose=input.verbose)
        if input.groups_code:
            # previous def (if any) overwritten
            # the result returned by groups_code should be consistent
            # with that one from misc.paresGroupSelection
            input.groups, input.reference = input.groups_code(traj)
        #
        # Another piece of general settings
        #
        if input.weights == 'mass':
            weightsList = MassList(traj.universe, input.atoms)
        elif input.weights == 'incoherent':
            if input.deuter:
                weightsList = BincohList(traj.universe, input.atoms, h2d)
            else:
                weightsList = BincohList(traj.universe, input.atoms)
        elif input.weights == 'coherent':
            if input.deuter:
                weightsList = BcohList(traj.universe, input.atoms, h2d)
            else:
                weightsList = BcohList(traj.universe, input.atoms)
        else:
            weightsList = None

        # input.trajectory = (traj, input.trajectory)
        input.trajectory = traj
        input.q_vector_set = qVectors
        input.weights = weightsList

    return input
Esempio n. 2
0
    def body(self, master):
        """Create dialog body. Return widget that should have initial focus.
        """

        # The frame that will contain the widgets whose the analysis dialog is built up.
        widgetsFrame = LabelFrame(master, text='Setup', bd=2, relief=GROOVE)
        widgetsFrame.grid(row=0, column=0, padx=3, pady=3, sticky=EW)
        widgetsFrame.grid_columnconfigure(0, weight=1)

        self.widgets = {}

        for widget in self.db_parameternames:

            widget = widget.lower()

            if widget == 'angminmax':
                self.widgets[widget] = ComboStringEntry(widgetsFrame,\
                                                        frameLabel = "HB angle min:max values (in deg)",\
                                                        tagName = 'angle_min_max',\
                                                        contents = "150.0:180.0")

            elif widget == 'armodelorder':
                self.widgets[widget] = ComboIntegerEntry(widgetsFrame,\
                                                         frameLabel = "Model order", \
                                                         tagName = 'model_order',\
                                                         contents = 50)

            elif widget == 'atomorder':

                self.widgets[widget] = ComboButton(widgetsFrame,\
                                                   frameLabel = "Atom order",\
                                                   tagName = 'atom_selection',\
                                                   contents = "Select",\
                                                   withEntry = '')

                t = Trajectory(None, self.trajectory, 'r')

                self.widgets[widget].command = lambda s=self, n=sorted(
                    set([at.name for at in t.universe.atomList()])
                ): AtomOrderDialog(s, n)

                t.close()

            elif widget == 'truebreakstep':
                self.widgets[widget] = ComboIntegerEntry(widgetsFrame,\
                                                         frameLabel = "True break step", \
                                                         tagName = 'true_break_step',\
                                                         contents = 1)

            elif widget == 'comselection':
                self.widgets[widget] = ComboButton(widgetsFrame,\
                                                   frameLabel = "Center of mass selection",\
                                                   tagName = 'center_of_mass_selection',\
                                                   contents = "Select",\
                                                   withEntry = 'all')

                self.widgets[
                    widget].command = lambda s=self, t='subset', c=self.chemicalObjectInfo, w=self.widgets[
                        widget]: SelectionDialog(s, t, c, w)

            elif widget == 'deuteration':
                self.widgets[widget] = ComboButton(widgetsFrame,\
                                                   frameLabel = "Deuteration selection",\
                                                   tagName = 'deuteration_selection',\
                                                   contents = "Select",\
                                                   withEntry = 'no')

                self.widgets[
                    widget].command = lambda s=self, t='deuteration', c=self.chemicalObjectInfo, w=self.widgets[
                        widget]: SelectionDialog(s, t, c, w)

            elif widget == 'differentiation':

                t = Trajectory(None, GVAR['current_traj'], 'r')

                if 'velocities' in t.variables():
                    diffOrder = (0, 1, 2, 3, 4, 5)
                else:
                    diffOrder = (1, 2, 3, 4, 5)

                t.close()

                self.widgets[widget] = ComboSpinbox(widgetsFrame,\
                                                    frameLabel = "Differentiation order",\
                                                    tagName = 'differentiation_order',\
                                                    contents = diffOrder)

            elif widget == 'direction':
                self.widgets[widget] = ComboRadiobutton(widgetsFrame,\
                                                        frameLabel = "Direction",\
                                                        tagName = 'direction',\
                                                        contents = ["X", "Y", "Z"],\
                                                        layout = (1,3))

            elif widget == 'disminmax':
                self.widgets[widget] = ComboStringEntry(widgetsFrame,\
                                                        frameLabel = "HB distance min:max values",\
                                                        tagName = 'dis_min_max',\
                                                        contents = "0.0:0.35")

            elif widget == 'distanceunits':
                self.widgets[widget] = ComboRadiobutton(widgetsFrame,\
                                                        frameLabel = "Distance units",\
                                                        tagName = 'distanceunits',\
                                                        contents = ["nm", "ang", "fm"],\
                                                        layout = (1,3))

            elif widget == 'filter':
                self.widgets[widget] = ComboStringEntry(widgetsFrame,\
                                                        frameLabel = "Pass-Band filter (in tHz)",\
                                                        tagName = 'pass_band_filer',\
                                                        contents = "0.0:1000.0")

            elif widget == 'frequencyunits':
                self.widgets[widget] = ComboRadiobutton(widgetsFrame,\
                                                        frameLabel = "Frequency units",\
                                                        tagName = 'frequencyunits',\
                                                        contents = ["THz", "rad s^-1", "cm^-1", "meV", "ueV"],\
                                                        layout = (1,5))

            elif widget == 'group':
                self.widgets[widget] = ComboButton(widgetsFrame,\
                                                   frameLabel = "Group selection",\
                                                   tagName = 'group_selection',\
                                                   contents = "Select",\
                                                   withEntry = 'all')

                self.widgets[
                    widget].command = lambda s=self, t='group', c=self.chemicalObjectInfo, w=self.widgets[
                        widget]: SelectionDialog(s, t, c, w)

            elif widget == 'normalize':
                self.widgets[widget] = ComboCheckbutton(widgetsFrame,\
                                                        frameLabel = "Normalize",\
                                                        tagName = 'normalize',\
                                                        onvalue = "yes",\
                                                        offvalue = "no")

            elif widget == 'output':
                # The basename of the input trajectory name.
                baseName = self.db_shortname.upper() + '_' + os.path.basename(
                    self.trajectory)

                try:
                    outputFilename = os.path.join(
                        PREFERENCES['outputfile_path'], baseName)

                except TypeError:
                    outputFilename = baseName

                self.widgets[widget] = ComboFileBrowser(widgetsFrame,\
                                                        frameLabel = "Output file",\
                                                        tagName= "output_file",\
                                                        contents = outputFilename,\
                                                        save = True,\
                                                        filetypes = [("NetCDF file", ".nc"),])

            elif widget == 'phivalues':
                self.widgets[widget] = ComboStringEntry(widgetsFrame,\
                                                        frameLabel = "Phi values (in deg)",\
                                                        tagName = 'phi_values',\
                                                        contents = "-180.0:180.0:10.0")

            elif widget == 'projection':
                self.widgets[widget] = ComboStringEntry(widgetsFrame,\
                                                        frameLabel = "Project displacement on",\
                                                        tagName = 'project_displacement_on',\
                                                        contents = "no")

            elif widget == 'pyroserver':

                self.widgets[widget] = ComboButton(widgetsFrame,\
                                                   frameLabel = "Pyro server",\
                                                   tagName = 'pyro_server',\
                                                   contents = "Select",\
                                                   withEntry = 'monoprocessor')

                self.widgets[widget].command = lambda s=self, w=self.widgets[
                    widget]: PyroServerDialog(s, w)

            elif widget == 'qshellvalues':
                self.widgets[widget] = ComboStringEntry(widgetsFrame,\
                                                        frameLabel = "Q values (in nm-1)",\
                                                        tagName = 'qshell_values',\
                                                        contents = "0.0:100.0:1.0")

            elif widget == 'qshellwidth':
                self.widgets[widget] = ComboFloatEntry(widgetsFrame,\
                                                       frameLabel = "Q shell width (in nm-1)",\
                                                       tagName = 'qshell_width',\
                                                       contents = 1.0)

            elif widget == 'qunits':
                self.widgets[widget] = ComboRadiobutton(widgetsFrame,\
                                                        frameLabel = "Q units",\
                                                        tagName = 'qunits',\
                                                        contents = ["nm^-1", "ang^-1"],\
                                                        layout = (1,2))

            elif widget == 'qvectors':
                self.widgets[widget] = ComboButton(widgetsFrame,\
                                                   frameLabel = "Q vectors",\
                                                   tagName = 'qvectors',\
                                                   contents = "Setup",\
                                                   withEntry = {'qgeometry': 'spatial', \
                                                                'qshellwidth': 1.0, \
                                                                'qshellvalues': '0.0:10.0:1.0', \
                                                                'qvectorspershell': 50,\
                                                                'hkls' : None})

                self.widgets[widget].command = lambda s=self, w=self.widgets[
                    widget]: QVectorsDialog(s, w)

            elif widget == 'qvectorsdirection':
                self.widgets[widget] = ComboStringEntry(widgetsFrame,\
                                                        frameLabel = "Q vectors direction",\
                                                        tagName = 'qvectors_direction',\
                                                        contents = "no")

            elif widget == 'qvectorsgenerator':
                self.widgets[widget] = ComboRadiobutton(widgetsFrame,\
                                                        frameLabel = "Q vectors generator",\
                                                        tagName = 'qvectors_generator',\
                                                        contents = ["3D isotropic", "2D isotropic", "anisotropic"],\
                                                        layout = (1,3))

            elif widget == 'qvectorspershell':
                self.widgets[widget] = ComboIntegerEntry(widgetsFrame,\
                                                         frameLabel = "Q vectors per shell",\
                                                         tagName= 'qvectors_per_shell',\
                                                         contents = 50)

            elif widget == 'referencedirection':
                self.widgets[widget] = ComboStringEntry(widgetsFrame,\
                                                        frameLabel = "Reference direction",\
                                                        tagName = 'reference_direction',\
                                                        contents = "0.0,0.0,1.0")

            elif widget == 'referenceframe':
                self.widgets[widget] = ComboIntegerEntry(widgetsFrame,\
                                                         frameLabel = "Reference frame",\
                                                         tagName= 'reference_frame',\
                                                         contents = 1)

            elif widget == 'removetranslation':
                self.widgets[widget] = ComboCheckbutton(widgetsFrame,\
                                                        frameLabel = "Remove translation",\
                                                        tagName = 'remove_translation',\
                                                        onvalue = "yes",\
                                                        offvalue = "no")

            elif widget == 'resolution':
                self.widgets[widget] = ComboFloatEntry(widgetsFrame,\
                                                       frameLabel = "Resolution (FWHM meV)",\
                                                       tagName = 'resolution',\
                                                       contents = 10.0)

                self.updateResolution()

                self.widgets[widget].entry.variable.trace_vdelete(
                    'w', self.widgets[widget].entry.cbname)

                self.widgets[widget].entry.variable.trace_variable(
                    'w', self.updateResolution)

                self.widgets[widget].entry.variable.trace_variable(
                    'w', self.widgets[widget].entry._callback)

            elif widget == 'rvalues':
                self.widgets[widget] = ComboStringEntry(widgetsFrame,\
                                                        frameLabel = "Distances (in nm)",\
                                                        tagName = 'distances',\
                                                        contents = "0.0:1.0:0.1")

            elif widget == 'stepwiserbt':
                self.widgets[widget] = ComboCheckbutton(widgetsFrame,\
                                                        frameLabel = "Stepwise RBT",\
                                                        tagName = 'stepwise_rbt',\
                                                        onvalue = "yes",\
                                                        offvalue = "no")

            elif widget == 'storerbtdetails':
                self.widgets[widget] = ComboCheckbutton(widgetsFrame,\
                                                        frameLabel = "Store RBT details",\
                                                        tagName = 'store_rbt_details',\
                                                        onvalue = "yes",\
                                                        offvalue = "no")

            elif widget in ['subset', 'subset1', 'subset2']:
                self.widgets[widget] = ComboButton(widgetsFrame,\
                                                   frameLabel = "%s selection" % widget.capitalize(),\
                                                   tagName = 'subset_selection',\
                                                   contents = "Select",\
                                                   withEntry = 'all')

                self.widgets[
                    widget].command = lambda s=self, t='subset', c=self.chemicalObjectInfo, w=self.widgets[
                        widget]: SelectionDialog(s, t, c, w)

            elif widget == 'target':
                self.widgets[widget] = ComboButton(widgetsFrame,\
                                                   frameLabel = "Target selection",\
                                                   tagName = 'target_selection',\
                                                   contents = "Select",\
                                                   withEntry = 'all')

                if self.db_shortname == "GMFT":
                    self.widgets[
                        widget].command = lambda s=self, t='subset', c=self.chemicalObjectInfo, w=self.widgets[
                            widget]: SelectionDialog(s, t, c, w)
                else:
                    self.widgets[
                        widget].command = lambda s=self, t='group', c=self.chemicalObjectInfo, w=self.widgets[
                            widget]: SelectionDialog(s, t, c, w)

            elif widget == 'temperature':
                self.widgets[widget] = ComboFloatEntry(widgetsFrame,\
                                                       frameLabel = "Temperature (in K)",\
                                                       tagName = 'temperature',\
                                                       contents = 1.0)

            elif widget == 'thetavalues':
                self.widgets[widget] = ComboStringEntry(widgetsFrame,\
                                                        frameLabel = "Theta values (in deg)",\
                                                        tagName = 'theta_values',\
                                                        contents = "0.0:180.0:10.0")

            elif widget == 'thickness':
                self.widgets[widget] = ComboFloatEntry(widgetsFrame,\
                                                       frameLabel = "Thickness (in nm)",\
                                                       tagName = 'thickness',\
                                                       contents = 0.05)

            elif widget == 'timeinfo':

                t = load_trajectory_file(self.trajectory)
                timeInfo = '%d:%d:%d' % (1, len(t), 1)
                self.widgets[widget] = ComboStringEntry(widgetsFrame,\
                                                        frameLabel = "Frame selection",\
                                                        tagName = 'frame_selection',\
                                                        contents = timeInfo)

                self.updateTimeInfo(t)

                self.widgets[widget].entry.variable.trace_variable(
                    'w', lambda: self.updateTimeInfo(t))

            elif widget == 'timeunits':
                self.widgets[widget] = ComboRadiobutton(widgetsFrame,\
                                                        frameLabel = "Time units",\
                                                        tagName = 'timeunits',\
                                                        contents = ["ps", "ns", "fs"],\
                                                        layout = (1,3))

            elif widget == 'trajectory':
                self.widgets[widget] = ComboLabel(widgetsFrame,\
                                                  frameLabel = "Trajectory file",\
                                                  tagName = 'tajectory_file',\
                                                  contents = self.trajectory)

            elif widget == 'weights':
                self.widgets[widget] = ComboRadiobutton(widgetsFrame,\
                                                        frameLabel = "Weights",\
                                                        tagName = 'weights',\
                                                        contents = ["equal", "mass", "coherent", "incoherent", "atomicNumber"],\
                                                        layout = (2,3))

            elif widget == 'wignerindexes':
                self.widgets[widget] = ComboStringEntry(widgetsFrame,\
                                                        frameLabel = "Wigner indexes",\
                                                        tagName = 'wigner_indexes',\
                                                        contents = "0,0,0")

            # The tagName for the combo widget is set.
            setattr(
                self.widgets[widget], 'tagName',
                '%s_%s' % (self.db_shortname.lower(),
                           self.widgets[widget].tagName.lower()))

            # And displayed into the analysis dialog.
            self.widgets[widget].grid(column=0, sticky=EW, padx=2, pady=2)
            self.widgets[widget].grid_columnconfigure(0, weight=1)

        if hasattr(self, 'db_modulator'):
            for k, v in self.db_modulator.items():
                k = k.lower()
                if k == 'weights':
                    self.widgets[k].setValue(v)

                elif k == 'differentiation':
                    self.widgets[k].spinbox.config(values=v)

        return None
    x2 += a2.beadPositions()[bead][x] * a2.mass()

    y2 += a2.beadPositions()[bead][y] * a2.mass()

    z2 += a2.beadPositions()[bead][z] * a2.mass()


  return sqrt(((x1/m1) - (x2/m2))**2 + ((y1/m1) - (y2/m2))**2 + ((z1/m1) - (z2/m2))**2)

####################################################################################################################################################################

print '.....Performing Analysis........................................................'
#Read in trajectory from file
trajectory = Trajectory(None, dir + '//' + dir + '_prod.nc')
#Output the variables stored in the trajectory
print 'The available variables in the trajectory are:', trajectory.variables()
universe = trajectory.universe
natoms = universe.numberOfAtoms()
P = universe[0].atomList()[0].numberOfPoints()
print 'There are', natoms, 'atoms and', P, 'beads per atom present in the trajectory'

#Output files to write centre of masses to.
com_out = open(dir + '//' + dir + '_centroid_com_distance.txt','w')
bead_com_out = open(dir + '//' + dir + '_bead_com_distance.txt','w')

for step in trajectory:
    #set the configuration to each new step
    universe.setConfiguration(step['configuration'])

    for object1 in universe.objectList():
        for object2 in universe.objectList():
        y2 += a2.beadPositions()[bead][y] * a2.mass()

        z2 += a2.beadPositions()[bead][z] * a2.mass()

    return sqrt(((x1 / m1) - (x2 / m2))**2 + ((y1 / m1) - (y2 / m2))**2 +
                ((z1 / m1) - (z2 / m2))**2)


####################################################################################################################################################################

print '.....Performing Analysis........................................................'
#Read in trajectory from file
trajectory = Trajectory(None, dir + '//' + dir + '_prod.nc')
#Output the variables stored in the trajectory
print 'The available variables in the trajectory are:', trajectory.variables()
universe = trajectory.universe
natoms = universe.numberOfAtoms()
P = universe[0].atomList()[0].numberOfPoints()
print 'There are', natoms, 'atoms and', P, 'beads per atom present in the trajectory'

#Output files to write centre of masses to.
com_out = open(dir + '//' + dir + '_centroid_com_distance.txt', 'w')
bead_com_out = open(dir + '//' + dir + '_bead_com_distance.txt', 'w')

for step in trajectory:
    #set the configuration to each new step
    universe.setConfiguration(step['configuration'])

    for object1 in universe.objectList():
        for object2 in universe.objectList():