Esempio n. 1
0
def run(pluginManager):
    """
    Entry point for the plugin manager
    :param pluginManager: plugin manager instance
    :return: None
    """
    printer = pluginManager.setup()
    loader = Loader(printer)
    data = DATA()
    dabapath = pluginManager.get_databasepath()
    FlexLoad(data, loader, dabapath, pluginManager, pluginManager.arg('load'))
    shelxliop = loader.get_IOP()

    atomsWithInvariomName = {}
    for atom in data['exp'].atoms:
        try:
            atomsWithInvariomName[atom.get_active_invariom()].append(atom.name)
        except KeyError:
            atomsWithInvariomName[atom.get_active_invariom()] = [atom.name]

    for invariomName, atomNames in atomsWithInvariomName.items():
        printer()
        printer(invariomName)
        for atomName in atomNames:
            printer('  {}'.format(atomName))
            for bede in shelxliop.atoms[atomName].getBedeInstructions():
                printer('      {}'.format(str(bede)))
Esempio n. 2
0
def load(pluginManager):
    loader = Loader(pluginManager.get_active_printer())
    filename = pluginManager.arg("load")
    loader.create(filename)
    mol = loader.load("compare")
    printer("Using file {} for comparison.".format(filename))
    return mol
Esempio n. 3
0
def load(pluginManager):
    printer = pluginManager.get_active_printer()
    loader = Loader(pluginManager.get_active_printer())
    filename = pluginManager.arg('load')
    loader.create(filename)
    mol = loader.load('compare')
    printer('Using file {} for comparison.'.format(filename))
    return mol
Esempio n. 4
0
 def run(self):
     super(ReadAtoms, self).run()
     from lauescript.laueio.loader import Loader
     loader = Loader()
     loader.create(self._FileName)
     print('1')
     mol = loader.load('quickloadedMolecule')
     print('2')
     self._Atoms(mol.atoms)
Esempio n. 5
0
def load(filename):
    loader = Loader(config.get_active_printer())
    loader.create(filename)
    mol = loader.load('compare')
    printer('Using file {} for comparison.'.format(filename))
    for atom in data['exp'].atoms:
        try:
            atom.adp['compare'] = mol[atom.name].adp['cart_meas']
        except KeyError:
            atom.adp['compare'] = [1, 1, 1, 0, 0, 0]
Esempio n. 6
0
def run(pluginManager):
    """
    This is the entry point for the plugin manager.
    The plugin manager will pass a reference to itself
    to the function.
    Use the APD_Printer instance returned by
    pluginManager.setup() instead of the 'print'
    statement to generate autoformated cmd line output.
    :param pluginManager: Reference to the plugin manager
    instance.
    """
    printer = pluginManager.setup()
    data = pluginManager.get_variable()
    if not data:
        loader = Loader(printer)
        loader.create(pluginManager.arg('load'))
        data = DATA()
        data['exp'] = loader.load('exp')
    #     T = loader.get_temperature()
    # else:
    #     T = pluginManager.get_variable('T')
    # obj = ObjectiveObject(data)
    # printer('Searching for optimal rigid bond description...')
    # f, best_solution = harmonize([(0, 10)], obj, 1000, startValues=[5, 0], pitchRange=0.01, dynamicPitch=200)
    # hresult, esd = obj(None, f[0], 'report')
    # printer('U_int/U_all * m ratio of f={:4.2f} yields best hirshfeld solution of {:5.3f} +- {:5.3f}.\n'.
    #         format(f[0], hresult, esd))
    # f = float('{:4.2f}'.format(f[0]))
    a, b = build_ls_matrix(data)
    solution = nnls(a, b)
    f = solution[0][0]
    if f > 1:
        printer('f out of bounds ({:4.2f}).'.format(f))
        printer('Starting linear search for reasonable solution:')
        f = find_f(data)[1]
        printer('U_int/U_all * m ratio of f={:4.2f} yields best hirshfeld solution.\n'.format(f))
    else:
        printer('U_int/U_all * m ratio of f={:4.2f} yields best hirshfeld solution.\n'.format(f))
    pluginManager.register_variable(f, 'f')
    analyser = Analyser(printer, pluginManager.get_variable('f'))
    for atom1, atom2 in data.iter_atom_pairs():
        if not any([atom.adp['flag'] == 'riding' for atom in (atom1, atom2)]) or pluginManager.arg('f'):
            # if atom1.element == 'H' or atom2.element == 'H':
            #     continue
            analyser(atom1, atom2)
    printer()
    printer('Average:             {:6.4f}\n                  +- {:6.4f}'.format(*analyser.harvest()))
    if pluginManager.arg('+'):
        printer('\n\nReporting element specific mean square displacements in bond direction.\n')
        for element, values in details(data).items():
            printer('{:>3}: {:5.3f}'.format(element, mean(values)))
    if pluginManager.arg('write'):
        options = {'full': True, 'use': 'beef'}
        pluginManager.call('W', options)
