• RE: CSD applicatiions do not pickup default border

    Hi,

    I'm sorry to tell you that you've come to the wrong place - the CSD this forum is about is not the GNOME project but the Cambridge Structural Database, a database of chemical structures for use by chemists. We can't help with questions about GTK3 I'm afraid.

     

    Kind regards,

    Florian

  • RE: How to handle errors in script?

    Hi Simon,

    The technique you're looking for is called "exception handling". The way to do this in Python would be e.g.:

    for mol in EntryReader():
    try:
    mol.assign_bond_types('Unknown')
    except (IndexError, RuntimeError) as exc:
    print('Couldn't process structure %s: %s' % (mol.identifier, exc))
    continue

    For any errors ("exceptions") that occur within the try block, Python will look for an except block that matches the error's type - if there is none they will be "raised", causing the script to exit; otherwise the script will "catch" the exception and continue in the matching except block (in this case also assigning the error information to a variable called exc).

    The example above would catch any IndexError or RuntimeError that may occur in the assign_bond_types function, print a warning (so you know which structure wasn't processed and which error occurred), and then continue with the next item in the for loop rather than exiting the script.

    Instead of just printing an error, you could also add further code to try and process the structure in a different way, or add multiple except blocks after the try block to handle different types of errors differently.

    Here's the official Python tutorial on exceptions and how to work with them: https://docs.python.org/3/tutorial/errors.html

     

  • RE: Python API requiring the X server

    Hi Luca!

     

    The requirement for an X server is built into Qt which the Python API uses (for example) to generate diagrams for structures.

    Until recent releases, the API would only initialize Qt when functionality requiring it was used, but this significantly slowed down the relevant functionality and sometimes caught users with no X server by surprise so we instead moved it to the initial import of the ccdc module.

    You can prevent the API from using Qt by setting the environment variable CCDC_PYTHON_API_NO_QAPPLICATION to a non-empty value (e.g. 1 or True). You can do this on a per-use basis by running CCDC_PYTHON_API_NO_QAPPLICATION=True python or by setting it in your shell configuration, e.g. by adding a line just saying CCDC_PYTHON_API_NO_QAPPLICATION=True to ~/.bash_profile.

    Do note that this will stop things requiring Qt, such as diagram generation, from working. To get full functionality out of the Python API on "headless" machines, we recommend running a virtual X server such as Xvfb or Xdummy and setting the DISPLAY environment variable to point at its X session.

     

    Hope this helps - if you have any other questions or problems, do get back to us!

    --Florian