From 4cf2953f13bfad6d1fc0b8d944e4b4a0ce767c97 Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Sat, 30 Jan 2021 13:00:05 -0500 Subject: [PATCH 1/4] Adapted to the new system classes. --- crystal_builder_step/crystal_builder.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crystal_builder_step/crystal_builder.py b/crystal_builder_step/crystal_builder.py index 64707e0..114089d 100644 --- a/crystal_builder_step/crystal_builder.py +++ b/crystal_builder_step/crystal_builder.py @@ -11,6 +11,7 @@ import pprint import crystal_builder_step +import molsystem import seamm from seamm_util import ureg, Q_ # noqa: F401 import seamm_util.printing as printing @@ -180,7 +181,8 @@ def run(self): next_node = super().run(printer) # Get the system - system = self.get_variable('_system') + system_db = self.get_variable('_system_db') + configuration = system_db.system.configuration # Get the values of the parameters, dereferencing any variables P = self.parameters.current_values_to_dict( @@ -197,7 +199,7 @@ def run(self): self.logger.debug(f'Formatted values:\n{pprint.pformat(PP)}') printer.important(__(self.description_text(PP), indent=self.indent)) - # Create the system from the cif file for the prototype + # Create the configuration from the cif file for the prototype aflow_prototype = P['AFLOW prototype'] package = self.__module__.split('.')[0] @@ -205,12 +207,12 @@ def run(self): if len(files) > 0: path = files[0] data = path.read_text() - system.from_cif_text(data) + configuration.from_cif_text(data) # Now set the cell parameters. If unmentioned the lattice parameters # get the previous value, e.g. a, a, c. The angles are those of the # prototype if not mentioned. - a0, b0, c0, alpha0, beta0, gamma0 = system.cell.cell().parameters + a0, b0, c0, alpha0, beta0, gamma0 = configuration.cell.parameters data = crystal_builder_step.prototype_data[aflow_prototype] cell = data['cell'] @@ -242,7 +244,7 @@ def run(self): new_cell.append(last) self.logger.debug(f'cell = {new_cell}') - system.cell.set_cell(new_cell) + configuration.cell.parameters = new_cell # And the elements for the sites. Not that symmetry has been lowered # to P1 @@ -253,8 +255,8 @@ def run(self): symbol = self.get_variable(symbol) symbols.extend([symbol] * mult) self.logger.debug(f'symbols = {symbols}') - atnos = system.atoms.to_atnos(symbols) - column = system.atoms.get_column('atno') + atnos = molsystem.elements.to_atnos(symbols) + column = configuration.atoms.get_column('atno') column[0:] = atnos # Requested citations for the AFLOW protoype library From 86aae386b9384d271eb5e6d9ff79bbdfe98e26a6 Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Tue, 2 Feb 2021 14:25:13 -0500 Subject: [PATCH 2/4] Updated pinned requirements. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f9b645c..e535a5c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ openpyxl==3.0.5 pycifrw==4.4.1 -seamm==2020.12.4 +seamm==2021.2.2 seamm-util==2020.12.2 seamm-widgets==2020.12.3 From bcdcd2559cc2a70ecc1fc785c419062bba6f9943 Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Tue, 2 Feb 2021 16:16:58 -0500 Subject: [PATCH 3/4] Fixed issues flagged by LGTM. --- crystal_builder_step/crystal_builder.py | 1 - .../crystal_builder_parameters.py | 1 - crystal_builder_step/parse.py | 198 +++++++++--------- crystal_builder_step/tk_crystal_builder.py | 2 - 4 files changed, 99 insertions(+), 103 deletions(-) diff --git a/crystal_builder_step/crystal_builder.py b/crystal_builder_step/crystal_builder.py index 114089d..b637e1c 100644 --- a/crystal_builder_step/crystal_builder.py +++ b/crystal_builder_step/crystal_builder.py @@ -13,7 +13,6 @@ import crystal_builder_step import molsystem import seamm -from seamm_util import ureg, Q_ # noqa: F401 import seamm_util.printing as printing from seamm_util.printing import FormattedText as __ diff --git a/crystal_builder_step/crystal_builder_parameters.py b/crystal_builder_step/crystal_builder_parameters.py index f150f41..48155d7 100644 --- a/crystal_builder_step/crystal_builder_parameters.py +++ b/crystal_builder_step/crystal_builder_parameters.py @@ -5,7 +5,6 @@ import logging import seamm -import pprint # noqa: F401 logger = logging.getLogger(__name__) diff --git a/crystal_builder_step/parse.py b/crystal_builder_step/parse.py index f1a7819..a8bf22e 100755 --- a/crystal_builder_step/parse.py +++ b/crystal_builder_step/parse.py @@ -195,7 +195,6 @@ def run(filename='prototypes.xlsx'): wb = openpyxl.load_workbook(filename=filename) ws = wb['Sheet1'] - row = 1 row_max = ws.max_row data = { @@ -324,19 +323,18 @@ def get_bibtex(prototype): pages = f'{first}-{last}' template = string.Template( - textwrap.dedent( - """\ - @article{$prototype, - author = {$author_list}, - title = {$title}, - journal = {$journal}, - volume = {$volume}, - pages = {$pages}, - year = $year, - } - """ - ) + """\ + @article{$prototype, + author = {$author_list}, + title = {$title}, + journal = {$journal}, + volume = {$volume}, + pages = {$pages}, + year = $year, + } + """ ) + citation = template.substitute( prototype=prototype, author_list=author_list, @@ -385,89 +383,91 @@ def test(): import urllib.parse import urllib.request - if True: - test() - elif False: - bibtex = '' - with open('prototypes.json', 'r') as fd: - data = json.load(fd) - - for prototype in data['AFLOW prototype']: - print(prototype) - if prototype in bib: - text = bib[prototype] - else: - text = get_bibtex(prototype) - bibtex += text - with open('references2.bib', 'w') as fd: - fd.write(bibtex) - elif False: - run() - elif False: - # Fix the prototypes to have added formula part in some cases - # Get the data from the json - with open('prototypes.json', 'r') as fd: - data = json.load(fd) - - aflow_prototypes = [] - for hyperlink in data['hyperlink']: - url = urllib.parse.urlsplit(hyperlink) - path = url.path - root, extension = os.path.splitext(os.path.basename(path)) - aflow_prototypes.append(root) - - data['AFLOW prototype'] = aflow_prototypes - - with open('prototypes2.json', 'w') as fd: - json.dump(data, fd, indent=4) - else: - # Get the data from the json - with open('prototypes2.json', 'r') as fd: - data = json.load(fd) - - cp = data['cell parameters'] = [] - sites = data['sites'] = [] - # Fetch the cif file to get the adjustable parameters - for hyperlink in data['hyperlink']: - url = urllib.parse.urlsplit(hyperlink) - path = url.path - root, extension = os.path.splitext(os.path.basename(path)) - filename = root + '.cif' - new_path = os.path.join('.', filename) - if not os.path.exists(new_path): - print(f'{new_path} does not exist') - else: - try: - cif = CifFile.ReadCif(new_path) - except Exception: - print(f'Error in {new_path}\n\n') - raise - tmp = cif['findsym-output'] - params = tmp['_aflow_params'].split(',') - values = tmp['_aflow_params_values'].split(',') - - cell_parameters = [] - for param, value in zip(params, values): - if param[0] in ('x', 'y', 'z'): - break - if param[0] == '\\': - cell_parameters.append((param[1:], value)) - elif param == 'b/a': - cell_parameters.append(('b', tmp['_cell_length_b'])) - elif param == 'c/a': - cell_parameters.append(('c', tmp['_cell_length_c'])) - else: - cell_parameters.append((param, value)) - cp.append(cell_parameters) - - site_data = [] - for symbol, site, mult in zip( - tmp['_atom_site_type_symbol'], - tmp['_atom_site_Wyckoff_label'], - tmp['_atom_site_symmetry_multiplicity'] - ): - site_data.append((site, int(mult), symbol)) - sites.append(site_data) - - with open('prototypes3.json', 'w') as fd: - json.dump(data, fd, indent=4) + test() + + # if True: + # test() + # elif False: + # bibtex = '' + # with open('prototypes.json', 'r') as fd: + # data = json.load(fd) + + # for prototype in data['AFLOW prototype']: + # print(prototype) + # if prototype in bib: + # text = bib[prototype] + # else: + # text = get_bibtex(prototype) + # bibtex += text + # with open('references2.bib', 'w') as fd: + # fd.write(bibtex) + # elif False: + # run() + # elif False: + # # Fix the prototypes to have added formula part in some cases + # # Get the data from the json + # with open('prototypes.json', 'r') as fd: + # data = json.load(fd) + + # aflow_prototypes = [] + # for hyperlink in data['hyperlink']: + # url = urllib.parse.urlsplit(hyperlink) + # path = url.path + # root, extension = os.path.splitext(os.path.basename(path)) + # aflow_prototypes.append(root) + + # data['AFLOW prototype'] = aflow_prototypes + + # with open('prototypes2.json', 'w') as fd: + # json.dump(data, fd, indent=4) + # else: + # # Get the data from the json + # with open('prototypes2.json', 'r') as fd: + # data = json.load(fd) + + # cp = data['cell parameters'] = [] + # sites = data['sites'] = [] + # # Fetch the cif file to get the adjustable parameters + # for hyperlink in data['hyperlink']: + # url = urllib.parse.urlsplit(hyperlink) + # path = url.path + # root, extension = os.path.splitext(os.path.basename(path)) + # filename = root + '.cif' + # new_path = os.path.join('.', filename) + # if not os.path.exists(new_path): + # print(f'{new_path} does not exist') + # else: + # try: + # cif = CifFile.ReadCif(new_path) + # except Exception: + # print(f'Error in {new_path}\n\n') + # raise + # tmp = cif['findsym-output'] + # params = tmp['_aflow_params'].split(',') + # values = tmp['_aflow_params_values'].split(',') + + # cell_parameters = [] + # for param, value in zip(params, values): + # if param[0] in ('x', 'y', 'z'): + # break + # if param[0] == '\\': + # cell_parameters.append((param[1:], value)) + # elif param == 'b/a': + # cell_parameters.append(('b', tmp['_cell_length_b'])) + # elif param == 'c/a': + # cell_parameters.append(('c', tmp['_cell_length_c'])) + # else: + # cell_parameters.append((param, value)) + # cp.append(cell_parameters) + + # site_data = [] + # for symbol, site, mult in zip( + # tmp['_atom_site_type_symbol'], + # tmp['_atom_site_Wyckoff_label'], + # tmp['_atom_site_symmetry_multiplicity'] + # ): + # site_data.append((site, int(mult), symbol)) + # sites.append(site_data) + + # with open('prototypes3.json', 'w') as fd: + # json.dump(data, fd, indent=4) diff --git a/crystal_builder_step/tk_crystal_builder.py b/crystal_builder_step/tk_crystal_builder.py index de27249..319df0d 100644 --- a/crystal_builder_step/tk_crystal_builder.py +++ b/crystal_builder_step/tk_crystal_builder.py @@ -2,12 +2,10 @@ """The graphical part of a Crystal Builder step""" -import pprint # noqa: F401 import tkinter as tk import tkinter.ttk as ttk import seamm -from seamm_util import ureg, Q_, units_class # noqa: F401 import seamm_widgets as sw import crystal_builder_step # noqa: F401 From add143691bab8e794b89370935ed4ca2bdbb918c Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Tue, 2 Feb 2021 16:23:18 -0500 Subject: [PATCH 4/4] Fixed introduced bugs. --- crystal_builder_step/parse.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crystal_builder_step/parse.py b/crystal_builder_step/parse.py index a8bf22e..52b252c 100755 --- a/crystal_builder_step/parse.py +++ b/crystal_builder_step/parse.py @@ -301,7 +301,7 @@ def get_bibtex(prototype): try: cif = CifFile.ReadCif(prototype + '.cif') except Exception: - print(f'Error in {new_path}\n\n') + print(f'Error in {prototype}.cif\n\n') raise tmp = cif['findsym-output'] authors = tmp['_publ_author_name'] @@ -334,7 +334,7 @@ def get_bibtex(prototype): } """ ) - + citation = template.substitute( prototype=prototype, author_list=author_list, @@ -349,7 +349,6 @@ def get_bibtex(prototype): def test(): - import textwrap import bibtexparser import reference_handler