Skip to content

Commit

Permalink
Small refactoring and imports improved
Browse files Browse the repository at this point in the history
  • Loading branch information
dkratzert committed Feb 22, 2024
1 parent 9b24333 commit b98090f
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 31 deletions.
4 changes: 2 additions & 2 deletions finalcif/equip_property/author_loop_templates.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# Daniel Kratzert <[email protected]> wrote this file. As long as you retain
# this notice you can do whatever you want with this stuff. If we meet some day,
# and you think this stuff is worth it, you can buy me a beer in return.
# ----------------------------------------------------------------------------
import re
from contextlib import suppress
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
Expand Down Expand Up @@ -51,7 +51,7 @@ class Author:


class AuthorLoops():
def __init__(self, ui: Ui_FinalCifWindow, cif: CifContainer, app: 'AppWindow'):
def __init__(self, ui: Ui_FinalCifWindow, cif: CifContainer, app: AppWindow):
self.ui = ui
self.cif = cif
self.app = app
Expand Down
3 changes: 2 additions & 1 deletion finalcif/equip_property/equipment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from bisect import bisect
from pathlib import Path
from typing import List, Dict
Expand All @@ -22,7 +23,7 @@

class Equipment:

def __init__(self, app: 'AppWindow', settings: FinalCifSettings):
def __init__(self, app: AppWindow, settings: FinalCifSettings):
self.app = app
self.settings = settings
if app:
Expand Down
4 changes: 2 additions & 2 deletions finalcif/equip_property/properties.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import threading
import time
from contextlib import suppress
Expand All @@ -15,15 +16,14 @@
from finalcif.tools.settings import FinalCifSettings
from finalcif.tools import misc


from typing import TYPE_CHECKING

if TYPE_CHECKING:
from finalcif.appwindow import AppWindow


class Properties(QtCore.QObject):
def __init__(self, parent: 'AppWindow', settings: FinalCifSettings):
def __init__(self, parent: AppWindow, settings: FinalCifSettings):
super().__init__(parent=parent)
self.app = parent
self.settings = settings
Expand Down
1 change: 0 additions & 1 deletion finalcif/equip_property/tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pathlib import Path
from typing import Union

import gemmi.cif
Expand Down
4 changes: 1 addition & 3 deletions finalcif/finalcif_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
# and you think this stuff is worth it, you can buy me a beer in return.
# Dr. Daniel Kratzert
# ----------------------------------------------------------------------------
import os
import sys
import time
import traceback
from pathlib import Path
from typing import Type

from PyQt5.QtGui import QIcon

from finalcif import VERSION
from finalcif.app_path import application_path
from finalcif.appwindow import AppWindow, DEBUG, app
Expand Down Expand Up @@ -62,6 +59,7 @@ def main():
file = None
app.setQuitOnLastWindowClosed(True)
w = AppWindow(file=file)
from PyQt5.QtGui import QIcon
app.setWindowIcon(QIcon(os.path.join(application_path, r'icon/finalcif2.png')))
w.setWindowTitle('FinalCif v{}'.format(VERSION))
# w.showMaximized() # For full screen view
Expand Down
1 change: 0 additions & 1 deletion finalcif/gui/custom_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from finalcif.cif.text import retranslate_delimiter
from finalcif.gui.combobox import MyComboBox
from finalcif.gui.dialogs import show_keyword_help
from finalcif.gui.edit_button import FloatingButtonWidget
from finalcif.gui.mixins import ItemTextMixin
from finalcif.gui.plaintextedit import MyQPlainTextEdit

Expand Down
3 changes: 2 additions & 1 deletion finalcif/gui/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMessageBox, QMainWindow, QFileDialog, QVBoxLayout, QTextEdit, \
QPushButton, QFrame, QApplication
QPushButton, QFrame

from finalcif import VERSION

Expand Down Expand Up @@ -226,6 +226,7 @@ def cif_file_save_dialog(filename: str) -> str:

if __name__ == '__main__':
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication

app = QApplication.instance()
if app is None:
Expand Down
4 changes: 2 additions & 2 deletions finalcif/report/report_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ def __init__(self, cif: CifContainer, paragraph: Paragraph, ref: ReferenceList):
refineref = SHELXLReference()
if 'OLEX' in refined.upper():
refineref = Olex2Reference()
if 'NOSPHERA2' in solution_prog.upper() or 'NOSPHERA2' in cif['_refine_special_details'].upper() \
or 'NOSPHERA2' in cif['_olex2_refine_details'].upper():
if ('NOSPHERA2' in solution_prog.upper() or 'NOSPHERA2' in cif['_refine_special_details'].upper()
or 'NOSPHERA2' in cif['_olex2_refine_details'].upper()):
refineref = [Olex2Reference(), Nosphera2Reference()]
refine_coef = gstr(cif['_refine_ls_structure_factor_coef'])
if manual_method:
Expand Down
27 changes: 17 additions & 10 deletions finalcif/report/templated_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,21 @@ def get_integration_program(self, cif: CifContainer) -> str:

