Skip to content

Commit

Permalink
enable debugging.
Browse files Browse the repository at this point in the history
Add cif-read Phase object
  • Loading branch information
rozyczko committed Aug 31, 2023
1 parent a8ade23 commit c05b0a0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
6 changes: 3 additions & 3 deletions easyDiffractionApp/Examples/PbSO4/models/pbso4.cif
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
data_pbso4

_cell.length_a 8.4693(1)
_cell.length_b 5.3910(1)
_cell.length_c 6.9506(1)
_cell.length_a 8.4693
_cell.length_b 5.3910
_cell.length_c 6.9506
_cell.angle_alpha 90
_cell.angle_beta 90
_cell.angle_gamma 90
Expand Down
35 changes: 35 additions & 0 deletions easyDiffractionApp/Logic/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from PySide6.QtCore import QFile, QTextStream, QIODevice
from PySide6.QtQml import QJSValue

from easyDiffractionLib import Phases, Phase, Lattice, Site, SpaceGroup
from easyCrystallography.Components.AtomicDisplacement import AtomicDisplacement

from EasyApp.Logic.Logging import console
from Logic.Helpers import IO
from Logic.Calculators import CryspyParser
Expand Down Expand Up @@ -84,6 +87,8 @@ def __init__(self, parent):
self._spaceGroupNames = self.createSpaceGroupNames()
self._isotopesNames = self.createIsotopesNames()

self.phases = Phases()

# QML accessible properties

@Property('QVariant', constant=True)
Expand Down Expand Up @@ -139,6 +144,27 @@ def structViewCellModel(self):
def structViewAxesModel(self):
return self._structViewAxesModel

def addDefaultPhase(self):
default_phase = self._defaultPhase()
r = re.compile('(.+[^0-9])\d*$')
known_phases = [r.findall(s)[0] for s in self.phases.phase_names] # Strip out any 1, 2, 3 etc we may have added
if default_phase.name in known_phases:
idx = known_phases.count(default_phase.name)
default_phase.name = default_phase.name + str(idx)
# print('Disabling scale')
default_phase.scale.fixed = True
self.phases.append(default_phase)

# @staticmethod
def _defaultPhase(self):
space_group = SpaceGroup('F d -3:2')
cell = Lattice(5.0, 3.0, 4.0, 90, 90, 90)
adp = AtomicDisplacement("Uiso")
atom = Site(label='O', specie='O', fract_x=0.0, fract_y=0.0, fract_z=0.0, adp=adp)#, interface=self._interface)
phase = Phase('Test', spacegroup=space_group, cell=cell)#, interface=self._interface)
phase.add_atom(atom)
return phase

# QML accessible methods

@Slot(str, str, result=str)
Expand All @@ -152,6 +178,7 @@ def atomData(self, typeSymbol, key):
def addDefaultModel(self):
console.debug("Adding default model(s)")
self.loadModelsFromEdCif(_DEFAULT_CIF_BLOCK)
self.addDefaultPhase()

@Slot('QVariant')
def loadModelsFromResources(self, fpaths):
Expand Down Expand Up @@ -179,6 +206,9 @@ def loadModelsFromFiles(self, fpaths):
edCif = file.read()
self.loadModelsFromEdCif(edCif)

phase = Phases.from_cif_file(fpath)
self.phases.append(phase)

@Slot(str)
def loadModelsFromEdCif(self, edCif):
cryspyObj = self._proxy.data._cryspyObj
Expand Down Expand Up @@ -311,6 +341,7 @@ def duplicateLoopRow(self, category, idx):
# Private methods

def cryspyObjCrystals(self):
print("\ncryspyObjCrystals\n")
cryspyObj = self._proxy.data._cryspyObj
cryspyModelType = cryspy.E_data_classes.cl_1_crystal.Crystal
models = [block for block in cryspyObj.items if type(block) == cryspyModelType]
Expand All @@ -333,6 +364,7 @@ def removeDataBlockLoopRow(self, category, rowIndex):
console.debug(IO.formatMsg('sub', 'Intern dict', 'removed', f'{block}[{blockIdx}].{category}[{rowIndex}]'))

def appendDataBlockLoopRow(self, category):
print("\nappendDataBlockLoopRow\n")
block = 'model'
blockIdx = self._currentIndex

Expand Down Expand Up @@ -658,11 +690,14 @@ def setCurrentModelStructViewAxesModel(self):
self.structViewAxesModelChanged.emit()

def setCurrentModelStructViewAtomsModel(self):
print("\nsetCurrentModelStructViewAtomsModel\n")
structViewModel = set()
currentModelIndex = self._proxy.model.currentIndex
models = self.cryspyObjCrystals()
spaceGroup = [sg for sg in models[currentModelIndex].items if type(sg) == cryspy.C_item_loop_classes.cl_2_space_group.SpaceGroup][0]
atoms = self._dataBlocks[self._currentIndex]['loops']['_atom_site']


# Add all atoms in the cell, including those in equivalent positions
for atom in atoms:
symbol = atom['type_symbol']['value']
Expand Down
18 changes: 12 additions & 6 deletions easyDiffractionApp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,22 @@
engine.load(resourcePaths.splashScreenQml)
console.debug('Splash screen QML component loaded')

from Logic.PyProxy import PyProxy
pyproxy = PyProxy()
engine.rootContext().setContextProperty('pyProxy', pyproxy)

if not engine.rootObjects():
sys.exit(-1)
console.debug('QML engine has root component')

from Logic.Helpers import PyProxyWorker
from PySide6.QtCore import QThreadPool
worker = PyProxyWorker(engine)
worker.pyProxyExposedToQml.connect(lambda: engine.load(resourcePaths.mainQml))
threadpool = QThreadPool.globalInstance()
threadpool.start(worker.exposePyProxyToQml)
#from Logic.Helpers import PyProxyWorker
#from PySide6.QtCore import QThreadPool
#worker = PyProxyWorker(engine)
#worker.pyProxyExposedToQml.connect(lambda: engine.load(resourcePaths.mainQml))
#threadpool = QThreadPool.globalInstance()
#threadpool.start(worker.exposePyProxyToQml)

engine.load(resourcePaths.mainQml)
console.debug('PyProxy object is creating in a separate thread and exposing to QML')

console.debug('Application event loop is about to start')
Expand Down

0 comments on commit c05b0a0

Please sign in to comment.