# # This script can be used for any purpose without limitation subject to the # conditions at http://www.ccdc.cam.ac.uk/Community/Pages/Licences/v2.aspx # # This permission notice and the following statement of attribution must be # included in all copies or substantial portions of this script. # # 2015-06-15: created by A. G. P. Maloney, the Cambridge Crystallographic Data Centre # 2015-06-18: made available by the Cambridge Crystallographic Data Centre# # """ An introductory script to explain features of the MercuryInterface utility """ # Comments are preceded by a hash -> # # This next statement will let us find out where this script is located later on import os # First we need to import the MercuryInterface utility: from mercury_interface import MercuryInterface # Then we create a MercuryInterface instance, storing it in a variable called 'helper': helper = MercuryInterface() # We can then use the MercuryInterface to obtain the current entry shown in the Mercury Visualiser: entry = helper.current_entry # We can use the MercuryInterface to find the locations to use for various output files, for example a .html file: html_file = helper.output_html_file # Using similar notation, we can output .csv files, .tsv files, .c2m files and .gcd files # We can also use the helper to get the CCDC logo! logo = helper.get_ccdc_logo # The following code will print the CCDC logo and write the identifier of the current entry to the .html file. # It will also give the location of this html file, as well as the location of this script so you can find it again! f = open(html_file, "w") f.write('') f.write('Welcome to the CCDC Python API!') f.write('CCDC Logo' % logo) f.write("

You are seeing this because you ran welcome.py from Mercury's CSD Python API Menu. Good job!

") f.write('
') f.write('
') f.write('This is the identifier for the current structure: ') f.write(helper.identifier) f.write('
') # Find info for components in entry for component in entry.molecule.components: f.write('Formula: %s, Mol wt: %s' % (component.formula, component.molecular_weight)) f.write('
') f.write('
') f.write('This is the directory where the output from this script is located: ') f.write('
') f.write(helper.options['working_directory_path']) f.write('
') f.write('
') f.write('This is where you can find the welcome.py script, so you can have a look at it yourself: ') f.write('
') f.write(os.path.dirname(__file__)) f.write('') f.close()