Skip to content

Commit

Permalink
Merge branch 'master' into roles
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlLevik committed Jan 21, 2020
2 parents 5e86af2 + ddb6519 commit 5250366
Show file tree
Hide file tree
Showing 8 changed files with 894 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -28,6 +28,7 @@ before_install:
- mysql -u root -D ispybtest < grants/ispyb_processing.sql
- mysql -u root -D ispybtest < grants/ispyb_import.sql
- mysql -u root -e "CREATE USER ispyb_api@'localhost' IDENTIFIED BY 'password_1234'; GRANT ispyb_processing to ispyb_api@'localhost'; GRANT ispyb_import to ispyb_api@'localhost'; SET DEFAULT ROLE ispyb_processing FOR ispyb_api@'localhost';"
- mysql -u root -e "CREATE USER ispyb_api_future@'localhost' IDENTIFIED BY 'password_4321'; GRANT SELECT ON ispybtest.* to ispyb_api_future@'localhost';"

before_script:
- cp conf/config.example.cfg conf/config.cfg
Expand Down
9 changes: 9 additions & 0 deletions conf/config.example.cfg
Expand Up @@ -7,3 +7,12 @@ port = 3306
db = ispybtest
reconn_attempts = 6
reconn_delay = 1

[ispyb]
username = ispyb_api_future
password = password_4321
host = localhost
port = 3306
database = ispybtest
reconn_attempts = 6
reconn_delay = 1
225 changes: 225 additions & 0 deletions ispyb/model/__future__.py
Expand Up @@ -105,11 +105,41 @@ def __exit__(cm, *args):
ispyb.model.datacollection.DataCollection.integrations = (
_get_linked_autoprocintegration_for_dc
)
ispyb.model.datacollection.DataCollection.screenings = _get_linked_screenings_for_dc
ispyb.model.datacollection.DataCollection.pdb = _get_linked_pdb_for_dc
import ispyb.model.processingprogram

ispyb.model.processingprogram.ProcessingProgram.reload = _get_autoprocprogram

import ispyb.model.screening

ispyb.model.screening.Screening.outputs = _get_linked_outputs_for_screening
ispyb.model.screening.Screening.reload = _get_screening

ispyb.model.screening.ScreeningOutput.lattices = (
_get_linked_lattices_for_screening_output
)
ispyb.model.screening.ScreeningOutput.strategies = (
_get_linked_strategies_for_screening_output
)
ispyb.model.screening.ScreeningOutput.reload = _get_screening_output

ispyb.model.screening.ScreeningOutputLattice.reload = _get_screening_output_lattice

ispyb.model.screening.ScreeningStrategy.wedges = (
_get_linked_wedges_for_screening_strategy
)
ispyb.model.screening.ScreeningStrategy.reload = _get_screening_strategy

ispyb.model.screening.ScreeningStrategyWedge.sub_wedges = (
_get_linked_sub_wedges_for_screening_strategy_wedge
)
ispyb.model.screening.ScreeningStrategyWedge.reload = _get_screening_strategy_wedge

ispyb.model.screening.ScreeningStrategySubWedge.reload = (
_get_screening_strategy_sub_wedge
)


def _get_autoprocprogram(self):
# https://jira.diamond.ac.uk/browse/SCI-7414
Expand Down Expand Up @@ -173,6 +203,201 @@ def _get_linked_pdb_for_dc(self):
]


@property
def _get_linked_screenings_for_dc(self):
import ispyb.model.screening

with _db_cc() as cursor:
cursor.run(
"SELECT screeningId, comments, shortComments, programVersion "
"FROM Screening "
"WHERE dataCollectionId = %s "
"ORDER BY screeningId",
self.dcid,
)
return [
ispyb.model.screening.Screening(ir["screeningId"], self._db, preload=ir)
for ir in cursor.fetchall()
]


@property
def _get_linked_outputs_for_screening(self):
import ispyb.model.screening

