Debian Codegraph @

blog/_posts/2023-02-26-libcootapi.md

raw
1 ---
2 layout: post
3 title: "libcootapi"
4 date: Sun 26 Feb 2023 02:27:51 GMT
5 ---
6
7 It's time to talk about libcootapi.
8
9 For about a year now, I've been working with a team from CCP4 to
10 bring Coot to the web browser - i.e. WebCoot (this project is known
11 as Moorhen and will have its own post soon).
12
13 As you may know, Coot already has an API, and that was used to create
14 the python module "coot" as well as having a scheme/guile interface.
15 Howver, to make that interface useful in the web browser (i.e. compilable
16 to WebAssembly using emscripten) then it needed to be stripped of GTK and OpenGL.
17
18 After some testing, I decided to abandon that idea (it was too ugly -
19 too many #ifdefs) and to create a new API from scratch - one where GTK
20 and OpenGL are not part of the dependencies. A new directory was
21 created ("api") and the resulting library is called libcootapi. It is
22 available in the `gtk3` branch of Coot.
23
24 The libcootapi API has been compiled to WebAssembly and has JavaScript
25 bindings so that it is useful in the web browser and thus is the basis
26 of Moorhen.
27
28 Additionally, this API now has Python bindings (currently generated
29 using SWIG) so that it is useful from command-line python3 or plugging
30 into other programs, such as... oh, I don't know... Blender perhaps.
31
32 libcootapi is the API that I am now recommending to Python scripters
33 that want to use Coot functions. Although it does not contain many of
34 the functions of the `coot` module, I am keen to transfer them into
35 libcootapi if/when they are needed.
36
37 However, with real space refinement, additions, deletions, validation
38 information, superpositions, rotamers, ligand-fitting and mutations
39 already in place, you can get quite a lot done as it stands.
40
41 ```
42 $ python3
43 >>> import coot_headless_api
44 >>> chapi = coot_headless_api.molecules_container_t()
45 ```
46
47 Many useful functions are now available in the `chapi` object:
48
49 ```
50 >>> imol = chapi.read_pdb("test.pdb")
51 >>> imol_map = chapi.read_mtz("test.mtz", "FWT", "PHWT", "W", False, False)
52 >>> chapi.auto_fit_rotamer(imol, "A", 44, "", "", imol_map)
53 >>> chapi.set_imol_refinement_map(imol_map)
54 >>> chapi.refine_residue_range(imol, "A", 43, 45)
55 >>> chapi.write_coordinates(imol, "mini-ref.pdb")
56 ```
57
58 The libcootapi documentation is here:
59
60 [https://www2.mrc-lmb.cam.ac.uk/personal/pemsley/coot/docs/api/html](https://www2.mrc-lmb.cam.ac.uk/personal/pemsley/coot/docs/api/html)
61
62 libcootapi uses mmdb coordinate identifiers (cids) extensively. The mmdb documentation is here:
63
64 [https://www.ebi.ac.uk/pdbe/docs/cldoc/object/cl_obj_selfnc.html](https://www.ebi.ac.uk/pdbe/docs/cldoc/object/cl_obj_selfnc.html)
65
66 Notes:
67
68 1. Compared to the Python 2 version of the API, the arguments to `auto_fit_best_rotamer()` have been changed
69 2. To run real-space refinement one would now use `refine_residues_using_atom_cid()` or `refine_residues()` or perhaps `refine_residue_range()`
70
71