Ejemplo n.º 1
0
def get_potential_axis(matrix):
    """
    Determines potential rotation axis within the molecule.
    """
    namelist = []
    axislist = []
    for atom in data['exp'].atoms:
        try:
            atomtypes = parse_inv_name(atom.invariom_name)
        except TypeError:
            atomtypes = []
        frame_atoms = cg.get_framework_neighbours(atom)
        if len(atomtypes) > 1:
            for atom2 in frame_atoms:
                if atom2.name[0] in atomtypes and cg.get_atom_with_longest_bond(atom2.name[0], atom):
                    pair = [atom.name, atom2.name]
                    pair = sorted(pair)
                    if not pair in namelist:
                        axislist.append((atom, atom2))
                        namelist.append(pair)
    printer('\n{} potential rotation axis found:'.format(len(namelist)))
    for pair in namelist:
        printer('AXIS: {0:5>s}---{1:4<s}'.format(pair[0], pair[1]))
    printer('\nGenerate associated rigid groups.')

    return generate_rigid_groups(axislist, matrix)
Ejemplo n.º 2
0
    def __call__(self, *args):
        value = []
        f = args[1]
        # if f < self.min:
        #     print f
        #     self.min= f
        for atom1 in self.data.iter_atoms():
            if atom1.adp['flag'] == 'riding':
                continue
            for atom2 in get_framework_neighbours(atom1, useH=True):
                if atom2.adp['flag'] == 'riding':
                    continue
                v = atom1.get_cart() - atom2.get_cart()
                v /= norm(v)
                m1 = atomicmass[atom1.get_element()]
                m2 = atomicmass[atom2.get_element()]
                adp1 = atom1.adp[use] * (1-f/m1) + atom1.adp[use] * f
                adp2 = atom2.adp[use] * (1-f/m2) + atom2.adp[use] * f
                h1 = norm(dot(ADP_to_matrix(adp1), v))
                h2 = norm(dot(ADP_to_matrix(adp2), v))
                value.append(abs(h1 - h2))
        if 'report' in args:
            # print f
            return mean(value), std(value)

        return mean(value) + 100 * std(value)
Ejemplo n.º 3
0
def Uiso(data, logfile):
    """
    Method for calculating the size of U_iso hydrogen ADP
    relative the the U_iso ADP of the bonding partner.
    """
    printer.register_file(logfile, 'log', mode='a')
    # isofilters, isopartnerfilters = set_filter()
    #===========================================================================
    # keys=['cart_int','cart_ext','cart_sum','cart_meas','iso_meas']
    #===========================================================================
    use1, use2 = None, None
    try:
        use = config.arg('iso').split(':')
        use1 = use[0]
        use2 = use[1]

    except:
        use1 = 'cart_sum'
        use2 = 'cart_sum'
    # printer('\nSelected filters:\n\n  Attribute      |    Value     | True  | Function'
    #         '\n===================================================\nAtom filter:     |              |       |')
    # for isofilter in isofilters:
    #     printer('{:15s}  | {:12s} | {:5s} | {}'.format(isofilter[0], isofilter[1], isofilter[2], isofilter[3]))
    # printer('-----------------|--------------|-------|----------\nPartner filter:  |              |       |')
    # for isofilter in isopartnerfilters:
    #     printer('{:15s}  | {:12s} | {:5s} | {}'.format(isofilter[0], isofilter[1], isofilter[2], isofilter[3]))
    printer('\nComparing {} of hydrogen atoms\nwith {} of parent atoms.\n'.format(use1, use2))
    printer(' Riding | Parent | U_rel | U_rel\n  atom  |  atom  | geom  | arith')
    printer(' ================================')
    geom_sum = []
    arit_sum = []
    for atom in data['exp'].atoms:
        # if apply_filter(atom, isofilters):
            for heavy_atom in cg.get_framework_neighbours(atom, useH=True):
                if not atom == heavy_atom and filter_atom_pair(config, atom, heavy_atom):
                    U_rel_geom = cg.Uiso(atom.adp[use1]) / cg.Uiso(heavy_atom.adp[use2])
                    geom_sum.append(U_rel_geom)
                    U_rel_arith = cg.Uiso(atom.adp[use1], mean='arithmetic') / \
                                  cg.Uiso(heavy_atom.adp[use2], mean='arithmetic')
                    arit_sum.append(U_rel_arith)
                    printer('  {light:5s} |  {heavy:5s} | {U:5.3f} | {U2:5.3f}'.format(light=atom.name,
                                                                                       heavy=heavy_atom,
                                                                                       U=U_rel_geom,
                                                                                       U2=U_rel_arith))
    printer(' -------|--------|-------|-------')
    printer('  {light:5s} |  {heavy:5s} | {U:5.3f} | {U2:5.3f}'.format(light='mean',
                                                                       heavy='---',
                                                                       U=np.mean(geom_sum),
                                                                       U2=np.mean(arit_sum)))
    printer('  {light:5s} |  {heavy:5s} | {U:5.3f} | {U2:5.3f}'.format(light='SD',
                                                                       heavy='---',
                                                                       U=np.std(geom_sum),
                                                                       U2=np.std(arit_sum)))

    printer('{temp:.1f} {U:5.3f} {Uer:5.3f} {U2:5.3f} {U2er:5.3f}'.format(temp=data.temperature,
                                                                          U=np.mean(geom_sum),
                                                                          Uer=np.std(geom_sum),
                                                                          U2=np.mean(arit_sum),
                                                                          U2er=np.std(arit_sum)),
            use=['log'])
    printer.spacer()