Esempio n. 7
0
def build_ls_matrices(data):
    """
    Prepares the data for the least square optimization. The useH option
    can be set to True to force the usage of hydron atoms. This is not
    recommendet for the actual fit but for the application of the
    fitted Parameters to the atoms.

    :param data: Instance of the DATA class containing all necessary data.
    """
    loader = Loader(printer)
    filename = config.arg("load")
    if not filename:
        filename = "neut.res"
    printer("Using file '{}' for target ADPs.\n".format(filename))
    loader.create(filename)
    global mol
    mol = loader.load("neutron")
    printer("Scaling '{}' from 'exp' model to\n'cart_meas' of target model.\n".format(use[0]))

    y = []
    A = []
    for atom in data["exp"].atoms:
        if not atom.name[0] == "H":
            name = atom.name.replace("(", "").replace(")", "")
            try:
                adpN = mol[name].adp["cart_meas"]
            except AttributeError:
                adpN = mol[atom.name].adp["cart_meas"]
            adpX = atom.adp[use[0]]

            A.append(np.array([adpX[0], 1, 0, 0, 0, 0, 0]))
            A.append(np.array([adpX[1], 0, 1, 0, 0, 0, 0]))
            A.append(np.array([adpX[2], 0, 0, 1, 0, 0, 0]))
            A.append(np.array([adpX[3], 0, 0, 0, 1, 0, 0]))
            A.append(np.array([adpX[4], 0, 0, 0, 0, 1, 0]))
            A.append(np.array([adpX[5], 0, 0, 0, 0, 0, 1]))

            for i in range(len(adpN)):
                y.append(adpN[i])

    A = np.array(A)
    return A, y
Esempio n. 8
0
def build_ls_matrices(data):
    """
    Prepares the data for the least square optimization. The useH option
    can be set to True to force the usage of hydron atoms. This is not
    recommendet for the actual fit but for the application of the
    fitted Parameters to the atoms.

    :param data: Instance of the DATA class containing all necessary data.
    """
    loader = Loader(printer)
    filename = config.arg('load')
    if not filename:
        filename = 'neut.res'
    printer('Using file \'{}\' for target ADPs.\n'.format(filename))
    loader.create(filename)
    global mol
    mol = loader.load('neutron')
    printer('Scaling \'{}\' from \'exp\' model to\n\'cart_meas\' of target model.\n'.format(use[0]))



    y = []
    A = []
    for atom in data['exp'].atoms:
        if not atom.name[0] == 'H':
            name = atom.name.replace('(', '').replace(')', '')
            adpN = mol[name].adp['cart_meas']
            adpX = atom.adp[use[0]]

            A.append(np.array([adpX[0], 1, 0, 0, 0, 0, 0]))
            A.append(np.array([adpX[1], 0, 1, 0, 0, 0, 0]))
            A.append(np.array([adpX[2], 0, 0, 1, 0, 0, 0]))
            A.append(np.array([adpX[3], 0, 0, 0, 1, 0, 0]))
            A.append(np.array([adpX[4], 0, 0, 0, 0, 1, 0]))
            A.append(np.array([adpX[5], 0, 0, 0, 0, 0, 1]))

            for i in range(len(adpN)):
                y.append(adpN[i])

    A = np.array(A)
    return A, y