def get_absortion_correction_program(self, cif: CifContainer) -> str:
absdetails = cif['_exptl_absorpt_process_details'].replace('-', ' ').replace(':', '')
bruker_scaling = cif['_computing_bruker_data_scaling'].replace('-', ' ').replace(':', '')
scale_prog, version = self._get_scaling_program(absdetails)
if not scale_prog:
scale_prog, version = self._get_scaling_program(bruker_scaling)
if 'SORTAV' in absdetails.upper():
scale_prog = 'SORTAV'
self.literature['absorption'] = SORTAVReference()
if 'crysalis' in absdetails.lower():
scale_prog = 'SCALE3 ABSPACK'
# see above also
scale_prog += " " + version

return scale_prog

def _get_scaling_program(self, absdetails: str) -> tuple[str, str]:
scale_prog = ''
version = ''
if 'SADABS' in absdetails.upper() or 'TWINABS' in absdetails.upper():
Expand All @@ -456,15 +471,7 @@ def get_absortion_correction_program(self, cif: CifContainer) -> str:
else:
scale_prog = 'TWINABS'
self.literature['absorption'] = SadabsTwinabsReference()
if 'SORTAV' in absdetails.upper():
scale_prog = 'SORTAV'
self.literature['absorption'] = SORTAVReference()
if 'crysalis' in absdetails.lower():
scale_prog = 'SCALE3 ABSPACK'
# see above also
scale_prog += " " + version

return scale_prog
return scale_prog, version

def solution_method(self, cif: CifContainer) -> str:
solution_method = gstr(cif['_atom_sites_solution_primary']) or '??'
Expand All @@ -487,7 +494,7 @@ def refinement_prog(self, cif: CifContainer) -> str:
if 'OLEX' in refined.upper():
self.literature['refinement'] = Olex2Reference()
if ('NOSPHERA2' in refined.upper() or 'NOSPHERA2' in cif['_refine_special_details'].upper() or
'NOSPHERAT2' in cif['_olex2_refine_details'].upper()):
'NOSPHERAT2' in cif['_olex2_refine_details'].upper()):
self.literature['refinement'] = Nosphera2Reference()
return refined.split()[0]

Expand Down
4 changes: 3 additions & 1 deletion finalcif/tools/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def _load_settings(self, property: str, item_name: str):
self.settings.beginGroup(property)
try:
v = self.settings.value(item_name)
except TypeError:
except TypeError as e:
print(f"DBG> Item name '{item_name}' could not be loaded from settings.")
print(e)
v = None
self.settings.endGroup()
return v
Expand Down
4 changes: 1 addition & 3 deletions tests/test_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
# ----------------------------------------------------------------------------
import os

import gemmi.cif

os.environ["RUNNING_TEST"] = 'True'
import unittest
from pathlib import Path
Expand Down Expand Up @@ -244,4 +242,4 @@ def test_move_row_up_from_start_save_and_load_again(self):
except AttributeError:
self.assertEqual('C', as_string(c.loops[3][0, 0]))
self.assertEqual('H', as_string(c.loops[3][1, 0]))
self.assertEqual('O', as_string(c.loops[3][2, 0]))
self.assertEqual('O', as_string(c.loops[3][2, 0]))
1 change: 0 additions & 1 deletion tests/test_main_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import unittest
from pathlib import Path

import pytest
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QColor

Expand Down
2 changes: 1 addition & 1 deletion tests/test_saint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# this notice you can do whatever you want with this stuff. If we meet some day,
# and you think this stuff is worth it, you can buy me a beer in return.
# ----------------------------------------------------------------------------
import os
import unittest
from pathlib import Path

Expand All @@ -13,6 +12,7 @@

data = Path('.')


class MyTestCase(unittest.TestCase):

def test_saint_repr(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_templated_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_ccdc_num_in_table(self):
t = TemplatedReport()
ok = t.make_templated_report(options=self.options,
cif=CifContainer(self.testcif),
output_filename=self.reportdoc,
output_filename=str(self.reportdoc),
picfile=self.report_pic,
template_path=self.text_template)
self.assertTrue(ok)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_workfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def setUp(self) -> None:
def tearDown(self) -> None:
Path('foo.cif').unlink(missing_ok=True)
Path('tests/examples/work/cu_BruecknerJK_153F40_0m-finalcif.cif').unlink(missing_ok=True)
self.myapp.ui.trackChangesCifCheckBox.setChecked(False)
self.myapp.close()

def test_save_action(self):
self.myapp.save_current_cif_file()
self.assertEqual(True, (data / 'examples/work/cu_BruecknerJK_153F40_0m-finalcif.cif').exists())
self.myapp.ui.trackChangesCifCheckBox.setChecked(False)


class TestWorkfolder(unittest.TestCase):
Expand Down

0 comments on commit b98090f

Please sign in to comment.