Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to new system classes. #3

Merged
merged 4 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions crystal_builder_step/crystal_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import pprint

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 __

Expand Down Expand Up @@ -180,7 +180,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(
Expand All @@ -197,20 +198,20 @@ 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]
files = [p for p in implib.files(package) if aflow_prototype in str(p)]
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']
Expand Down Expand Up @@ -242,7 +243,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
Expand All @@ -253,8 +254,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
Expand Down
1 change: 0 additions & 1 deletion crystal_builder_step/crystal_builder_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import logging
import seamm
import pprint # noqa: F401

logger = logging.getLogger(__name__)

Expand Down
201 changes: 100 additions & 101 deletions crystal_builder_step/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -302,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']
Expand All @@ -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,
Expand All @@ -351,7 +349,6 @@ def get_bibtex(prototype):


def test():
import textwrap
import bibtexparser
import reference_handler

Expand Down Expand Up @@ -385,89 +382,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)
2 changes: 0 additions & 2 deletions crystal_builder_step/tk_crystal_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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