Ejemplo n.º 4
0
def FlexLoad(data, loader, dabapath, config, filename='./', noTransfer=False, planarityThreshold=.1):
    """
    A more flexible variation of the 'Load' function.

    The actual 'loading' is handled by the 'Loader'
    class which relies on InputOutputProviders to
    access files independent of their specific file
    format.

    FlexLoad itself is only integrating the molecule
    returned by the 'Loader' in the APD-Toolkit's
    data structure and subsequently populating the
    data structure with the necessary model molecules.
    """
    printer = config.get_active_printer()
    loader.auto_setup(filename)
    data.register_molecule(loader.load('exp'), 'exp')

    data['exp'].give_cell(loader.get_cell())
    T = config.arg('temp')
    if not T:
        T = loader.get_temperature()
    if not T:
        printer.highlight('Warning: No temperature specified. Falling back to default.')
        T = 100
    T = int(T)
    data.give_temperature(T)

    dabapa = dabapath + '/APD_DABA_{:.1f}_.txt'.format(data.temperature)
    printer('Crystal temperature: {:.1f} K'.format(data.temperature))
    try:
        dabapointer = open(dabapa)
    except IOError:
        printer('inout.py: Error: File {} not found.'.format(dabapa))
        printer('Calling database generator to generate appropriate database file.\n\n')
        import lauescript.database as db

        frequency_cutoff = config.get_frequency_cutoff()
        db.generate_database(data, frequency_cutoff, clean=False, temperatures=[data.temperature], path=dabapath,
                             newh=config.get_config_valueBool('APD', 'newH'))
        dabapointer = open(dabapa)

    database = dabapointer.readlines()
    printer()
    if noTransfer:
        read_database(data, database, invlist=[], readAll=True)
        return
    correctionsPointer = open(dabapath + '/empirical_corrections.txt')
    for invdict, orientations, compounds in invstring.get_invariom_names(names=[i.name for i in data['exp'].atoms],
                                                                         cart=[i.cart for i in data['exp'].atoms],
                                                                         dictionary=True,
                                                                         orientations=True,
                                                                         compounds=open(dabapath + '/APD_MAP.txt'),
                                                                         corrections=correctionsPointer,
                                                                         dynamic=True,
                                                                         output=printer,
                                                                         verbose=False,
                                                                         newH=config.get_config_valueBool('APD', 'newH'),
                                                                         planarityThreshold=planarityThreshold):


        invlist = [item for _, item in compounds.items()]
        read_database(data, database, invlist)
        kill = False
        misses = []
        for atom in data['exp'].atoms:
            invname = invdict[atom.name]
            orientation = orientations[atom.name]
            atom.add_invariom(invname, orientation)
            if invname in compounds.keys() and not atom.model_compound:
                modelname = compounds[invname]
                atom.model_compound = data[modelname]
                atom.set_active_invariom(invname)
            elif invname not in compounds.keys() and not atom.model_compound:
                misses.append((atom, invname))
                kill = True
                printer('Trying dynamic invariom name for atom {}. {} not available'.format(atom.name, invname))
    printer()
    if kill:
        for atom in misses:
            atom = atom[0]
            neighbours = cg.get_framework_neighbours(atom, useH=False)
            if len(neighbours) > 1:
                for atom2 in neighbours:
                    if not atom2.get_active_invariom():
                        message = 'Error: The following invarioms are missing in the database:\n'
                        message += '\n'.join(['{:<6} <-> {:>}'.format(miss[0].name, miss[1]) for miss in misses])
                        message += '\n\n!!!Terminating program due to fatal error: MISSING INVARIOMS!!!'
                        core.apd_exit(message=message)
                atom.tolerate()
                printer('WARNING: Tolerating missing invariom for {}.'.format(atom.name))
            else:
                message = 'Error: The following invarioms are missing in the database:\n'
                message += '\n'.join(['{:<6} <-> {:>}'.format(miss[0].name, miss[1]) for miss in misses])
                message += '\n\n!!!Terminating program due to fatal error: MISSING INVARIOMS!!!'
                core.apd_exit(message=message)
        return
        message = 'Error: The following invarioms are missing in the database:\n'
        message += '\n'.join(['{:<6} <-> {:>}'.format(miss[0].name, miss[1]) for miss in misses])
        message += '\n\n!!!Terminating program due to fatal error: MISSING INVARIOMS!!!'
        core.apd_exit(message=message)