with _db_cc() as cursor:
cursor.run(
"SELECT screeningOutputId, alignmentSuccess, indexingSuccess, strategySuccess, program "
"FROM ScreeningOutput "
"WHERE screeningid = %s "
"ORDER BY screeningOutputId",
self._screening_id,
)
return [
ispyb.model.screening.ScreeningOutput(
ir["screeningOutputId"], self._db, preload=ir
)
for ir in cursor.fetchall()
]


@property
def _get_linked_lattices_for_screening_output(self):
import ispyb.model.screening

with _db_cc() as cursor:
cursor.run(
"SELECT screeningOutputLatticeId, spaceGroup, "
"unitCell_a, unitCell_b, unitCell_c, "
"unitCell_alpha, unitCell_beta, unitCell_gamma "
"FROM ScreeningOutputLattice "
"WHERE screeningoutputid = %s "
"ORDER BY screeningOutputLatticeId",
self._output_id,
)
return [
ispyb.model.screening.ScreeningOutputLattice(
ir["screeningOutputLatticeId"], self._db, preload=ir
)
for ir in cursor.fetchall()
]


@property
def _get_linked_strategies_for_screening_output(self):
import ispyb.model.screening

with _db_cc() as cursor:
cursor.run(
"SELECT screeningStrategyId, anomalous, program, "
"exposureTime, rankingResolution "
"FROM ScreeningStrategy "
"WHERE screeningoutputid = %s "
"ORDER BY screeningStrategyId",
self._output_id,
)
return [
ispyb.model.screening.ScreeningStrategy(
ir["screeningStrategyId"], self._db, preload=ir
)
for ir in cursor.fetchall()
]


@property
def _get_linked_wedges_for_screening_strategy(self):
import ispyb.model.screening

with _db_cc() as cursor:
cursor.run(
"SELECT screeningStrategyWedgeId, chi, completeness, kappa, "
"multiplicity, numberOfImages, phi, resolution, wedgeNumber "
"FROM ScreeningStrategyWedge "
"WHERE screeningStrategyId = %s "
"ORDER BY screeningStrategyWedgeId",
self._strategy_id,
)
return [
ispyb.model.screening.ScreeningStrategyWedge(
ir["screeningStrategyWedgeId"], self._db, preload=ir
)
for ir in cursor.fetchall()
]


@property
def _get_linked_sub_wedges_for_screening_strategy_wedge(self):
import ispyb.model.screening

with _db_cc() as cursor:
cursor.run(
"SELECT axisEnd, axisStart, completeness, exposureTime, "
"multiplicity, numberOfImages, oscillationRange, resolution, "
"rotationAxis, subWedgeNumber, transmission, "
"screeningStrategySubWedgeId "
"FROM ScreeningStrategySubWedge "
"WHERE screeningStrategyWedgeId = %s "
"ORDER BY screeningStrategySubWedgeId",
self._wedge_id,
)
return [
ispyb.model.screening.ScreeningStrategySubWedge(
ir["screeningStrategySubWedgeId"], self._db, preload=ir
)
for ir in cursor.fetchall()
]


def _get_screening(self):
with _db_cc() as cursor:
cursor.run(
"SELECT comments, shortComments, programVersion "
"FROM Screening "
"WHERE screeningId = %s",
self._screening_id,
)
self._data = cursor.fetchone()


def _get_screening_output(self):
with _db_cc() as cursor:
cursor.run(
"SELECT alignmentSuccess, indexingSuccess, strategySuccess, program "
"FROM ScreeningOutput "
"WHERE screeningOutputId = %s",
self._output_id,
)
self._data = cursor.fetchone()


def _get_screening_output_lattice(self):
with _db_cc() as cursor:
cursor.run(
"SELECT spaceGroup, unitCell_a, unitCell_b, unitCell_c, "
"unitCell_alpha, unitCell_beta, unitCell_gamma "
"FROM ScreeningOutputLattice "
"WHERE screeningOutputLatticeId = %s",
self._lattice_id,
)
self._data = cursor.fetchone()


def _get_screening_strategy(self):
with _db_cc() as cursor:
cursor.run(
"SELECT anomalous, program, exposureTime, rankingResolution "
"FROM ScreeningStrategy "
"WHERE screeningStrategyId = %s",
self._strategy_id,
)
self._data = cursor.fetchone()


