def update(self, match='inv', *args, **kwargs): """ Main interface function for transfering ADP from model compounds the the 'exp' molecule. All necessary funtions and methods will be called by this method. :param match: String specifying how relative orientations should be determined. 'inv' uses the invstring2 module to determine orientations. 'geom' uses iterative shape recognition. :param args: ... :param kwargs: ... """ if match == 'inv': self._link() self._get_atoms() self._get_distances() self._find_molecules() if match == 'inv': # self._get_code_atom_links() self._get_prochirality() # =================================================================== # self._get_orientations() #=================================================================== self._transfer_adp() elif match == 'geom': self._match_molecules() elif match == 'trust': self._trust_molecules() else: apd_exit(1, 'Unknown ADP transfer method. Use inv/geom/trust.') self._update_H_ADP()
def register_IOP(self, IOP): """ Adds an IOP to the Loader.IOPs attribute and makes it active. """ self.IOP = IOP try: Loader.IOPs[IOP.get_id()] = IOP except AttributeError: apd_exit(1, '\nError: No valid file found.\nTerminating APD-Toolkit.', report=False)
def update_H_ADP(self): if self.adp['flag'] == 'iso': return try: # self.adp['cart_meas'] = array(self.partner[0].adp['cart_meas'] * 1.2) self.adp['flag'] = 'riding' uiso = cg.Uiso(self.partner[0].adp['cart_meas'] * 1.2) self.adp['cart_meas'] = array([uiso, uiso, uiso, 0, 0, 0]) except: apd_exit('error in ATOM.update_H_ADP') self.adp['cart_meas'] = None
def run(pluginManager): """ Called by the plugin manager. Asks the plugin manager for user input and configures the database generator to generate the desired database file. """ import lauescript.database as db from lauescript.types.data import GENERATOR from lauescript.laueio.inout import FlexLoad from lauescript.laueio.loader import Loader from lauescript.core.core import apd_exit printer = pluginManager.setup() data = DATA() loader = Loader(printer) pluginManager.register_variable(loader, 'loader') pluginManager.register_variable(data, 'data') dabapath = '.' match = pluginManager.arg('match') if pluginManager.arg('generate'): printer('Generating new micro database.') data = GENERATOR([], True) path = pluginManager.arg('load') db.generate_micro_database(data, pluginManager.get_frequency_cutoff(), path=path, printer=printer, clustersize=int(pluginManager.arg('cluster')), frequency_scale=pluginManager.get_config_valueFloat('Database', 'frequency_scale')) apd_exit(0) data = pluginManager.get_variable() printer('Loading data.') filename = pluginManager.arg('load') printer('Setting ADP transfer mode to pattern matching.\n') loader = Loader(printer) pluginManager.register_variable(loader, 'loader') if filename: if '.apd' in filename: printer('APD-Script file found. Executing script.') from lauescript.scripting import Parser parser = Parser(filename, indent=5) printer.enter() parser() printer.exit() apd_exit() FlexLoad(data, loader, dabapath, pluginManager, filename, noTransfer=True) # data['exp'] = quickLoad(pluginManager, filename) else: FlexLoad(data, loader, dabapath, pluginManager, noTransfer=True) # data['exp'] = quickLoad(pluginManager, filename) printer('Loading successful.') printer.spacer() printer('\nUsing option {} to transfer ADPs.'.format(match)) data.update(match=match)
def load(self, name): """ Creates and returns a molecule object. """ Loader.read_files.append(self.IOP.filename) try: self.IOP.read() except IOError as a: # self.printer('Error: No valid file named {} found'.format(self.IOP.filename)) apd_exit(1, '\nError: No valid file named {} found.\nTerminating APD-Toolkit.'.format(self.IOP.filename)) molecule = MOLECULE(name, cell=self.IOP.get_cell()) for atom in self.IOP.provide(['cart', 'frac', 'adp_cart', 'element']): if not atom[4].startswith('W'): molecule.add_atom(name=atom[0], cart=atom[1], frac=atom[2], molecule=molecule, element=atom[4]) molecule[atom[0]].give_adp(key='cart_meas', value=atom[3]) molecule.get_distances() return molecule
def _taste_file(self, filename): """ Reads the first few line of the file corresponding to 'filename' in order to determine its file format. This makes the selection of the correct IOP independent of the name of the file thereby allowing shelx style files named 'xd.res' to be correctly identified as shelx style .res files. :param filename: String representing the path to the file to 'taste'. :return: """ for headsize in [10, 100, 500]: try: with open(filename) as fp: head = fp.readlines(headsize) except IOError: apd_exit(1, '\n\nERROR: Cannot find file >>>{}<<<'.format(filename)) for tasteMehod in [method for method in dir(self) if method.startswith('_tastes_like_')]: taste = getattr(self, tasteMehod)(head) if taste: return taste(filename) self.printer("File content not familiar. Relying of file name for file format.\n") return False
def no_file_exit(self): """ Exits the APD-Toolkit. """ message = 'ERROR: No suitable file found in working directory.' apd_exit(1, message=message)
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)
def parse_master_file(self): self.key_dict = {} self.master_body = [] keyswitch = False atomsswitch = False self.chemcons = {} try: filepointer = open(self.master_file_name) except IOError: apd_exit(3, '\n\nERROR: Cannot find file {}'.format(self.master_file_name)) for line in filepointer.readlines(): if line.lstrip(' ').startswith('!'): continue if 'END SCAT' in line: atomsswitch = True if line.startswith('DUM'): atomsswitch = False if atomsswitch: sline = [item for item in line[:-1].split(' ') if item] try: self.chemcons[sline[0]] = sline[12] except IndexError: pass if line.startswith('CELL') and self.cell is None: self.cell = list([float(i) for i in line.split(' ')[1:] if i]) elif line.startswith('END KEY'): keyswitch = False elif line.startswith('KEY'): keyswitch = True if keyswitch: sline = [i.rstrip('\n') for i in line.split(' ') if i] if '(' in sline[0] and ')' in sline[0]: key = sline[0] if key in self.chemcons.keys(): self.key_dict[key] = self.key_dict[self.chemcons[key]] self.master_body.append(key+'\n') continue atom_key_dict = KEY(key) atom_key_dict['xyz'] = sline[1] try: atom_key_dict['U2'] = sline[2] atom_key_dict['U3'] = sline[3] atom_key_dict['U4'] = sline[4] except IndexError: atom_key_dict['U2'] = 0 atom_key_dict['U3'] = 0 atom_key_dict['U4'] = 0 try: atom_key_dict['Mono'] = sline[5] atom_key_dict['Dipo'] = sline[6] atom_key_dict['Quato'] = sline[7] atom_key_dict['Okto'] = sline[8] atom_key_dict['Hexa'] = sline[9] except KeyError: pass except IndexError: atom_key_dict['Mono'] = 0 atom_key_dict['Dipo'] = 0 atom_key_dict['Quato'] = 0 atom_key_dict['Okto'] = 0 atom_key_dict['Hexa'] = 0 self.key_dict[key] = atom_key_dict self.master_body.append(atom_key_dict) else: self.master_body.append(line) else: self.master_body.append(line) filepointer.close()