def _get_screening_strategy_wedge(self):
with _db_cc() as cursor:
cursor.run(
"SELECT chi, completeness, kappa, multiplicity, numberOfImages, "
"phi, resolution, wedgeNumber "
"FROM ScreeningStrategyWedge "
"WHERE screeningStrategyWedgeId = %s",
self._wedge_id,
)
self._data = cursor.fetchone()


def _get_screening_strategy_sub_wedge(self):
with _db_cc() as cursor:
cursor.run(
"SELECT axisEnd, axisStart, completeness, exposureTime, "
"multiplicity, numberOfImages, oscillationRange, resolution, "
"rotationAxis, subWedgeNumber, transmission "
"FROM ScreeningStrategySubWedge "
"WHERE screeningStrategySubWedgeId = %s",
self._sub_wedge_id,
)
self._data = cursor.fetchone()


def test_connection():
"""A test function to verify that the database connection is alive."""
with _db_cc() as cursor:
Expand Down
9 changes: 8 additions & 1 deletion ispyb/model/datacollection.py
Expand Up @@ -49,6 +49,11 @@ def integrations(self):
"""Returns the list of IntegrationResult objects associated with this DC."""
raise NotImplementedError("TODO: Not implemented yet")

@property
def screenings(self):
"""Returns the list of Screening objects associated with this DC."""
raise NotImplementedError("TODO: Not implemented yet")

@property
def file_template_full(self):
"""Template for file names with full directory path. As with file_template
Expand Down Expand Up @@ -193,7 +198,9 @@ def __init__(self, dcgid, db_conn, preload=None):

def reload(self):
"""Load/update information from the database."""
self._data = self._db.mx_acquisition.retrieve_data_collection_group(self._dcgid)[0]
self._data = self._db.mx_acquisition.retrieve_data_collection_group(
self._dcgid
)[0]

@property
def dcgid(self):
Expand Down
39 changes: 38 additions & 1 deletion ispyb/model/interface.py
Expand Up @@ -3,6 +3,7 @@
import ispyb.model.datacollection
import ispyb.model.processingprogram
import ispyb.model.processingjob
import ispyb.model.screening


class ObjectModelMixIn:
Expand All @@ -24,6 +25,42 @@ def get_processing_job(self, jobid):
return ispyb.model.processingjob.ProcessingJob(jobid, self.mx_processing)

def get_processing_program(self, appid):
"""Return an ProcessingProgram object representing the information
"""Return a ProcessingProgram object representing the information
about a processing program invocation."""
return ispyb.model.processingprogram.ProcessingProgram(appid, self)

def get_screening(self, screening_id):
"""Return a Screening object representing the information
about a Screening result."""
return ispyb.model.screening.Screening(screening_id, self)

def get_screening_output(self, screening_output_id):
"""Return a ScreeningOutput object representing the information
about a ScreeningOutput result."""
return ispyb.model.screening.ScreeningOutput(screening_output_id, self)

def get_screening_output_lattice(self, screening_output_lattice_id):
"""Return a ScreeningOutputLattice object representing the information
about a ScreeningOutputLattice result."""
return ispyb.model.screening.ScreeningOutputLattice(
screening_output_lattice_id, self
)

def get_screening_strategy(self, screening_strategy_id):
"""Return a ScreeningStrategy object representing the information
about a ScreeningStrategy result."""
return ispyb.model.screening.ScreeningStrategy(screening_strategy_id, self)

def get_screening_strategy_wedge(self, screening_strategy_wedge_id):
"""Return a ScreeningStrategyWedge object representing the information
about a ScreeningStrategyWedge result."""
return ispyb.model.screening.ScreeningStrategyWedge(
screening_strategy_wedge_id, self
)

def get_screening_strategy_sub_wedge(self, screening_strategy_sub_wedge_id):
"""Return a ScreeningStrategySubWedge object representing the
information about a ScreeningStrategySubWedge result."""
return ispyb.model.screening.ScreeningStrategySubWedge(
screening_strategy_sub_wedge_id, self
)

0 comments on commit 5250366

Please sign in to comment.