From 80631843d058c2a0dc164828ad9b6c132eb1f8fc Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Wed, 15 Jul 2026 11:35:06 +0100 Subject: [PATCH 01/23] Added start of command retrieval with natural language --- python/coot_commands/agent.py | 235 +++++++++++++++++++++++ python/coot_commands/retrieval.py | 179 ++++++++++++++++++ python/coot_commands/tools.py | 179 ++++++++++++++++++ python/test_coot_tools.py | 303 ++++++++++++++++++++++++++++++ 4 files changed, 896 insertions(+) create mode 100644 python/coot_commands/agent.py create mode 100644 python/coot_commands/retrieval.py create mode 100644 python/coot_commands/tools.py create mode 100644 python/test_coot_tools.py diff --git a/python/coot_commands/agent.py b/python/coot_commands/agent.py new file mode 100644 index 0000000000..6f0b675105 --- /dev/null +++ b/python/coot_commands/agent.py @@ -0,0 +1,235 @@ +# coot_commands/agent.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""Drive Coot from natural language with a small local model. + +This is the loop that ties a language model to the command registry: it +sends the user's request plus the command *tools* (see +:mod:`coot_commands.tools`) to a local, OpenAI-compatible chat endpoint, +runs whatever tool calls the model emits, feeds the results back, and +repeats until the model answers in plain text. + +The default endpoint is Ollama's OpenAI-compatible API +(``http://localhost:11434/v1/chat/completions``); any server speaking that +protocol works. A 7-8B instruct model with solid tool-calling - Qwen2.5-7B +or Qwen3-8B at 4-bit fits comfortably in 16 GB - is the target. Override +the model and URL with the ``COOT_AGENT_MODEL`` and ``COOT_AGENT_URL`` +environment variables, or the keyword arguments. + +Only the Python standard library is used, so there is no new build +dependency. The chat transport is injectable (the *chat* argument), which +keeps the loop itself testable without a running model server - and lets a +future in-process, GTK-thread-aware transport slot in without touching the +loop. + +Usage inside Coot's Python tab:: + + import coot_commands.agent as agent + print(agent.run_agent("go to residue A 45 and colour it by chain")) + +or standalone (drives Ollama; handlers no-op without Coot, so this also +exercises the loop end to end):: + + python3 -m coot_commands.agent "add a water near A 45" + +Note: :func:`run_agent` is synchronous and blocks on the model call. Called +from Coot's GUI thread it will freeze the display until it returns; wiring it +into the Command tab without blocking (a worker thread that marshals each tool +call back onto the main loop) is deliberately left as a follow-up. +""" + +from __future__ import annotations + +import json +import os +import urllib.error +import urllib.request +from typing import Any, Callable, Dict, List, Optional + +from coot_commands.tools import command_tools, execute_tool + +DEFAULT_URL = "http://localhost:11434/v1/chat/completions" +DEFAULT_MODEL = "gemma4" +# How many commands to expose per request when retrieval is on. A small model +# chooses far better from ~12 tools than from all ~90; see coot_commands.retrieval. +DEFAULT_TOP_K = 12 + +# A message-producing transport: given the running message list and the tool +# definitions, return the assistant's reply message (the OpenAI +# ``choices[0].message`` dict, with an optional ``tool_calls`` list). +ChatFn = Callable[[List[Dict[str, Any]], List[Dict[str, Any]]], Dict[str, Any]] + +SYSTEM_PROMPT = ( + "You are the assistant inside Coot, a program for building and refining " + "macromolecular models into experimental density. Carry out the user's " + "request by calling the provided tools; each tool is a Coot command. " + "Molecules are referred to by integer number (models and maps share the " + "numbering). When the user does not name a molecule, omit the argument and " + "the command acts on the active one. Call one tool at a time, use the " + "result of each call to decide the next, and when the task is done reply " + "with a short plain-text summary of what you did. Do not invent tools or " + "arguments that were not provided." +) + + +def _normalise_chat_url(url: str) -> str: + """Accept a full endpoint or just a base, and return the chat endpoint. + + POSTing to the Ollama base URL (``http://localhost:11434``) returns 405 + Method Not Allowed, so we tolerate a base or a ``.../v1`` root and append + the ``/v1/chat/completions`` path, and strip a trailing slash (which + otherwise redirects). + """ + url = url.rstrip("/") + if url.endswith("/chat/completions"): + return url + if url.endswith("/v1"): + return url + "/chat/completions" + return url + "/v1/chat/completions" + + +def _ollama_chat(model: str, url: str, timeout: float, + messages: List[Dict[str, Any]], + tools: List[Dict[str, Any]]) -> Dict[str, Any]: + """Default transport: one round-trip to an OpenAI-compatible endpoint.""" + url = _normalise_chat_url(url) + payload = { + "model": model, + "messages": messages, + "tools": tools, + "tool_choice": "auto", + "stream": False, + # Low temperature: we want deterministic tool selection, not prose. + "temperature": 0.0, + } + data = json.dumps(payload).encode("utf-8") + req = urllib.request.Request( + url, data=data, headers={"Content-Type": "application/json"}) + try: + with urllib.request.urlopen(req, timeout=timeout) as resp: + body = json.loads(resp.read().decode("utf-8")) + except urllib.error.HTTPError as e: + # The server's body carries the real reason (e.g. "model 'x' not + # found"), which urllib otherwise hides behind a bare status code. + detail = e.read().decode("utf-8", "replace").strip() + raise RuntimeError( + f"chat request to {url} with model {model!r} failed " + f"(HTTP {e.code}): {detail}") from None + return body["choices"][0]["message"] + + +def _run_tool_calls(tool_calls: List[Dict[str, Any]], + verbose: bool) -> List[Dict[str, Any]]: + """Execute each tool call, returning the ``role: tool`` reply messages.""" + replies = [] + for call in tool_calls: + function = call.get("function", {}) + name = function.get("name", "") + raw_args = function.get("arguments") or "{}" + try: + args = json.loads(raw_args) if isinstance(raw_args, str) else raw_args + except json.JSONDecodeError: + args = {} + result = execute_tool(name, args) + if verbose: + shown = ", ".join(f"{k}={v!r}" for k, v in args.items()) + print(f" -> {name}({shown}): {result}") + replies.append({ + "role": "tool", + "tool_call_id": call.get("id", ""), + "content": result, + }) + return replies + + +def _retrieved_tools(user_text: str, top_k: int, + verbose: bool) -> List[Dict[str, Any]]: + """Tools for the commands most relevant to *user_text*, top_k of them. + + Falls back to the full command set if retrieval fails (e.g. the embedding + model is not pulled or the server is down) so a request never breaks just + because the optional embeddings are unavailable. + """ + from coot_commands import retrieval + try: + names = retrieval.select_tools(user_text, top_k) + if verbose: + print(f" (retrieved {len(names)} tools: {', '.join(names)})") + return command_tools(names) + except Exception as e: # noqa: BLE001 - retrieval is best-effort + if verbose: + print(f" (retrieval unavailable: {e}; using all tools)") + return command_tools() + + +def run_agent(user_text: str, *, + model: Optional[str] = None, + url: Optional[str] = None, + tools: Optional[List[Dict[str, Any]]] = None, + chat: Optional[ChatFn] = None, + top_k: Optional[int] = DEFAULT_TOP_K, + max_steps: int = 8, + timeout: float = 120.0, + verbose: bool = True) -> str: + """Fulfil *user_text* by letting the model call Coot commands. + + Returns the model's final plain-text reply. *chat* overrides the transport + (used by the tests); by default a fresh Ollama transport is built from + *model*/*url* (falling back to ``COOT_AGENT_MODEL``/``COOT_AGENT_URL`` then + the module defaults). *tools* overrides the exposed command set; when it is + ``None`` and *top_k* is set, embedding retrieval narrows the ~90 commands to + the *top_k* most relevant (pass ``top_k=None`` to expose them all). + *max_steps* caps the tool-calling rounds so a confused model cannot loop + forever. + """ + model = model or os.environ.get("COOT_AGENT_MODEL", DEFAULT_MODEL) + url = url or os.environ.get("COOT_AGENT_URL", DEFAULT_URL) + if tools is None: + tools = _retrieved_tools(user_text, top_k, verbose) if top_k else command_tools() + if chat is None: + def chat(messages, tools): + return _ollama_chat(model, url, timeout, messages, tools) + + messages: List[Dict[str, Any]] = [ + {"role": "system", "content": SYSTEM_PROMPT}, + {"role": "user", "content": user_text}, + ] + + for _step in range(max_steps): + message = chat(messages, tools) + messages.append(message) + tool_calls = message.get("tool_calls") + if not tool_calls: + return (message.get("content") or "").strip() + messages.extend(_run_tool_calls(tool_calls, verbose)) + + return ("Stopped after {} tool-calling rounds without a final answer." + .format(max_steps)) + + +def main(argv: Optional[List[str]] = None) -> int: + import sys + args = sys.argv[1:] if argv is None else argv + if not args: + sys.stderr.write('usage: python3 -m coot_commands.agent ""\n') + return 2 + print(run_agent(" ".join(args))) + return 0 + + +if __name__ == "__main__": + import sys + sys.exit(main()) diff --git a/python/coot_commands/retrieval.py b/python/coot_commands/retrieval.py new file mode 100644 index 0000000000..f7d5b8f067 --- /dev/null +++ b/python/coot_commands/retrieval.py @@ -0,0 +1,179 @@ +# coot_commands/retrieval.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""Pick the commands relevant to a request, so the model sees few tools. + +The bridge (:mod:`coot_commands.tools`) can emit all ~90 commands as tools, +but a small local model chooses far more reliably from a dozen than from +ninety. This module ranks the commands by semantic similarity to the +user's request and returns the top few names, which +:func:`coot_commands.tools.command_tools` then narrows to via its *names* +argument. + +Ranking uses text embeddings from a local, Ollama-style endpoint +(``/api/embed``, default model ``embeddinggemma`` - a ~300 MB pull; +override with ``COOT_EMBED_MODEL``). +Each command is embedded once from a short document built out of its name, +help, examples, category and notes; the query is embedded per request; we +return the commands with the highest cosine similarity. Embeddings are +memoised for the process, so only the first request pays to embed the +command set. + +As with :mod:`coot_commands.agent`, the embedding transport is injectable +(:class:`ToolRetriever` takes an *embed_fn*), so the ranking logic is +testable without a model server, and only the standard library is used. +""" + +from __future__ import annotations + +import json +import math +import os +import urllib.error +import urllib.request +from typing import Callable, Dict, List, Optional, Sequence + +from coot_commands.registry import Command, all_commands + +DEFAULT_EMBED_URL = "http://localhost:11434/api/embed" +DEFAULT_EMBED_MODEL = "embeddinggemma" + +# Embed a batch of texts -> one vector per text. +EmbedFn = Callable[[Sequence[str]], List[List[float]]] + + +def command_document(cmd: Command) -> str: + """The text embedded to represent a command for retrieval. + + Bundles every scrap of natural language the command carries - help, + example phrasings, category and notes - since domain terms a user might + use ("H-bond", "rotamer", "blur") often live in the notes rather than the + one-line help. + """ + parts = [cmd.name.replace("_", " "), cmd.help_text or cmd.description] + if cmd.examples: + parts.append("Examples: " + "; ".join(cmd.examples)) + parts.append("Category: " + cmd.category) + if cmd.notes: + parts.append(cmd.notes) + return ". ".join(p for p in parts if p) + + +def command_documents() -> Dict[str, str]: + """Map command name -> its retrieval document, for every command.""" + docs: Dict[str, str] = {} + for cmd in all_commands(): + docs.setdefault(cmd.name, command_document(cmd)) + return docs + + +def cosine(a: Sequence[float], b: Sequence[float]) -> float: + """Cosine similarity of two vectors; 0.0 if either is degenerate.""" + dot = sum(x * y for x, y in zip(a, b)) + na = math.sqrt(sum(x * x for x in a)) + nb = math.sqrt(sum(y * y for y in b)) + if na == 0.0 or nb == 0.0: + return 0.0 + return dot / (na * nb) + + +def _normalise_embed_url(url: str) -> str: + """Accept a full endpoint or just a base, and return the embed endpoint. + + POSTing to the Ollama base URL returns 405 Method Not Allowed, so we + tolerate a base or a ``.../api`` root and append the ``/api/embed`` path, + and strip a trailing slash (which otherwise redirects). + """ + url = url.rstrip("/") + if url.endswith("/api/embed"): + return url + if url.endswith("/api"): + return url + "/embed" + return url + "/api/embed" + + +def ollama_embed(texts: Sequence[str], *, + model: Optional[str] = None, + url: Optional[str] = None, + timeout: float = 60.0) -> List[List[float]]: + """Embed *texts* via an Ollama ``/api/embed`` endpoint (batched request).""" + model = model or os.environ.get("COOT_EMBED_MODEL", DEFAULT_EMBED_MODEL) + url = _normalise_embed_url(url or os.environ.get("COOT_EMBED_URL", DEFAULT_EMBED_URL)) + payload = {"model": model, "input": list(texts)} + data = json.dumps(payload).encode("utf-8") + req = urllib.request.Request( + url, data=data, headers={"Content-Type": "application/json"}) + try: + with urllib.request.urlopen(req, timeout=timeout) as resp: + body = json.loads(resp.read().decode("utf-8")) + except urllib.error.HTTPError as e: + # Surface the server's reason (e.g. "model 'x' not found") rather than a + # bare status code; this message reaches the agent's fallback log. + detail = e.read().decode("utf-8", "replace").strip() + raise RuntimeError( + f"embed request to {url} with model {model!r} failed " + f"(HTTP {e.code}): {detail}") from None + return body["embeddings"] + + +class ToolRetriever: + """Rank documents against a query using an embedding transport. + + *documents* maps a name to its text; *embed_fn* embeds a batch of texts. + Document embeddings are computed lazily on the first :meth:`select` and + cached for the retriever's lifetime. + """ + + def __init__(self, documents: Dict[str, str], embed_fn: EmbedFn) -> None: + self.documents = documents + self.embed_fn = embed_fn + self._names: Optional[List[str]] = None + self._vectors: Optional[List[List[float]]] = None + + def _ensure_embedded(self) -> None: + if self._names is None: + self._names = list(self.documents) + self._vectors = self.embed_fn([self.documents[n] for n in self._names]) + + def select(self, query: str, k: int) -> List[str]: + """Return the *k* document names most similar to *query*, best first.""" + self._ensure_embedded() + query_vec = self.embed_fn([query])[0] + scored = sorted( + zip(self._names, self._vectors), + key=lambda nv: cosine(query_vec, nv[1]), + reverse=True, + ) + return [name for name, _ in scored[:k]] + + +# Process-wide default retriever over the registry, embedded via Ollama. Built +# lazily so importing this module never touches the network. +_default_retriever: Optional[ToolRetriever] = None + + +def default_retriever() -> ToolRetriever: + """The shared retriever over all registered commands (Ollama embeddings).""" + global _default_retriever + if _default_retriever is None: + _default_retriever = ToolRetriever(command_documents(), ollama_embed) + return _default_retriever + + +def select_tools(query: str, k: int = 12, + retriever: Optional[ToolRetriever] = None) -> List[str]: + """Command names most relevant to *query* (convenience over the default).""" + return (retriever or default_retriever()).select(query, k) diff --git a/python/coot_commands/tools.py b/python/coot_commands/tools.py new file mode 100644 index 0000000000..523c76c296 --- /dev/null +++ b/python/coot_commands/tools.py @@ -0,0 +1,179 @@ +# coot_commands/tools.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""Expose the command registry to a tool-calling language model. + +This is the bridge that lets a small local model (Gemma, Qwen, ...) drive +Coot: it turns each :func:`~coot_commands.registry.command` into an +OpenAI-style *tool* (a JSON schema of name, description and parameters) +and runs a tool call the model emits back through the registered handler. + +Nothing here talks to a model or a network - see :mod:`coot_commands.agent` +for the loop that does. Keeping the bridge separate means it is pure +Python and unit-testable without Coot or a model server: the command +modules ``try: import coot / except ImportError: coot = None``, so the +schemas build and (side-effect-free) handlers run standalone. + +Why not hand the model Coot's ~400 raw API functions? A 7-8B model +degrades badly past a few dozen tools. The curated ``@command`` set - each +with a one-line description and example phrasings - is a far better tool +surface, and :func:`command_tools` accepts a *names* subset so a future +retrieval step can narrow it further per request. + +The handler signature is the source of truth for a command's parameters: +by convention it mirrors the regex's named groups (e.g. +``go_to_residue(chain, resno, model=None)``), so :func:`inspect.signature` +yields both the parameter list and which are required (no default) versus +optional (default ``None``, resolved to the active molecule). +""" + +from __future__ import annotations + +import inspect +from typing import Any, Dict, Iterable, List, Optional + +from coot_commands.registry import Command, all_commands +from coot_commands.types import ArgType, CommandError + +# JSON-schema parameter descriptions per argument kind. The value the model +# supplies is always coerced to a string before the handler sees it (handlers +# expect the same strings the regex would capture), so every parameter is typed +# "string"; the ArgType only enriches the human-readable description. +_ARG_DESCRIPTIONS = { + ArgType.MODEL: "Model (molecule) number, e.g. \"0\".", + ArgType.MAP: "Map (molecule) number, e.g. \"1\".", + ArgType.COLOUR: "A colour name, e.g. \"red\" or \"sky blue\".", +} + +# What to add for an optional argument of a given kind: the fallback the shared +# resolvers apply when the model omits it (see coot_commands.types). +_ARG_OMIT_HINTS = { + ArgType.MODEL: " Omit to act on the active model.", + ArgType.MAP: " Omit to use the map set for refinement.", +} + + +def _handler_params(cmd: Command) -> List[inspect.Parameter]: + """The command's real arguments: named handler params, minus ``**kwargs``. + + Some handlers accept ``**_`` (they take no arguments but must swallow the + named groups ``dispatch`` would pass); those contribute no tool parameters. + """ + sig = inspect.signature(cmd.handler) + return [p for p in sig.parameters.values() + if p.kind in (inspect.Parameter.POSITIONAL_OR_KEYWORD, + inspect.Parameter.KEYWORD_ONLY)] + + +def _param_schema(cmd: Command, param: inspect.Parameter) -> Dict[str, Any]: + """JSON schema for one parameter, described using its :class:`ArgType`.""" + arg_type = cmd.arg_types.get(param.name) + required = param.default is inspect.Parameter.empty + description = _ARG_DESCRIPTIONS.get(arg_type, "") + if not required: + description += _ARG_OMIT_HINTS.get(arg_type, "") + schema: Dict[str, Any] = {"type": "string"} + if description: + schema["description"] = description.strip() + return schema + + +def _description(cmd: Command) -> str: + """The tool description: the command's help plus its example phrasings. + + Example phrasings matter a lot for a small model - they show the natural + language that maps to this command, so the model can pick the right tool + from an ambiguous request. + """ + text = (cmd.help_text or cmd.description or cmd.name).strip() + if cmd.examples: + text += "\n\nExample phrasings: " + "; ".join( + f'"{ex}"' for ex in cmd.examples[:4]) + return text + + +def command_to_tool(cmd: Command) -> Dict[str, Any]: + """Render one :class:`Command` as an OpenAI-style tool definition.""" + properties: Dict[str, Any] = {} + required: List[str] = [] + for param in _handler_params(cmd): + properties[param.name] = _param_schema(cmd, param) + if param.default is inspect.Parameter.empty: + required.append(param.name) + parameters: Dict[str, Any] = {"type": "object", "properties": properties} + if required: + parameters["required"] = required + return { + "type": "function", + "function": { + "name": cmd.name, + "description": _description(cmd), + "parameters": parameters, + }, + } + + +def _commands_by_name() -> Dict[str, Command]: + """Map tool name -> command, keeping the first on a name clash. + + Tool names must be unique; two commands sharing a handler ``__name__`` + (different modules, same function name) would otherwise collide, so we keep + the first-registered and skip the rest. + """ + by_name: Dict[str, Command] = {} + for cmd in all_commands(): + by_name.setdefault(cmd.name, cmd) + return by_name + + +def command_tools(names: Optional[Iterable[str]] = None) -> List[Dict[str, Any]]: + """Return tool definitions for the registered commands. + + Pass *names* to expose only a subset (e.g. the output of a retrieval step + that picked the commands relevant to a request); by default every command + is exposed. + """ + by_name = _commands_by_name() + selected = list(by_name) if names is None else [n for n in names if n in by_name] + return [command_to_tool(by_name[n]) for n in selected] + + +def execute_tool(name: str, arguments: Optional[Dict[str, Any]] = None) -> str: + """Run the command *name* with the model-supplied *arguments*. + + Returns the handler's result string, or a readable error string (never + raises) so the agent loop can feed failures straight back to the model. + + Arguments are coerced to strings and passed by the handler's parameter + name, mirroring exactly what ``registry.dispatch`` passes from a regex + ``groupdict`` - a missing argument arrives as ``None`` and the shared + resolvers fall back to the active molecule (or raise a clear + :class:`CommandError`). + """ + arguments = arguments or {} + cmd = _commands_by_name().get(name) + if cmd is None: + return f"Error: unknown command '{name}'" + kwargs = {} + for param in _handler_params(cmd): + value = arguments.get(param.name) + kwargs[param.name] = None if value is None else str(value) + try: + return cmd.handler(**kwargs) + except CommandError as e: + return f"Error: {e}" + except Exception as e: # noqa: BLE001 - report any handler failure to the model + return f"Error running '{name}': {e}" diff --git a/python/test_coot_tools.py b/python/test_coot_tools.py new file mode 100644 index 0000000000..f6eaa14e96 --- /dev/null +++ b/python/test_coot_tools.py @@ -0,0 +1,303 @@ +# test_coot_tools.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""Standalone tests for the language-model bridge (no Coot, no model server). + +Run from the python/ directory: + + python3 test_coot_tools.py + +Covers coot_commands.tools (registry -> tool schemas, tool call -> handler) +and coot_commands.agent's loop with an injected fake transport, so nothing +here needs Coot or Ollama. Also discoverable by pytest. +""" + +import json + +import coot_commands # noqa: F401 - triggers command discovery/registration +from coot_commands import agent +from coot_commands.registry import all_commands +from coot_commands.tools import command_to_tool, command_tools, execute_tool + + +def _tool_named(name): + for tool in command_tools(): + if tool["function"]["name"] == name: + return tool + return None + + +def test_every_command_becomes_a_valid_tool(): + tools = command_tools() + assert len(tools) == len({c.name for c in all_commands()}) + for tool in tools: + assert tool["type"] == "function" + fn = tool["function"] + assert isinstance(fn["name"], str) and fn["name"] + assert isinstance(fn["description"], str) and fn["description"] + params = fn["parameters"] + assert params["type"] == "object" + assert isinstance(params["properties"], dict) + + +def test_tool_names_are_unique(): + names = [t["function"]["name"] for t in command_tools()] + assert len(names) == len(set(names)) + + +def test_required_and_optional_params_from_signature(): + # go_to_residue(chain, resno, model=None): chain/resno required, model not. + tool = _tool_named("go_to_residue") + assert tool is not None + params = tool["function"]["parameters"] + assert set(params["properties"]) == {"chain", "resno", "model"} + assert set(params["required"]) == {"chain", "resno"} + + +def test_arg_type_enriches_description_and_omit_hint(): + tool = _tool_named("go_to_residue") + model_desc = tool["function"]["parameters"]["properties"]["model"]["description"] + assert "Model" in model_desc + assert "active" in model_desc # optional -> omit hint appended + + +def test_examples_included_in_description(): + tool = _tool_named("go_to_residue") + assert "Example phrasings" in tool["function"]["description"] + + +def test_kwargs_only_handler_has_no_params(): + # next_residue(**_) takes no real arguments. + tool = _tool_named("next_residue") + assert tool is not None + assert tool["function"]["parameters"]["properties"] == {} + assert "required" not in tool["function"]["parameters"] + + +def test_execute_tool_dispatches_to_handler(): + # centre_at_xyz runs without Coot (the coot-is-None branch returns a string). + out = execute_tool("centre_at_xyz", {"x": "12.0", "y": "4.5", "z": "-3.2"}) + assert out == "Centred at (12, 4.5, -3.2)" + + +def test_execute_tool_coerces_numeric_arguments_to_strings(): + # A model may emit JSON numbers, not strings; handlers expect strings. + out = execute_tool("centre_at_xyz", {"x": 1, "y": 2, "z": 3}) + assert out == "Centred at (1, 2, 3)" + + +def test_execute_unknown_tool_reports_error(): + out = execute_tool("no_such_command", {}) + assert out.startswith("Error: unknown command") + + +def test_execute_tool_reports_command_error(): + # A bad coordinate raises CommandError inside the handler; execute_tool + # turns it into a readable string rather than propagating. + out = execute_tool("centre_at_xyz", {"x": "not-a-number", "y": "0", "z": "0"}) + assert out.startswith("Error:") + + +def test_command_tools_subset_by_name(): + tools = command_tools(names=["go_to_residue", "no_such_command"]) + names = [t["function"]["name"] for t in tools] + assert names == ["go_to_residue"] # unknown names are dropped + + +def test_command_to_tool_matches_registry_entry(): + cmd = next(c for c in all_commands() if c.name == "centre_at_xyz") + tool = command_to_tool(cmd) + assert tool["function"]["name"] == "centre_at_xyz" + assert set(tool["function"]["parameters"]["properties"]) == {"x", "y", "z"} + + +# --- agent loop (fake transport) -------------------------------------------- + +def _fake_chat_script(*replies): + """Return a chat transport that yields *replies* in order, recording calls.""" + state = {"i": 0, "seen": []} + + def chat(messages, tools): + state["seen"].append((list(messages), tools)) + reply = replies[state["i"]] + state["i"] += 1 + return reply + + chat.state = state + return chat + + +def test_agent_runs_a_tool_call_then_returns_final_text(): + chat = _fake_chat_script( + {"role": "assistant", "content": None, "tool_calls": [ + {"id": "c1", "function": { + "name": "centre_at_xyz", + "arguments": json.dumps({"x": "1", "y": "2", "z": "3"})}}]}, + {"role": "assistant", "content": "Done - centred the view."}, + ) + out = agent.run_agent("centre at 1 2 3", chat=chat, top_k=None, verbose=False) + assert out == "Done - centred the view." + # The tool result must be fed back before the final turn. + final_messages = chat.state["seen"][-1][0] + tool_msgs = [m for m in final_messages if m.get("role") == "tool"] + assert tool_msgs and tool_msgs[0]["content"] == "Centred at (1, 2, 3)" + assert tool_msgs[0]["tool_call_id"] == "c1" + + +def test_agent_handles_reply_with_no_tool_calls(): + chat = _fake_chat_script({"role": "assistant", "content": "Hello!"}) + assert agent.run_agent("hi", chat=chat, top_k=None, verbose=False) == "Hello!" + + +def test_agent_stops_after_max_steps(): + loop_reply = {"role": "assistant", "content": None, "tool_calls": [ + {"id": "c", "function": {"name": "centre_at_xyz", + "arguments": "{\"x\":\"0\",\"y\":\"0\",\"z\":\"0\"}"}}]} + chat = _fake_chat_script(*([loop_reply] * 10)) + out = agent.run_agent("spin", chat=chat, max_steps=3, top_k=None, verbose=False) + assert "Stopped after 3" in out + assert chat.state["i"] == 3 + + +# --- retrieval (fake embeddings) -------------------------------------------- + +def _bag_of_words_embed(vocab): + """A fake embedder: each text -> a count vector over *vocab*. + + Deterministic and network-free, so retrieval ranking can be asserted: + documents sharing more query words score higher under cosine. + """ + def embed(texts): + vectors = [] + for text in texts: + words = text.lower().split() + vectors.append([float(words.count(term)) for term in vocab]) + return vectors + return embed + + +def test_retriever_ranks_by_similarity(): + from coot_commands.retrieval import ToolRetriever + vocab = ["water", "add", "refine", "residue", "centre", "colour"] + documents = { + "add_water": "add a water molecule", + "refine_residue": "refine a residue", + "set_colour": "set the colour", + } + retriever = ToolRetriever(documents, _bag_of_words_embed(vocab)) + assert retriever.select("add a water please", k=1) == ["add_water"] + assert retriever.select("refine this residue", k=1) == ["refine_residue"] + + +def test_retriever_k_limits_results_and_orders_them(): + from coot_commands.retrieval import ToolRetriever + vocab = ["water", "refine", "colour"] + documents = {"add_water": "water", "refine_residue": "refine", + "set_colour": "colour"} + retriever = ToolRetriever(documents, _bag_of_words_embed(vocab)) + top = retriever.select("water refine colour", k=2) + assert len(top) == 2 + + +def test_command_documents_cover_every_command(): + from coot_commands.retrieval import command_documents + docs = command_documents() + assert len(docs) == len({c.name for c in all_commands()}) + assert all(text.strip() for text in docs.values()) + + +def test_agent_uses_retrieved_subset_when_top_k_set(): + from coot_commands import retrieval + captured = {} + + def chat(messages, tools): + captured["tools"] = tools + return {"role": "assistant", "content": "ok"} + + fake = retrieval.ToolRetriever( + {"add_water": "add water", "refine_residue": "refine"}, + _bag_of_words_embed(["water", "refine", "add"])) + orig = retrieval._default_retriever + retrieval._default_retriever = fake + try: + agent.run_agent("add a water", chat=chat, top_k=1, verbose=False) + finally: + retrieval._default_retriever = orig + names = [t["function"]["name"] for t in captured["tools"]] + assert names == ["add_water"] + + +def test_agent_falls_back_to_all_tools_when_retrieval_fails(): + from coot_commands import retrieval + + def boom(texts): + raise RuntimeError("no embedding server") + + captured = {} + + def chat(messages, tools): + captured["tools"] = tools + return {"role": "assistant", "content": "ok"} + + fake = retrieval.ToolRetriever({"add_water": "add water"}, boom) + orig = retrieval._default_retriever + retrieval._default_retriever = fake + try: + agent.run_agent("do something", chat=chat, top_k=5, verbose=False) + finally: + retrieval._default_retriever = orig + # Fallback exposes the full command set rather than raising. + assert len(captured["tools"]) == len({c.name for c in all_commands()}) + + +def test_chat_url_normalisation(): + from coot_commands.agent import _normalise_chat_url as n + full = "http://127.0.0.1:11435/v1/chat/completions" + assert n("http://127.0.0.1:11435") == full # bare base (the 405 case) + assert n("http://127.0.0.1:11435/") == full # trailing slash + assert n("http://127.0.0.1:11435/v1") == full # v1 root + assert n(full) == full # already full: unchanged + assert n(full + "/") == full # full with trailing slash + + +def test_embed_url_normalisation(): + from coot_commands.retrieval import _normalise_embed_url as n + full = "http://127.0.0.1:11435/api/embed" + assert n("http://127.0.0.1:11435") == full + assert n("http://127.0.0.1:11435/") == full + assert n("http://127.0.0.1:11435/api") == full + assert n(full) == full + assert n(full + "/") == full + + +def _run(): + tests = [v for k, v in sorted(globals().items()) + if k.startswith("test_") and callable(v)] + failures = 0 + for test in tests: + try: + test() + print(f"PASS {test.__name__}") + except AssertionError as e: + failures += 1 + print(f"FAIL {test.__name__}: {e}") + print(f"\n{len(tests) - failures}/{len(tests)} passed") + return failures == 0 + + +if __name__ == "__main__": + import sys + sys.exit(0 if _run() else 1) From bb3ba045dc6a16ccc8538ec939a0f1f2126185ca Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Wed, 15 Jul 2026 13:42:58 +0100 Subject: [PATCH 02/23] Added Coot Assistant Alpha --- python/coot_commands/__init__.py | 4 + python/coot_commands/agent.py | 153 ++++++-- python/coot_commands/agent_serve.py | 184 ++++++++++ python/coot_commands/commands/model_edit.py | 4 +- python/coot_commands/commands/refine.py | 6 +- python/coot_commands/context_tools.py | 72 ++++ python/coot_commands/new.py | 245 +++++++++++++ python/coot_commands/socket_client.py | 157 +++++++++ python/coot_commands/speech.py | 154 ++++++++ python/coot_commands/tools.py | 72 +++- python/coot_commands/try.py | 120 +++++++ python/coot_commands/types.py | 19 + python/test_coot_commands.py | 18 + python/test_coot_tools.py | 318 ++++++++++++++++- src/vte.cc | 372 +++++++++++++++++++- 15 files changed, 1855 insertions(+), 43 deletions(-) create mode 100644 python/coot_commands/agent_serve.py create mode 100644 python/coot_commands/context_tools.py create mode 100644 python/coot_commands/new.py create mode 100644 python/coot_commands/socket_client.py create mode 100644 python/coot_commands/speech.py create mode 100644 python/coot_commands/try.py diff --git a/python/coot_commands/__init__.py b/python/coot_commands/__init__.py index 6941e42a29..6edfb24488 100644 --- a/python/coot_commands/__init__.py +++ b/python/coot_commands/__init__.py @@ -42,3 +42,7 @@ def _discover_command_modules() -> None: _discover_command_modules() + +# Register the custom context tools (get_active_residue, ...) that the assistant +# uses to read live state; see coot_commands.context_tools. +from . import context_tools # noqa: E402,F401 diff --git a/python/coot_commands/agent.py b/python/coot_commands/agent.py index 6f0b675105..709ce68a88 100644 --- a/python/coot_commands/agent.py +++ b/python/coot_commands/agent.py @@ -59,7 +59,7 @@ import urllib.request from typing import Any, Callable, Dict, List, Optional -from coot_commands.tools import command_tools, execute_tool +from coot_commands.tools import command_tools, custom_tools, execute_tool DEFAULT_URL = "http://localhost:11434/v1/chat/completions" DEFAULT_MODEL = "gemma4" @@ -74,14 +74,43 @@ SYSTEM_PROMPT = ( "You are the assistant inside Coot, a program for building and refining " - "macromolecular models into experimental density. Carry out the user's " - "request by calling the provided tools; each tool is a Coot command. " - "Molecules are referred to by integer number (models and maps share the " - "numbering). When the user does not name a molecule, omit the argument and " - "the command acts on the active one. Call one tool at a time, use the " - "result of each call to decide the next, and when the task is done reply " - "with a short plain-text summary of what you did. Do not invent tools or " - "arguments that were not provided." + "macromolecular models (proteins, nucleic acids, ligands) into experimental " + "density from X-ray crystallography or cryo-EM. You act by calling the " + "provided tools; each tool is a Coot command. Work in small steps: call one " + "tool at a time, use each result to decide the next, and finish with a short " + "plain-text summary of what you did.\n" + "\n" + "Molecules: every model and map has an integer molecule number, shared " + "across models and maps (e.g. model 0, map 1). When the user does not name a " + "molecule, omit that argument so the command acts on the active molecule. " + "Residues are referenced by chain and residue number, written 'A/45' or " + "'A 45'. When the user says 'here', 'this residue', 'the current residue' or " + "similar, call get_active_residue to find out which residue and model they " + "mean before acting.\n" + "\n" + "Structural-biology terms - map the user's shorthand to the right command. " + "Real-space refinement (RSR, 'refine') locally optimises atoms into the " + "density. A rotamer is a side-chain conformation; fitting or fixing a rotamer " + "picks the best-fitting one. A Ramachandran outlier is a residue with an " + "unusual backbone phi/psi combination. A peptide flip ('pepflip') rotates a " + "peptide bond by ~180 degrees to correct the backbone; a backrub is a small " + "local backbone adjustment. A clash is atoms too close together; C-beta " + "deviations and chiral-volume errors are geometry problems. ADPs (B-factors) " + "describe atomic displacement; occupancy is the fraction of an atom present; " + "an alt conf is an alternate conformation; OXT is the C-terminal oxygen. " + "Waters are ordered solvent; a ligand or monomer is a bound small molecule. " + "The refinement map is the map refinement uses; a 2Fo-Fc map shows density, " + "while a difference (Fo-Fc) map shows model-vs-data disagreement - green " + "(positive) peaks suggest missing atoms, red (negative) peaks suggest atoms " + "that should not be there. Validation flags these problems so you can fix " + "them.\n" + "\n" + "The conversation may span several requests: remember what you did earlier " + "(for example, a residue you just refined) and use it as context. Only call " + "tools that are provided, with the arguments they define - never invent a " + "tool or argument. If a request is ambiguous or very large in scope, do the " + "most sensible part and state what you assumed, or ask one brief clarifying " + "question." ) @@ -131,8 +160,23 @@ def _ollama_chat(model: str, url: str, timeout: float, return body["choices"][0]["message"] +# Executes a tool by name with a dict of arguments, returning a result string. +# The default runs commands in-process; the GUI/agent_serve path injects one +# that runs them over the socket into a live Coot (see coot_commands.socket_client). +ExecuteFn = Callable[[str, Dict[str, Any]], str] + +# Receives structured progress events so a consumer (the GUI transcript, a test) +# can observe the run without parsing printed text. Event shapes: +# {"type": "tools", "names": [...]} +# {"type": "step", "tool": name, "args": {...}, "result": "..."} +# {"type": "final", "text": "..."} +# {"type": "stopped","steps": n} +EventFn = Callable[[Dict[str, Any]], None] + + def _run_tool_calls(tool_calls: List[Dict[str, Any]], - verbose: bool) -> List[Dict[str, Any]]: + execute: ExecuteFn, + emit: EventFn) -> List[Dict[str, Any]]: """Execute each tool call, returning the ``role: tool`` reply messages.""" replies = [] for call in tool_calls: @@ -143,10 +187,8 @@ def _run_tool_calls(tool_calls: List[Dict[str, Any]], args = json.loads(raw_args) if isinstance(raw_args, str) else raw_args except json.JSONDecodeError: args = {} - result = execute_tool(name, args) - if verbose: - shown = ", ".join(f"{k}={v!r}" for k, v in args.items()) - print(f" -> {name}({shown}): {result}") + result = execute(name, args) + emit({"type": "step", "tool": name, "args": args, "result": result}) replies.append({ "role": "tool", "tool_call_id": call.get("id", ""), @@ -156,7 +198,7 @@ def _run_tool_calls(tool_calls: List[Dict[str, Any]], def _retrieved_tools(user_text: str, top_k: int, - verbose: bool) -> List[Dict[str, Any]]: + emit: EventFn) -> List[Dict[str, Any]]: """Tools for the commands most relevant to *user_text*, top_k of them. Falls back to the full command set if retrieval fails (e.g. the embedding @@ -166,20 +208,49 @@ def _retrieved_tools(user_text: str, top_k: int, from coot_commands import retrieval try: names = retrieval.select_tools(user_text, top_k) - if verbose: - print(f" (retrieved {len(names)} tools: {', '.join(names)})") + emit({"type": "tools", "names": names}) return command_tools(names) except Exception as e: # noqa: BLE001 - retrieval is best-effort - if verbose: - print(f" (retrieval unavailable: {e}; using all tools)") + emit({"type": "tools", "names": [], "error": str(e)}) return command_tools() +def _make_emit(on_event: Optional[EventFn], verbose: bool) -> EventFn: + """Build the event sink: fans out to *on_event* and/or a human-readable print.""" + def emit(event: Dict[str, Any]) -> None: + if on_event is not None: + on_event(event) + if verbose: + print(_format_event(event)) + return emit + + +def _format_event(event: Dict[str, Any]) -> str: + """Render an event as the one-line form the CLI/verbose mode prints.""" + kind = event.get("type") + if kind == "tools": + names = event.get("names") or [] + if event.get("error"): + return f" (retrieval unavailable: {event['error']}; using all tools)" + return f" (retrieved {len(names)} tools: {', '.join(names)})" + if kind == "step": + args = ", ".join(f"{k}={v!r}" for k, v in (event.get("args") or {}).items()) + return f" -> {event.get('tool')}({args}): {event.get('result')}" + if kind == "final": + return event.get("text", "") + if kind == "stopped": + return f"Stopped after {event.get('steps')} tool-calling rounds without a final answer." + return json.dumps(event) + + def run_agent(user_text: str, *, model: Optional[str] = None, url: Optional[str] = None, tools: Optional[List[Dict[str, Any]]] = None, chat: Optional[ChatFn] = None, + execute: Optional[ExecuteFn] = None, + on_event: Optional[EventFn] = None, + messages: Optional[List[Dict[str, Any]]] = None, top_k: Optional[int] = DEFAULT_TOP_K, max_steps: int = 8, timeout: float = 120.0, @@ -189,33 +260,50 @@ def run_agent(user_text: str, *, Returns the model's final plain-text reply. *chat* overrides the transport (used by the tests); by default a fresh Ollama transport is built from *model*/*url* (falling back to ``COOT_AGENT_MODEL``/``COOT_AGENT_URL`` then - the module defaults). *tools* overrides the exposed command set; when it is - ``None`` and *top_k* is set, embedding retrieval narrows the ~90 commands to - the *top_k* most relevant (pass ``top_k=None`` to expose them all). - *max_steps* caps the tool-calling rounds so a confused model cannot loop - forever. + the module defaults). *execute* overrides how a tool call is run (default: + in-process :func:`coot_commands.tools.execute_tool`; the GUI injects a + socket-backed executor into a live Coot). *on_event* receives structured + progress events (see :data:`EventFn`), for a GUI transcript or tests. + *messages* is the running conversation: pass the same list across calls to + give the agent memory of earlier requests (it is seeded with the system + prompt if empty and appended to in place); omit it for a one-shot call. + *tools* overrides the exposed command set; when it is ``None`` and *top_k* + is set, embedding retrieval narrows the ~90 commands to the *top_k* most + relevant (pass ``top_k=None`` to expose them all). *max_steps* caps the + tool-calling rounds so a confused model cannot loop forever. """ model = model or os.environ.get("COOT_AGENT_MODEL", DEFAULT_MODEL) url = url or os.environ.get("COOT_AGENT_URL", DEFAULT_URL) + execute = execute or execute_tool + emit = _make_emit(on_event, verbose) if tools is None: - tools = _retrieved_tools(user_text, top_k, verbose) if top_k else command_tools() + commands = _retrieved_tools(user_text, top_k, emit) if top_k else command_tools() + # Custom context tools (e.g. get_active_residue) are always available, + # so "here"/"this residue" can be resolved whatever the request says. + tools = custom_tools() + commands if chat is None: def chat(messages, tools): return _ollama_chat(model, url, timeout, messages, tools) - messages: List[Dict[str, Any]] = [ - {"role": "system", "content": SYSTEM_PROMPT}, - {"role": "user", "content": user_text}, - ] + # Seed a fresh conversation, or continue a caller-supplied one (giving the + # agent memory across requests); either way append this request's turn. + if messages is None: + messages = [{"role": "system", "content": SYSTEM_PROMPT}] + elif not messages: + messages.append({"role": "system", "content": SYSTEM_PROMPT}) + messages.append({"role": "user", "content": user_text}) for _step in range(max_steps): message = chat(messages, tools) messages.append(message) tool_calls = message.get("tool_calls") if not tool_calls: - return (message.get("content") or "").strip() - messages.extend(_run_tool_calls(tool_calls, verbose)) + text = (message.get("content") or "").strip() + emit({"type": "final", "text": text}) + return text + messages.extend(_run_tool_calls(tool_calls, execute, emit)) + emit({"type": "stopped", "steps": max_steps}) return ("Stopped after {} tool-calling rounds without a final answer." .format(max_steps)) @@ -226,7 +314,8 @@ def main(argv: Optional[List[str]] = None) -> int: if not args: sys.stderr.write('usage: python3 -m coot_commands.agent ""\n') return 2 - print(run_agent(" ".join(args))) + # verbose=True already prints the step and final lines as they happen. + run_agent(" ".join(args), verbose=True) return 0 diff --git a/python/coot_commands/agent_serve.py b/python/coot_commands/agent_serve.py new file mode 100644 index 0000000000..2aa8b2e595 --- /dev/null +++ b/python/coot_commands/agent_serve.py @@ -0,0 +1,184 @@ +# coot_commands/agent_serve.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""Run the agent as a subprocess that Coot's Assistant tab drives. + +This is the process Coot spawns for the Assistant tab. It reads one request +per line from ``stdin`` and writes newline-delimited JSON *events* to +``stdout``, so the GUI can stream progress without ever blocking on the slow +model calls (those happen here, in this separate process). Tool calls are +executed back in the live Coot over its socket +(:mod:`coot_commands.socket_client`), which runs them on Coot's main thread. + +Protocol +-------- +Requests (one JSON object per line on stdin):: + + {"text": "load the tutorial data and refine A 89"} + +(a bare line of text is also accepted and treated as the ``text``). + +Events (one JSON object per line on stdout):: + + {"type": "ready"} + {"type": "tools", "names": [...]} + {"type": "step", "tool": "...", "args": {...}, "result": "..."} + {"type": "final", "text": "..."} + {"type": "error", "message": "..."} + {"type": "done"} # one per request, always last + +The port to reach Coot comes from ``COOT_RPC_PORT`` (Coot sets it when it +spawns us); the model and endpoints come from the same ``COOT_AGENT_*`` / +``COOT_EMBED_*`` environment as the standalone CLI. +""" + +from __future__ import annotations + +import json +import os +import sys +import urllib.error +import urllib.request +from typing import Any, Dict, Optional, TextIO +from urllib.parse import urlparse + +from coot_commands.agent import run_agent +from coot_commands.socket_client import CootSocketClient, make_socket_executor + + +def _emit(out: TextIO, event: Dict[str, Any]) -> None: + """Write one JSON event as a line and flush (the GUI reads line by line).""" + out.write(json.dumps(event) + "\n") + out.flush() + + +def _parse_request(line: str): + """Classify a stdin *line*: ``("reset", None)``, ``("text", str)`` or None. + + ``{"reset": true}`` starts a new conversation; ``{"text": "..."}`` (or a + bare, unquoted line) is a request; anything else is skipped. + """ + line = line.strip() + if not line: + return None + try: + parsed = json.loads(line) + except json.JSONDecodeError: + return ("text", line) # tolerate a bare, unquoted request line + if isinstance(parsed, dict): + if parsed.get("reset"): + return ("reset", None) + text = parsed.get("text") + if isinstance(text, str) and text.strip(): + return ("text", text) + return None + if isinstance(parsed, str): + return ("text", parsed) if parsed.strip() else None + return None + + +def _probe_ollama(timeout: float = 2.0): + """Check the model server is reachable; return ``(ok, detail)``. + + A GET to the server root is enough - Ollama answers it, and any HTTP + response (even an error status) proves the server is up. + """ + from coot_commands.agent import DEFAULT_URL, _normalise_chat_url + url = _normalise_chat_url(os.environ.get("COOT_AGENT_URL", DEFAULT_URL)) + parts = urlparse(url) + base = f"{parts.scheme}://{parts.netloc}" + try: + with urllib.request.urlopen(base, timeout=timeout) as resp: + resp.read(64) + return True, "" + except urllib.error.HTTPError as e: + return True, f"HTTP {e.code}" # the server responded, so it is reachable + except Exception as e: # noqa: BLE001 - any failure means unreachable + return False, str(e) + + +def _startup_status(client: CootSocketClient) -> Dict[str, Any]: + """Probe the RPC socket and the model server for a GUI readiness indicator.""" + from coot_commands.agent import DEFAULT_MODEL + model = os.environ.get("COOT_AGENT_MODEL", DEFAULT_MODEL) + rpc_ok, rpc_detail = True, "" + try: + client.connect() # also warms the connection reused for tool calls + except Exception as e: # noqa: BLE001 + rpc_ok, rpc_detail = False, str(e) + ollama_ok, ollama_detail = _probe_ollama() + return {"type": "status", "model": model, + "rpc": rpc_ok, "rpc_detail": rpc_detail, + "ollama": ollama_ok, "ollama_detail": ollama_detail} + + +def _context_stats(conversation: list) -> Dict[str, Any]: + """Approximate how much context the running conversation is using. + + We have no tokenizer here, so tokens are estimated at ~4 characters each + over the serialised messages - enough for a GUI "how full is the context" + indicator, labelled as approximate. + """ + return {"messages": len(conversation), + "approx_tokens": max(0, len(json.dumps(conversation)) // 4)} + + +def serve(stdin: TextIO, stdout: TextIO, *, + client: Optional[CootSocketClient] = None, + startup_status: bool = True) -> None: + """Read requests from *stdin*, stream events to *stdout*, until EOF. + + A single *conversation* is threaded across requests for the life of the + process, so the agent remembers earlier turns (a ``{"reset": true}`` line + starts a new one). *client* is injectable for testing; by default a real + socket client to Coot is created (connecting lazily on the first tool call). + On start it emits a ``status`` event (RPC + model reachability) for the GUI + readiness indicator, unless *startup_status* is false. + """ + client = client or CootSocketClient() + execute = make_socket_executor(client) + conversation: list = [] + _emit(stdout, {"type": "ready"}) + if startup_status: + _emit(stdout, _startup_status(client)) + + for line in stdin: + request = _parse_request(line) + if request is None: + continue + kind, text = request + if kind == "reset": + conversation = [] + _emit(stdout, {"type": "reset"}) + continue + try: + run_agent(text, messages=conversation, execute=execute, + on_event=lambda e: _emit(stdout, e), verbose=False) + except Exception as e: # noqa: BLE001 - report any failure to the GUI + _emit(stdout, {"type": "error", "message": str(e)}) + _emit(stdout, {"type": "context", **_context_stats(conversation)}) + _emit(stdout, {"type": "done"}) + + client.close() + + +def main() -> int: + serve(sys.stdin, sys.stdout) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/python/coot_commands/commands/model_edit.py b/python/coot_commands/commands/model_edit.py index 30a920d83d..c87342111b 100644 --- a/python/coot_commands/commands/model_edit.py +++ b/python/coot_commands/commands/model_edit.py @@ -27,7 +27,8 @@ from coot_commands.registry import command from coot_commands.types import (RES_SPEC, OPT_RES_SPEC, resolve_residue, - ArgType, CommandError, ACTIVE_RESIDUE_NOTE) + ArgType, CommandError, centre_on_residue, + ACTIVE_RESIDUE_NOTE) try: import coot @@ -191,5 +192,6 @@ def pepflip_residue(chain: Optional[str] = None, resno: Optional[str] = None, """Flip the peptide following a residue.""" imol, chain_id, res, ins = resolve_residue(chain, resno, model) if coot is not None: + centre_on_residue(imol, chain_id, res, ins) # show it before flipping coot.pepflip(imol, chain_id, res, ins, "") return f"Flipped the peptide at {chain_id}/{res} of model {imol}" diff --git a/python/coot_commands/commands/refine.py b/python/coot_commands/commands/refine.py index 557eb6ba81..b72bfa3595 100644 --- a/python/coot_commands/commands/refine.py +++ b/python/coot_commands/commands/refine.py @@ -22,7 +22,7 @@ from coot_commands.registry import command from coot_commands.types import (RES_SPEC, resolve_model, resolve_residue, - as_int, ArgType, CommandError, + as_int, ArgType, CommandError, centre_on_residue, ACTIVE_MODEL_NOTE, ACTIVE_RESIDUE_NOTE) try: @@ -44,9 +44,11 @@ def _refine_zone(imol: int, chain_id: str, res1: int, res2: int) -> str: """ if coot is None: return f"Refined {chain_id}/{res1}-{res2} of model {imol}" + lo, hi = (res1, res2) if res1 <= res2 else (res2, res1) + # Bring the target on screen first, so the user sees what is being refined. + centre_on_residue(imol, chain_id, lo) if coot.imol_refinement_map() < 0: raise CommandError("no map set for refinement - open a map first") - lo, hi = (res1, res2) if res1 <= res2 else (res2, res1) replacement_state = coot.refinement_immediate_replacement_state() coot.set_refinement_immediate_replacement(1) try: diff --git a/python/coot_commands/context_tools.py b/python/coot_commands/context_tools.py new file mode 100644 index 0000000000..7aa571ac67 --- /dev/null +++ b/python/coot_commands/context_tools.py @@ -0,0 +1,72 @@ +# coot_commands/context_tools.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""Custom context tools for the assistant: live queries, not actions. + +These are :func:`~coot_commands.tools.custom_tool` handlers - always offered to +the model, unlike the retrieval-filtered commands - that let it read Coot's +current state so it can resolve what the user *means* before acting. The +motivating case: the user says "refine here" or "what's this residue?"; the +model calls :func:`get_active_residue` to learn the residue at the centre of +the screen, then acts on it. + +Importing this module registers the tools (it is imported by the package +``__init__``). Add a query here and it becomes available to the assistant with +no other wiring. They run wherever ``execute_tool`` runs - in-process, or +inside a live Coot over the socket - so the values are always current. +""" + +from __future__ import annotations + +from coot_commands.tools import custom_tool + +try: + import coot +except ImportError: + coot = None + + +@custom_tool( + "get_active_residue", + "Return the residue currently at the centre of the screen (the \"active\" " + "residue) as its chain, residue number and model number. Call this when the " + "user refers to \"here\", \"this residue\", \"the current residue\" or " + "similar, to find out which residue and model they mean before acting.") +def get_active_residue() -> str: + """Report the residue at the centre of the screen.""" + if coot is None: + return "the Coot API is not available" + active = coot.active_residue_py() + if not active: + return "No active residue - centre on a model first" + imol, chain, resno = active[0], active[1], active[2] + ins_code = active[3] if len(active) > 3 else "" + spec = f"{chain}/{resno}" + (f" (insertion code '{ins_code}')" if ins_code else "") + return f"Active residue: {spec} of model {imol}" + + +@custom_tool( + "get_active_map", + "Return the map molecule number currently set for refinement (the map that " + "refinement commands use). Call this to find out which map is active.") +def get_active_map() -> str: + """Report the molecule number of the map set for refinement.""" + if coot is None: + return "the Coot API is not available" + imol = coot.imol_refinement_map() + if imol is None or imol < 0: + return "No map is set for refinement - open a map first" + return f"Refinement map: molecule {imol}" diff --git a/python/coot_commands/new.py b/python/coot_commands/new.py new file mode 100644 index 0000000000..48211594d2 --- /dev/null +++ b/python/coot_commands/new.py @@ -0,0 +1,245 @@ +# coot_commands/new.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""Scaffold a new command from a pattern and examples. + +Writing the boilerplate by hand is the tedious part: the licence header, the +``import`` lines, and a handler signature whose parameters exactly match the +pattern's named groups (with the optional ones defaulting to ``None``). This +helper does that for you. + +It derives the signature *from the examples*: it matches each example against +the pattern, and a named group that is ``None`` in any example is treated as +optional (``= None``), the rest as required. So give at least one example that +omits each optional argument and the signature comes out right. + +Run it interactively:: + + python3 -m coot_commands.new + +It prints a ready-to-paste ``@command`` block. If you name a command *file* +that does not exist yet, it offers to create it (header + imports + the stub) +and reminds you to add it to ``python/Makefile.am``. It never edits an +existing file - appending blindly would put a specific pattern *after* the +general ones and get it shadowed (see ordering in ``doc/writing-commands.md``), +so for an existing file it prints the block for you to place by hand. +""" + +from __future__ import annotations + +import os +import re +import sys +from typing import List + +from coot_commands.registry import normalise + +_GROUP_RE = re.compile(r"\(\?P<([A-Za-z_]\w*)>") + +_HEADER = '''\ +# coot_commands/commands/{module}.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""{summary}""" + +from __future__ import annotations + +from typing import Optional + +from coot_commands.registry import command +from coot_commands.types import resolve_model, resolve_map, as_int, as_float, CommandError + +try: + import coot +except ImportError: + coot = None + + +CATEGORY = "{category}" +''' + + +def group_names(pattern: str) -> List[str]: + """The named groups in *pattern*, in order of appearance.""" + seen: List[str] = [] + for name in _GROUP_RE.findall(pattern): + if name not in seen: + seen.append(name) + return seen + + +def signature(pattern: str, examples: List[str]) -> str: + """Build the handler parameter list for *pattern* from its *examples*. + + A named group is optional (``name=None``) if it fails to participate in + at least one example match; otherwise it is required. Groups that never + appear in any successful match are assumed optional, to be safe. + """ + names = group_names(pattern) + if not names: + return "" + regex = re.compile(pattern, re.IGNORECASE) + optional = {name: False for name in names} + matched_any = False + for example in examples: + m = regex.match(normalise(example)) + if not m: + continue + matched_any = True + groups = m.groupdict() + for name in names: + if groups.get(name) is None: + optional[name] = True + if not matched_any: + optional = {name: True for name in names} + required = [n for n in names if not optional[n]] + opt = [n for n in names if optional[n]] + parts = [f"{n}: str" for n in required] + parts += [f"{n}: Optional[str] = None" for n in opt] + return ", ".join(parts) + + +def stub(name: str, pattern: str, examples: List[str], + help_text: str, notes: str) -> str: + """Render the ``@command`` decorator + handler stub as source text.""" + ex_lines = ", ".join(repr(e) for e in examples) or repr(pattern) + deco = [f'@command(r"{pattern}",', + f' examples=[{ex_lines}],', + f' category=CATEGORY,'] + if notes: + deco.append(f' notes={notes!r},') + # Drop trailing comma on the last kwarg, close the call. + deco[-1] = deco[-1].rstrip(",") + ")" + + sig = signature(pattern, examples) + doc = help_text or "TODO: one-line description." + body = [" \"\"\"" + doc + "\"\"\"", + " # TODO: resolve arguments and call the coot.* API, then return a", + " # short status string. Coerce captured strings via types.py helpers.", + " raise CommandError(\"not implemented yet\")"] + return "\n".join(deco + [f"def {name}({sig}) -> str:"] + body) + "\n" + + +def _prompt(label: str, default: str = "") -> str: + suffix = f" [{default}]" if default else "" + try: + value = input(f"{label}{suffix}: ").strip() + except EOFError: + value = "" + return value or default + + +def _prompt_examples() -> List[str]: + print("Examples (one per line, blank to finish; the first is canonical):") + examples: List[str] = [] + while True: + try: + line = input(" example> ").strip() + except EOFError: + break + if not line: + break + examples.append(line) + return examples + + +def interactive() -> int: + print("Scaffold a new Coot command. Ctrl-C to abort.\n") + name = _prompt("Handler function name (e.g. refine_chain)") + if not name.isidentifier(): + sys.stderr.write(f"error: {name!r} is not a valid function name\n") + return 1 + category = _prompt("Category", "General") + pattern = _prompt("Pattern (regex; named groups become arguments)") + if not pattern: + sys.stderr.write("error: a pattern is required\n") + return 1 + try: + re.compile(pattern) + except re.error as exc: + sys.stderr.write(f"error: pattern is not a valid regex: {exc}\n") + return 1 + examples = _prompt_examples() + help_text = _prompt("One-line help") + notes = _prompt("Notes (optional, longer prose for the docs)") + + # Validate the examples up front - the same check the test suite enforces. + regex = re.compile(pattern, re.IGNORECASE) + bad = [e for e in examples if not regex.match(normalise(e))] + if bad: + sys.stderr.write("\nwarning: these examples do NOT match the pattern " + "(fix the pattern or the example):\n") + for e in bad: + sys.stderr.write(f" {e!r}\n") + + block = stub(name, pattern, examples, help_text, notes) + + module = _prompt("\nTarget command module (file stem under commands/, " + "e.g. refine)") + print() + if not module: + print("# Paste this into a file in coot_commands/commands/:\n") + print(block) + return 0 + + here = os.path.dirname(os.path.abspath(__file__)) + path = os.path.join(here, "commands", f"{module}.py") + if os.path.exists(path): + print(f"# {module}.py already exists - not editing it (ordering matters:") + print("# specific patterns must come before general ones). Paste this in,") + print("# placing it above any more-general pattern:\n") + print(block) + return 0 + + summary = f"Commands for {category.lower()}." + contents = _HEADER.format(module=module, summary=summary, + category=category) + "\n\n" + block + with open(path, "w") as fh: + fh.write(contents) + print(f"wrote {path}") + print("\nNext:") + print(f" 1. add 'coot_commands/commands/{module}.py' to " + "python/Makefile.am (nobase_dist_pkgpython_PYTHON)") + print(" 2. implement the handler body (it raises NotImplemented for now)") + print(f" 3. dry-run it: python3 -m coot_commands.try " + f"{examples[0]!r}" if examples else + " 3. dry-run it with: python3 -m coot_commands.try ''") + return 0 + + +def main() -> int: + try: + return interactive() + except KeyboardInterrupt: + sys.stderr.write("\naborted\n") + return 130 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/python/coot_commands/socket_client.py b/python/coot_commands/socket_client.py new file mode 100644 index 0000000000..accec3235b --- /dev/null +++ b/python/coot_commands/socket_client.py @@ -0,0 +1,157 @@ +# coot_commands/socket_client.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""Talk to a running Coot from another process, over its JSON-RPC socket. + +The agent runs as a separate process (so its slow model calls never block +Coot's GUI), but its tool calls must reach the live Coot. Coot already +serves a length-prefixed JSON-RPC socket on localhost (see ``src/json-rpc.cc``, +started via ``make_socket_listener_maybe``); this client speaks that wire +format and runs a ``python.exec`` there. Because the server processes the +request on Coot's GTK idle function, the executed code runs on the main +thread - exactly where the Coot API is safe to call. + +The frame format is a 4-byte big-endian length prefix followed by the JSON +payload, in both directions. :meth:`CootSocketClient.exec_python` sends one +request and reads one response (a single client, used sequentially). + +:func:`make_socket_executor` adapts the client into the ``execute`` callback +that :func:`coot_commands.agent.run_agent` expects: it runs a command by +calling :func:`coot_commands.tools.execute_tool` *inside* Coot, so the same +registry and argument handling apply whether a command runs in-process or +over the socket. +""" + +from __future__ import annotations + +import json +import os +import socket +import struct +import time +from typing import Any, Dict, Optional + +DEFAULT_HOST = "127.0.0.1" +# Coot's default remote-control port (graphics_info_t::remote_control_port_number; +# vte.cc falls back to 9090 when it is unset). +DEFAULT_PORT = 9090 + + +class CootSocketError(RuntimeError): + """A transport-level failure talking to Coot (connection or protocol).""" + + +class CootSocketClient: + """A client for Coot's length-prefixed JSON-RPC socket.""" + + def __init__(self, host: str = DEFAULT_HOST, port: Optional[int] = None, + timeout: float = 30.0) -> None: + self.host = host + self.port = port if port is not None else int( + os.environ.get("COOT_RPC_PORT", DEFAULT_PORT)) + self.timeout = timeout + self._sock: Optional[socket.socket] = None + self._next_id = 1 + + def connect(self, retries: int = 15, delay: float = 0.2) -> None: + """Connect to Coot, retrying briefly so a startup race can't fail us. + + Coot brings the listener up and spawns this process at nearly the same + moment, so the first connect can land a hair too early. We retry for + ~*retries* x *delay* seconds before giving up with the last error. + """ + if self._sock is not None: + return + last_error: Optional[OSError] = None + for attempt in range(max(1, retries)): + try: + self._sock = socket.create_connection( + (self.host, self.port), timeout=self.timeout) + return + except OSError as e: + last_error = e + if attempt < retries - 1: + time.sleep(delay) + raise CootSocketError( + f"cannot connect to Coot at {self.host}:{self.port} after " + f"{retries} attempts: {last_error}") from None + + def close(self) -> None: + if self._sock is not None: + try: + self._sock.close() + finally: + self._sock = None + + def _send_frame(self, payload: bytes) -> None: + assert self._sock is not None + self._sock.sendall(struct.pack(">I", len(payload)) + payload) + + def _recv_exactly(self, n: int) -> bytes: + assert self._sock is not None + chunks = [] + remaining = n + while remaining > 0: + chunk = self._sock.recv(remaining) + if not chunk: + raise CootSocketError("Coot closed the connection") + chunks.append(chunk) + remaining -= len(chunk) + return b"".join(chunks) + + def _recv_frame(self) -> bytes: + (length,) = struct.unpack(">I", self._recv_exactly(4)) + return self._recv_exactly(length) + + def exec_python(self, code: str) -> str: + """Evaluate *code* (a single expression) in Coot; return its value string. + + Raises :class:`CootSocketError` on a transport failure or if the server + reports an error. + """ + self.connect() + request_id = self._next_id + self._next_id += 1 + request = { + "jsonrpc": "2.0", + "id": request_id, + "method": "python.exec", + "params": {"code": code}, + } + self._send_frame(json.dumps(request).encode("utf-8")) + response = json.loads(self._recv_frame().decode("utf-8")) + if "error" in response: + message = response["error"].get("message", "unknown error") + raise CootSocketError(f"Coot error: {message}") + result = response.get("result") or {} + return result.get("value", "") + + +def make_socket_executor(client: CootSocketClient): + """Return an ``execute(name, args)`` that runs a command inside Coot. + + The command runs via :func:`coot_commands.tools.execute_tool` on the Coot + side, as a single ``__import__`` expression so no separate import statement + is needed, mirroring how the Command tab evaluates its Python. + """ + def execute(name: str, args: Dict[str, Any]) -> str: + args_json = json.dumps(args) + code = ( + "__import__('coot_commands.tools', fromlist=['execute_tool'])" + ".execute_tool({name!r}, __import__('json').loads({args!r}))" + ).format(name=name, args=args_json) + return client.exec_python(code) + return execute diff --git a/python/coot_commands/speech.py b/python/coot_commands/speech.py new file mode 100644 index 0000000000..ef32727404 --- /dev/null +++ b/python/coot_commands/speech.py @@ -0,0 +1,154 @@ +# coot_commands/speech.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""Turn dictated speech into the canonical text the command patterns expect. + +macOS Dictation (and other speech-to-text) types its transcription straight +into the focused field, so a spoken command arrives as ordinary text - but +worded the way people speak rather than the way the command regexes are +written. :func:`from_speech` rewrites those spoken forms into the canonical +tokens, and :func:`~coot_commands.registry.dispatch` runs it on every input, +so "superpose model zero onto model one" reaches the same handler as +"superpose model 0 onto model 1". + +It only ever rewrites number words, "point"/"minus" and spoken separators; a +command that is already typed with digits passes through unchanged, so this is +safe to run on all input, not just dictated input. No command keyword is a +number word, and the number words themselves are spelled distinctly from their +homophones ("two" not "to", "four" not "for"), so the rewrite does not clash +with the vocabulary. +""" + +from __future__ import annotations + +import re +from typing import List, Tuple + +_UNITS = { + "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, + "six": 6, "seven": 7, "eight": 8, "nine": 9, +} +_TEENS = { + "ten": 10, "eleven": 11, "twelve": 12, "thirteen": 13, "fourteen": 14, + "fifteen": 15, "sixteen": 16, "seventeen": 17, "eighteen": 18, + "nineteen": 19, +} +_TENS = { + "twenty": 20, "thirty": 30, "forty": 40, "fifty": 50, "sixty": 60, + "seventy": 70, "eighty": 80, "ninety": 90, +} +_NUMBER_WORDS = {**_UNITS, **_TEENS, **_TENS} + + +def _is_number_word(word: str) -> bool: + w = word.lower() + return w in _NUMBER_WORDS or w in ("hundred", "thousand") + + +def _parse_number(tokens: List[str], start: int) -> Tuple[int, int]: + """Parse a run of spoken number words at *start*. + + Returns ``(value, count)`` where *count* is how many tokens were consumed + (0 if *start* is not a number word). Follows ordinary English number + grammar - "forty five" -> 45, "one hundred twenty" -> 120 - but stops + rather than merging two bare units ("four five" -> 4, then 5), so a number + read out digit by digit is not silently turned into its sum. + """ + total = 0 # sum of scale-completed groups (… thousand) + current = 0 # the group being built + unit_open = False # a units/teens value has been placed in this group + count = 0 + saw = False + n = len(tokens) + + while start + count < n: + w = tokens[start + count].lower() + if w in _UNITS: + # A unit fits after a tens word ("forty" "five") or a hundred + # boundary, but never straight after another unit/teen - so a + # number read out digit by digit ("four" "five") is not merged. + if unit_open: + break + current += _NUMBER_WORDS[w] + unit_open = True + elif w in _TEENS: + # A teen (10-19) only starts a group or follows a hundred. + if unit_open or (current % 100) != 0: + break + current += _NUMBER_WORDS[w] + unit_open = True + elif w in _TENS: + if unit_open or (current % 100) != 0: + break + current += _NUMBER_WORDS[w] + elif w == "hundred" and saw: + current = (current or 1) * 100 + unit_open = False + elif w == "thousand" and saw: + total += (current or 1) * 1000 + current = 0 + unit_open = False + elif w == "and" and saw and start + count + 1 < n \ + and _is_number_word(tokens[start + count + 1]): + pass # spoken connector, e.g. "one hundred and five" + else: + break + saw = True + count += 1 + + if not saw: + return (0, 0) + return (total + current, count) + + +_POINT = re.compile(r"(\d) (?:point|dot) (\d)", re.IGNORECASE) +_NEGATIVE = re.compile(r"\b(?:minus|negative|dash) (\d)", re.IGNORECASE) +_SPACED_SLASH = re.compile(r" ?/ ?") + + +def from_speech(text: str) -> str: + """Rewrite dictated *text* into canonical command text. + + Idempotent on already-canonical (digit) input. + """ + if not text: + return text or "" + + collapsed = re.sub(r"\s+", " ", text.strip()) + if not collapsed: + return "" + + tokens = collapsed.split(" ") + out: List[str] = [] + i = 0 + while i < len(tokens): + value, consumed = _parse_number(tokens, i) + if consumed: + out.append(str(value)) + i += consumed + else: + out.append(tokens[i]) + i += 1 + result = " ".join(out) + + # "one point five" -> "1 point 5" -> "1.5" + result = _POINT.sub(r"\1.\2", result) + # "minus 5" / "negative 5" -> "-5" (for negative residue numbers) + result = _NEGATIVE.sub(r"-\1", result) + # spoken or spaced chain/residue separator -> a bare slash ("A / 45" -> "A/45") + result = result.replace(" slash ", "/").replace(" stroke ", "/") + result = _SPACED_SLASH.sub("/", result) + return result diff --git a/python/coot_commands/tools.py b/python/coot_commands/tools.py index 523c76c296..97a57f6e3a 100644 --- a/python/coot_commands/tools.py +++ b/python/coot_commands/tools.py @@ -151,19 +151,83 @@ def command_tools(names: Optional[Iterable[str]] = None) -> List[Dict[str, Any]] return [command_to_tool(by_name[n]) for n in selected] +# Custom (context/query) tools: agent-only tools that are NOT @command regex +# handlers. A command is an ACTION triggered by typed or spoken language; a +# custom tool is typically a QUERY returning live context - e.g. the residue at +# the centre of the screen - so the model can resolve deictic references like +# "here", "this residue" or "the current position" before it acts. Register one +# with @custom_tool (see coot_commands.context_tools). They are always exposed +# to the model (never dropped by retrieval), since such context is relevant +# regardless of how a request is worded. +_CUSTOM_TOOLS: Dict[str, Dict[str, Any]] = {} + + +def custom_tool(name: str, description: str, + parameters: Optional[Dict[str, Any]] = None) -> Callable: + """Register *handler* as an agent tool named *name*. + + *parameters* is a JSON-schema object for the arguments (default: none). The + handler returns a result string (like a command handler); it receives the + model-supplied arguments as keyword arguments. + """ + schema_params = parameters or {"type": "object", "properties": {}} + + def decorator(handler: Callable[..., str]) -> Callable[..., str]: + _CUSTOM_TOOLS[name] = { + "schema": { + "type": "function", + "function": { + "name": name, + "description": description, + "parameters": schema_params, + }, + }, + "handler": handler, + } + return handler + + return decorator + + +def custom_tools() -> List[Dict[str, Any]]: + """Tool definitions for the always-available custom (context) tools.""" + return [entry["schema"] for entry in _CUSTOM_TOOLS.values()] + + +def _custom_kwargs(handler: Callable, arguments: Dict[str, Any]) -> Dict[str, Any]: + """Filter *arguments* to those the custom *handler* actually accepts.""" + sig = inspect.signature(handler) + if any(p.kind == inspect.Parameter.VAR_KEYWORD for p in sig.parameters.values()): + return dict(arguments) + allowed = {name for name, p in sig.parameters.items() + if p.kind in (inspect.Parameter.POSITIONAL_OR_KEYWORD, + inspect.Parameter.KEYWORD_ONLY)} + return {k: v for k, v in arguments.items() if k in allowed} + + def execute_tool(name: str, arguments: Optional[Dict[str, Any]] = None) -> str: - """Run the command *name* with the model-supplied *arguments*. + """Run the tool *name* (custom tool or command) with *arguments*. Returns the handler's result string, or a readable error string (never raises) so the agent loop can feed failures straight back to the model. - Arguments are coerced to strings and passed by the handler's parameter - name, mirroring exactly what ``registry.dispatch`` passes from a regex - ``groupdict`` - a missing argument arrives as ``None`` and the shared + Command arguments are coerced to strings and passed by the handler's + parameter name, mirroring exactly what ``registry.dispatch`` passes from a + regex ``groupdict`` - a missing argument arrives as ``None`` and the shared resolvers fall back to the active molecule (or raise a clear :class:`CommandError`). """ arguments = arguments or {} + + custom = _CUSTOM_TOOLS.get(name) + if custom is not None: + try: + return custom["handler"](**_custom_kwargs(custom["handler"], arguments)) + except CommandError as e: + return f"Error: {e}" + except Exception as e: # noqa: BLE001 - report any failure to the model + return f"Error running '{name}': {e}" + cmd = _commands_by_name().get(name) if cmd is None: return f"Error: unknown command '{name}'" diff --git a/python/coot_commands/try.py b/python/coot_commands/try.py new file mode 100644 index 0000000000..87e416c54e --- /dev/null +++ b/python/coot_commands/try.py @@ -0,0 +1,120 @@ +# coot_commands/try.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""Dry-run a command line against the registry without running Coot. + +Answers the two questions you actually have while writing a pattern: + +* **Which command wins?** ``dispatch`` runs the *first* registered + pattern that matches, so this shows that command, the arguments it would + be called with, and where it lives. +* **Is anything shadowing it?** It also lists every *other* command whose + pattern matches the same input. Those are unreachable for this input + (the first one wins) - a classic cause of "my new command never fires". + +It never calls the handler, so it is safe to run outside Coot:: + + python3 -m coot_commands.try "refine chain A" + +With no argument it reads lines from stdin, so you can pipe or type several +inputs to probe. +""" + +from __future__ import annotations + +import inspect +import sys +from typing import List, Optional, Tuple + +import coot_commands # noqa: F401 - imports all command modules so they register +from coot_commands.registry import Command, all_commands, normalise + + +def _location(cmd: Command) -> str: + """`file.py:line` for a command's handler, for a clickable pointer.""" + try: + path = inspect.getsourcefile(cmd.handler) or "?" + line = cmd.handler.__code__.co_firstlineno + return f"{path.rsplit('/', 1)[-1]}:{line}" + except (TypeError, OSError): + return "?" + + +def _format_call(cmd: Command, groups: dict) -> str: + """Render the handler call that would be made, e.g. ``f(chain='A')``.""" + args = ", ".join(f"{k}={v!r}" for k, v in groups.items()) + return f"{cmd.name}({args})" + + +def matches(text: str) -> List[Tuple[Command, dict]]: + """Every command whose pattern matches *text*, in registration order. + + The first entry is the one ``dispatch`` would run; the rest are + shadowed for this input. Each is paired with the captured groups + (``match.groupdict()``) it would pass to its handler. + """ + norm = normalise(text) + found = [] + for cmd in all_commands(): + m = cmd.regex.match(norm) + if m: + found.append((cmd, m.groupdict())) + return found + + +def explain(text: str) -> str: + """Human-readable dry-run report for a single input line.""" + norm = normalise(text) + found = matches(text) + lines = [f"input (normalised): {norm!r}", ""] + if not found: + lines.append("no command matched - nothing would run.") + return "\n".join(lines) + + winner, groups = found[0] + lines.append(f"MATCH {winner.name} [{winner.category}] {_location(winner)}") + if groups: + for key, value in groups.items(): + lines.append(f" {key} = {value!r}") + else: + lines.append(" (no arguments captured)") + lines.append(f" would call: {_format_call(winner, groups)}") + + if len(found) > 1: + lines.append("") + lines.append("also matched (shadowed - the first match above wins):") + for cmd, _ in found[1:]: + lines.append(f" {cmd.name} [{cmd.category}] {_location(cmd)}") + return "\n".join(lines) + + +def main(argv: Optional[List[str]] = None) -> int: + argv = list(sys.argv[1:] if argv is None else argv) + if argv: + print(explain(" ".join(argv))) + return 0 + # No argument: treat each stdin line as an input to probe. + for raw in sys.stdin: + line = raw.strip() + if not line: + continue + print(explain(line)) + print() + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/python/coot_commands/types.py b/python/coot_commands/types.py index 2f3a8178ea..2d9585d8ee 100644 --- a/python/coot_commands/types.py +++ b/python/coot_commands/types.py @@ -234,6 +234,25 @@ def resolve_residue(chain: Optional[str] = None, resno: Optional[str] = None, return active_residue() +def centre_on_residue(imol: int, chain_id: str, resno: int, + ins_code: str = "") -> bool: + """Centre the view on a residue, best-effort, so edits are visible. + + Residue-targeting *action* commands (refine, pepflip, ...) call this before + acting, so operating on a named residue - whether typed or issued by the + assistant - first brings it on screen ("go to A 45, then refine it"). It + never raises and returns ``True`` if the residue was found, so it can wrap + an edit without changing its error behaviour. + """ + if coot is None: + return False + try: + coot.set_go_to_atom_molecule(imol) + return coot.set_go_to_atom_from_res_spec_py([chain_id, resno, ins_code]) > 0 + except Exception: + return False + + # Named colours -> (r, g, b) floats in 0..1, for map/background colour commands. COLOURS: dict[str, tuple[float, float, float]] = { "black": (0.0, 0.0, 0.0), diff --git a/python/test_coot_commands.py b/python/test_coot_commands.py index 2f44057b17..c510d88765 100644 --- a/python/test_coot_commands.py +++ b/python/test_coot_commands.py @@ -698,6 +698,24 @@ def test_refine_b_factors_runs_shiftfield(): assert calls["bf"] == 1 +def test_refine_residue_centres_on_the_target_first(): + fake = _FakeCootFull() + calls = {} + fake.imol_refinement_map = lambda: 3 + fake.set_go_to_atom_molecule = lambda imol: calls.__setitem__("goto_mol", imol) + fake.set_go_to_atom_from_res_spec_py = lambda spec: calls.setdefault("goto_spec", spec) or 1 + fake.refinement_immediate_replacement_state = lambda: 0 + fake.set_refinement_immediate_replacement = lambda s: None + fake.refine_zone = lambda imol, ch, lo, hi, ins: calls.__setitem__("zone", (imol, ch, lo, hi)) + fake.accept_regularizement = lambda: None + with _use_coot(fake, refine_mod): + out = cli.run_command("refine A 45") + # The view was centred on A/45 before the refinement ran. + assert calls["goto_spec"] == ["A", 45, ""] + assert calls["zone"] == (0, "A", 45, 45) + assert "Refined A/45" in out + + def test_refine_b_factors_needs_a_map(): fake = _FakeCootFull() fake.imol_refinement_map = lambda: -1 # no refinement map set diff --git a/python/test_coot_tools.py b/python/test_coot_tools.py index f6eaa14e96..567242abb7 100644 --- a/python/test_coot_tools.py +++ b/python/test_coot_tools.py @@ -25,7 +25,11 @@ here needs Coot or Ollama. Also discoverable by pytest. """ +import io import json +import socket +import struct +import threading import coot_commands # noqa: F401 - triggers command discovery/registration from coot_commands import agent @@ -237,7 +241,8 @@ def chat(messages, tools): finally: retrieval._default_retriever = orig names = [t["function"]["name"] for t in captured["tools"]] - assert names == ["add_water"] + assert "add_water" in names # the retrieved command + assert "get_active_residue" in names # custom tools are pinned def test_agent_falls_back_to_all_tools_when_retrieval_fails(): @@ -259,8 +264,10 @@ def chat(messages, tools): agent.run_agent("do something", chat=chat, top_k=5, verbose=False) finally: retrieval._default_retriever = orig - # Fallback exposes the full command set rather than raising. - assert len(captured["tools"]) == len({c.name for c in all_commands()}) + # Fallback exposes the full command set (plus the pinned custom tools). + from coot_commands.tools import custom_tools + assert len(captured["tools"]) == ( + len({c.name for c in all_commands()}) + len(custom_tools())) def test_chat_url_normalisation(): @@ -283,6 +290,311 @@ def test_embed_url_normalisation(): assert n(full + "/") == full +# --- pluggable executor + events ------------------------------------------- + +def test_run_agent_uses_injected_executor_and_emits_events(): + calls = [] + + def execute(name, args): + calls.append((name, args)) + return "did " + name + + events = [] + chat = _fake_chat_script( + {"role": "assistant", "content": None, "tool_calls": [ + {"id": "c1", "function": { + "name": "add_water", "arguments": "{}"}}]}, + {"role": "assistant", "content": "Added a water."}, + ) + out = agent.run_agent("add water", chat=chat, execute=execute, + on_event=events.append, top_k=None, verbose=False) + assert out == "Added a water." + assert calls == [("add_water", {})] # our executor ran + kinds = [e["type"] for e in events] + assert "step" in kinds and kinds[-1] == "final" + step = next(e for e in events if e["type"] == "step") + assert step["tool"] == "add_water" and step["result"] == "did add_water" + + +# --- socket client (loopback fake server) ----------------------------------- + +def _recv_exactly(conn, n): + buf = b"" + while len(buf) < n: + chunk = conn.recv(n - len(buf)) + if not chunk: + break + buf += chunk + return buf + + +def _fake_coot_server(responder): + """A one-shot loopback server framing like json-rpc.cc; returns its port.""" + srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + srv.bind(("127.0.0.1", 0)) + srv.listen(1) + port = srv.getsockname()[1] + + def run(): + conn, _ = srv.accept() + (length,) = struct.unpack(">I", _recv_exactly(conn, 4)) + request = json.loads(_recv_exactly(conn, length).decode("utf-8")) + payload = json.dumps(responder(request)).encode("utf-8") + conn.sendall(struct.pack(">I", len(payload)) + payload) + conn.close() + srv.close() + + threading.Thread(target=run, daemon=True).start() + return port + + +def test_socket_client_exec_python_returns_value(): + from coot_commands.socket_client import CootSocketClient + seen = {} + + def responder(req): + seen["req"] = req + return {"jsonrpc": "2.0", "id": str(req["id"]), + "result": {"value": "Centred on A/45"}} + + port = _fake_coot_server(responder) + client = CootSocketClient(port=port) + assert client.exec_python("1 + 1") == "Centred on A/45" + assert seen["req"]["method"] == "python.exec" + assert seen["req"]["params"]["code"] == "1 + 1" + client.close() + + +def test_socket_client_raises_on_server_error(): + from coot_commands.socket_client import CootSocketClient, CootSocketError + port = _fake_coot_server( + lambda req: {"jsonrpc": "2.0", "id": str(req["id"]), + "error": {"code": -32001, "message": "boom"}}) + client = CootSocketClient(port=port) + try: + client.exec_python("bad") + assert False, "expected CootSocketError" + except CootSocketError as e: + assert "boom" in str(e) + client.close() + + +def test_socket_executor_builds_execute_tool_call(): + from coot_commands.socket_client import CootSocketClient, make_socket_executor + seen = {} + + def responder(req): + seen["code"] = req["params"]["code"] + return {"jsonrpc": "2.0", "id": str(req["id"]), + "result": {"value": "Centred on A/45 of model 0"}} + + port = _fake_coot_server(responder) + execute = make_socket_executor(CootSocketClient(port=port)) + result = execute("go_to_residue", {"chain": "A", "resno": "45"}) + assert result == "Centred on A/45 of model 0" + # The generated code invokes execute_tool with the name and JSON args. + assert "execute_tool" in seen["code"] + assert "go_to_residue" in seen["code"] + assert '"chain": "A"' in seen["code"] or "'chain': 'A'" in seen["code"] + + +# --- agent_serve event loop ------------------------------------------------- + +def test_agent_serve_streams_events_per_request(monkeypatch=None): + from coot_commands import agent_serve + + # Stub run_agent so the serve loop is tested without a model: it drives one + # tool call through the injected executor and emits step/final events. + def fake_run_agent(text, *, messages, execute, on_event, verbose): + on_event({"type": "step", "tool": "load_tutorial", "args": {}, + "result": execute("load_tutorial", {})}) + on_event({"type": "final", "text": "done: " + text}) + + orig = agent_serve.run_agent + agent_serve.run_agent = fake_run_agent + + class FakeClient: + def exec_python(self, code): + return "Loaded the tutorial model and data" + + def close(self): + pass + + try: + stdin = io.StringIO('{"text": "load tutorial"}\n') + stdout = io.StringIO() + agent_serve.serve(stdin, stdout, client=FakeClient(), startup_status=False) + finally: + agent_serve.run_agent = orig + + events = [json.loads(line) for line in stdout.getvalue().splitlines()] + kinds = [e["type"] for e in events] + assert kinds[0] == "ready" + assert "step" in kinds + assert any(e["type"] == "final" and e["text"] == "done: load tutorial" + for e in events) + assert any(e["type"] == "context" and "approx_tokens" in e for e in events) + assert kinds[-1] == "done" + + +# --- custom (context) tools ------------------------------------------------- + +def test_custom_tools_are_registered_and_schematised(): + from coot_commands.tools import custom_tools + names = [t["function"]["name"] for t in custom_tools()] + assert "get_active_residue" in names + for tool in custom_tools(): + assert tool["type"] == "function" + assert tool["function"]["description"] + + +def test_execute_tool_dispatches_to_custom_tool(): + from coot_commands import tools + + @tools.custom_tool("unit_probe", "test probe", + parameters={"type": "object", + "properties": {"x": {"type": "string"}}}) + def _probe(x=None): + return f"probe:{x}" + + try: + assert tools.execute_tool("unit_probe", {"x": "7"}) == "probe:7" + # Unknown/extra args are filtered out, not passed through as a TypeError. + assert tools.execute_tool("unit_probe", {"x": "7", "bogus": "9"}) == "probe:7" + finally: + tools._CUSTOM_TOOLS.pop("unit_probe", None) + + +def test_get_active_residue_without_coot(): + # Standalone (no coot) it reports the API is unavailable rather than raising. + from coot_commands.tools import execute_tool + out = execute_tool("get_active_residue", {}) + assert "Coot API is not available" in out + + +def test_agent_pins_custom_tools_even_with_no_commands(): + captured = {} + + def chat(messages, tools): + captured["tools"] = tools + return {"role": "assistant", "content": "ok"} + + from coot_commands.tools import custom_tools + agent.run_agent("do nothing", chat=chat, tools=None, top_k=None, verbose=False) + names = [t["function"]["name"] for t in captured["tools"]] + for custom in custom_tools(): + assert custom["function"]["name"] in names + + +def test_run_agent_threads_conversation_across_calls(): + conversation = [] + chat1 = _fake_chat_script({"role": "assistant", "content": "refined A 42"}) + agent.run_agent("refine the worst residue", chat=chat1, + messages=conversation, top_k=None, verbose=False) + # The running conversation retains system + this turn. + assert [m["role"] for m in conversation] == ["system", "user", "assistant"] + + chat2 = _fake_chat_script({"role": "assistant", "content": "ok"}) + agent.run_agent("focus on the residue you just refined", chat=chat2, + messages=conversation, top_k=None, verbose=False) + # The second call sees the first turn's history (that's the memory). + seen = chat2.state["seen"][0][0] + contents = [m.get("content") for m in seen] + assert "refine the worst residue" in contents + assert "refined A 42" in contents + assert "focus on the residue you just refined" in contents + + +def test_agent_serve_threads_conversation_and_reset(): + from coot_commands import agent_serve + snapshots = [] + + def fake_run_agent(text, *, messages, execute, on_event, verbose): + snapshots.append(list(messages)) # history coming into this turn + messages.append({"role": "user", "content": text}) + messages.append({"role": "assistant", "content": "ok:" + text}) + on_event({"type": "final", "text": "ok:" + text}) + + class FakeClient: + def exec_python(self, code): + return "x" + + def close(self): + pass + + orig = agent_serve.run_agent + agent_serve.run_agent = fake_run_agent + try: + stdin = io.StringIO('{"text": "first"}\n{"text": "second"}\n' + '{"reset": true}\n{"text": "third"}\n') + stdout = io.StringIO() + agent_serve.serve(stdin, stdout, client=FakeClient(), startup_status=False) + finally: + agent_serve.run_agent = orig + + assert snapshots[0] == [] # first: no history + assert any(m.get("content") == "first" for m in snapshots[1]) # second sees first + assert snapshots[2] == [] # after reset: cleared + events = [json.loads(line) for line in stdout.getvalue().splitlines()] + assert any(e["type"] == "reset" for e in events) + + +def test_agent_serve_emits_startup_status(): + from coot_commands import agent_serve + + class FakeClient: + def connect(self): + pass # RPC reachable + + def exec_python(self, code): + return "x" + + def close(self): + pass + + orig_probe = agent_serve._probe_ollama + agent_serve._probe_ollama = lambda timeout=2.0: (True, "") + try: + stdout = io.StringIO() + agent_serve.serve(io.StringIO(""), stdout, client=FakeClient(), + startup_status=True) + finally: + agent_serve._probe_ollama = orig_probe + + events = [json.loads(line) for line in stdout.getvalue().splitlines()] + status = [e for e in events if e["type"] == "status"] + assert status, "expected a status event" + assert status[0]["rpc"] is True + assert status[0]["ollama"] is True + assert "model" in status[0] + + +def test_agent_serve_startup_status_reports_rpc_failure(): + from coot_commands import agent_serve + + class DeadClient: + def connect(self): + raise RuntimeError("connection refused") + + def close(self): + pass + + orig_probe = agent_serve._probe_ollama + agent_serve._probe_ollama = lambda timeout=2.0: (False, "no server") + try: + stdout = io.StringIO() + agent_serve.serve(io.StringIO(""), stdout, client=DeadClient(), + startup_status=True) + finally: + agent_serve._probe_ollama = orig_probe + + status = [json.loads(l) for l in stdout.getvalue().splitlines() + if json.loads(l)["type"] == "status"][0] + assert status["rpc"] is False and "refused" in status["rpc_detail"] + assert status["ollama"] is False + + def _run(): tests = [v for k, v in sorted(globals().items()) if k.startswith("test_") and callable(v)] diff --git a/src/vte.cc b/src/vte.cc index ee0dbc17bb..98ea63634a 100644 --- a/src/vte.cc +++ b/src/vte.cc @@ -662,7 +662,8 @@ create_vte_terminal_with_style() { // When the user switches notebook tab directly (rather than via the Py/AI buttons), // make sure the terminal for that tab has its child process running. Both spawn -// functions are idempotent. +// functions are idempotent. The Assistant tab does NOT auto-start anything: start +// the JSON-RPC listener yourself (Coot's remote-control menu), then use the tab. static void on_vte_notebook_switch_page(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data) { if (page_num == 0) @@ -872,6 +873,370 @@ static GtkWidget *create_command_tab_widget() { return box; } +// --------------------------------------------------------------------------- +// "Assistant" tab - a local-model agent that drives Coot +// --------------------------------------------------------------------------- +// +// Unlike the Command tab (instant, deterministic regex dispatch), the Assistant +// tab hands a natural-language request to a small local language model that +// plans a sequence of Coot commands to fulfil it. Those model calls are slow, +// so the agent runs as a SEPARATE process (python3 -m coot_commands.agent_serve) +// and we drive it over stdin/stdout: +// - a request is written as one JSON line: {"text": "..."} +// - the agent streams back newline-delimited JSON events +// (ready/tools/step/final/error/done) that we render into the transcript. +// The agent executes each planned command back in THIS Coot over the JSON-RPC +// socket (json-rpc.cc), which runs it on this main thread - so the GUI never +// blocks on the model and command execution is never racy. + +static GtkWidget *assistant_output_view = nullptr; +static GtkWidget *assistant_entry_widget = nullptr; +static GtkWidget *assistant_context_label = nullptr; +static GtkWidget *assistant_status_label = nullptr; +static GtkWidget *assistant_spinner = nullptr; +static GSubprocess *assistant_process = nullptr; +static GDataInputStream *assistant_stdout = nullptr; + +// Show/hide the "thinking" spinner while the model works on a request. +static void assistant_set_thinking(bool thinking) { + if (!assistant_spinner) return; + gtk_widget_set_visible(assistant_spinner, thinking); + if (thinking) gtk_spinner_start(GTK_SPINNER(assistant_spinner)); + else gtk_spinner_stop(GTK_SPINNER(assistant_spinner)); +} + +static void assistant_output_append(const std::string &text) { + + if (!assistant_output_view) return; + GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(assistant_output_view)); + GtkTextIter end; + gtk_text_buffer_get_end_iter(buffer, &end); + gtk_text_buffer_insert(buffer, &end, text.c_str(), -1); + + gtk_text_buffer_get_end_iter(buffer, &end); + GtkTextMark *mark = gtk_text_buffer_create_mark(buffer, nullptr, &end, FALSE); + gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(assistant_output_view), mark); + gtk_text_buffer_delete_mark(buffer, mark); +} + +// Render one streamed JSON event line into the transcript. +static void assistant_handle_event(const std::string &line) { + + json ev; + try { + ev = json::parse(line); + } catch (...) { + return; // ignore any non-JSON noise on stdout + } + std::string type = ev.value("type", ""); + + if (type == "step") { + std::string tool = ev.value("tool", ""); + std::string result = ev.value("result", ""); + std::string args_str; + if (ev.contains("args") && ev["args"].is_object()) { + bool first = true; + for (auto it = ev["args"].begin(); it != ev["args"].end(); ++it) { + if (!first) args_str += ", "; + first = false; + const json &v = it.value(); + args_str += it.key() + "=" + (v.is_string() ? v.get() : v.dump()); + } + } + assistant_output_append(" \xE2\x86\x92 " + tool + "(" + args_str + "): " + result + "\n"); + } else if (type == "final") { + assistant_output_append("\n" + ev.value("text", "") + "\n"); + } else if (type == "error") { + assistant_output_append("Error: " + ev.value("message", "") + "\n"); + } else if (type == "context") { + // Update the "how full is the context" indicator. + if (assistant_context_label) { + int n_msgs = ev.value("messages", 0); + int approx_tokens = ev.value("approx_tokens", 0); + char buf[128]; + if (approx_tokens >= 1000) + g_snprintf(buf, sizeof(buf), "Context: %d msgs \xC2\xB7 ~%.1fk tokens", + n_msgs, approx_tokens / 1000.0); + else + g_snprintf(buf, sizeof(buf), "Context: %d msgs \xC2\xB7 ~%d tokens", + n_msgs, approx_tokens); + gtk_label_set_text(GTK_LABEL(assistant_context_label), buf); + } + } else if (type == "reset") { + if (assistant_context_label) + gtk_label_set_text(GTK_LABEL(assistant_context_label), "New conversation"); + } else if (type == "ready") { + if (assistant_status_label) + gtk_label_set_text(GTK_LABEL(assistant_status_label), + "Assistant starting\xE2\x80\xA6"); + } else if (type == "status") { + // Readiness indicator: whether the model server and the RPC are reachable. + bool ollama = ev.value("ollama", false); + bool rpc = ev.value("rpc", false); + if (assistant_status_label) { + std::string model = ev.value("model", "?"); + std::string s = "Model " + model + (ollama ? ": connected" : ": UNREACHABLE") + + " \xC2\xB7 RPC: " + (rpc ? "ready" : "NOT connected"); + gtk_label_set_text(GTK_LABEL(assistant_status_label), s.c_str()); + } + // Surface the underlying reason for a failure so it can be diagnosed. + if (!rpc && ev.contains("rpc_detail")) + assistant_output_append("RPC not connected: " + + ev.value("rpc_detail", "") + "\n"); + if (!ollama && ev.contains("ollama_detail")) + assistant_output_append("Model server unreachable: " + + ev.value("ollama_detail", "") + "\n"); + } else if (type == "done") { + assistant_set_thinking(false); + if (assistant_entry_widget) { + gtk_widget_set_sensitive(assistant_entry_widget, TRUE); + gtk_widget_grab_focus(assistant_entry_widget); + } + } + // "ready" and "tools" events are informational; we don't clutter the + // transcript with them. +} + +static void assistant_read_line_cb(GObject *source, GAsyncResult *res, gpointer user_data); + +static void assistant_queue_read() { + if (assistant_stdout) + g_data_input_stream_read_line_async(assistant_stdout, G_PRIORITY_DEFAULT, + nullptr, assistant_read_line_cb, nullptr); +} + +static void assistant_read_line_cb(GObject *source, GAsyncResult *res, gpointer user_data) { + + GDataInputStream *stream = G_DATA_INPUT_STREAM(source); + gsize length = 0; + GError *error = nullptr; + char *line = g_data_input_stream_read_line_finish(stream, res, &length, &error); + + if (error) { + g_warning("Assistant: stdout read error: %s", error->message); + g_error_free(error); + return; + } + if (!line) { + // EOF: the agent process exited. Reset so the next request respawns it. + if (assistant_process) { + assistant_output_append("\n[assistant process ended]\n"); + g_object_unref(assistant_process); + assistant_process = nullptr; + } + assistant_stdout = nullptr; // freed when this async op drops its ref + assistant_set_thinking(false); + if (assistant_entry_widget) + gtk_widget_set_sensitive(assistant_entry_widget, TRUE); + return; + } + + assistant_handle_event(std::string(line, length)); + g_free(line); + assistant_queue_read(); +} + +// Ask the embedded interpreter where coot_commands lives, so the spawned +// python3 can import it via PYTHONPATH regardless of install layout. +static std::string assistant_pythonpath() { + + std::string code = + "__import__('os').path.dirname(__import__('coot_commands').__path__[0])"; + execute_python_results_container_t rc = execute_python_code_with_result_internal(code); + if (rc.result && PyUnicode_Check(rc.result)) { + const char *s = PyUnicode_AsUTF8(rc.result); + if (s) return std::string(s); + } + return ""; +} + +// The port the agent uses to reach Coot's JSON-RPC socket. We deliberately do +// NOT start the listener from here - start it yourself from Coot's remote-control +// menu, then use the Assistant. (Auto-starting it proved unreliable.) +static int assistant_rpc_port() { + int port = graphics_info_t::remote_control_port_number; + return port == 0 ? 9090 : port; +} + +static void spawn_assistant_process() { + + if (assistant_process) return; + + int port = assistant_rpc_port(); + + GSubprocessLauncher *launcher = g_subprocess_launcher_new( + (GSubprocessFlags)(G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE)); + g_subprocess_launcher_setenv(launcher, "COOT_RPC_PORT", + std::to_string(port).c_str(), TRUE); + std::string ppath = assistant_pythonpath(); + if (!ppath.empty()) { + const char *existing = g_getenv("PYTHONPATH"); + std::string combined = existing ? (ppath + ":" + existing) : ppath; + g_subprocess_launcher_setenv(launcher, "PYTHONPATH", combined.c_str(), TRUE); + } + + GError *error = nullptr; + assistant_process = g_subprocess_launcher_spawn( + launcher, &error, + "python3", "-u", "-m", "coot_commands.agent_serve", nullptr); + g_object_unref(launcher); + + if (!assistant_process) { + assistant_output_append(std::string("Failed to start assistant: ") + + (error ? error->message : "unknown error") + "\n"); + if (error) g_error_free(error); + return; + } + + GInputStream *out_pipe = g_subprocess_get_stdout_pipe(assistant_process); + assistant_stdout = g_data_input_stream_new(out_pipe); + assistant_queue_read(); +} + +// Write one JSON line to the running agent's stdin. Returns false if there is +// no live process to write to (the caller decides whether to spawn one first). +static bool assistant_write_line(const json &obj) { + + if (!assistant_process) return false; + GOutputStream *in_pipe = g_subprocess_get_stdin_pipe(assistant_process); + if (!in_pipe) return false; + + std::string line = obj.dump() + "\n"; + GError *error = nullptr; + g_output_stream_write_all(in_pipe, line.c_str(), line.size(), + nullptr, nullptr, &error); + if (error) { + assistant_output_append(std::string("Write error: ") + error->message + "\n"); + g_error_free(error); + return false; + } + g_output_stream_flush(in_pipe, nullptr, nullptr); + return true; +} + +static void assistant_send_request(const std::string &text) { + + spawn_assistant_process(); + json req; + req["text"] = text; + assistant_write_line(req); +} + +static void on_assistant_entry_activate(GtkEntry *entry, gpointer user_data) { + + const char *text = gtk_editable_get_text(GTK_EDITABLE(entry)); + if (!text) return; + std::string input(text); + if (input.find_first_not_of(" \t") == std::string::npos) return; // blank line + + assistant_output_append("> " + input + "\n"); + // Disable input until the agent signals "done", so requests don't overlap, + // and show the thinking spinner while the model works. + gtk_widget_set_sensitive(GTK_WIDGET(entry), FALSE); + assistant_send_request(input); + assistant_set_thinking(true); + gtk_editable_set_text(GTK_EDITABLE(entry), ""); +} + +static void on_assistant_new_chat_clicked(GtkButton *button, gpointer user_data) { + + // Clear the transcript locally for immediate feedback... + if (assistant_output_view) { + GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(assistant_output_view)); + gtk_text_buffer_set_text(buffer, "", -1); + } + if (assistant_context_label) + gtk_label_set_text(GTK_LABEL(assistant_context_label), "New conversation"); + // ...and tell a running agent to drop its conversation memory. If none is + // running, the next request spawns a fresh one (which starts empty anyway). + json reset; + reset["reset"] = true; + assistant_write_line(reset); + if (assistant_entry_widget) + gtk_widget_grab_focus(assistant_entry_widget); +} + +static void on_assistant_stop_clicked(GtkButton *button, gpointer user_data) { + + if (assistant_process) { + g_subprocess_force_exit(assistant_process); + g_object_unref(assistant_process); + assistant_process = nullptr; + assistant_stdout = nullptr; + assistant_output_append("\n[stopped]\n"); + } + assistant_set_thinking(false); + if (assistant_entry_widget) + gtk_widget_set_sensitive(assistant_entry_widget, TRUE); +} + +static GtkWidget *create_assistant_tab_widget() { + + GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); + + GtkWidget *scrolled = gtk_scrolled_window_new(); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_widget_set_vexpand(scrolled, TRUE); + + assistant_output_view = gtk_text_view_new(); + gtk_text_view_set_editable(GTK_TEXT_VIEW(assistant_output_view), FALSE); + gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(assistant_output_view), FALSE); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(assistant_output_view), GTK_WRAP_WORD_CHAR); + gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrolled), assistant_output_view); + + GtkWidget *row = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2); + assistant_entry_widget = gtk_entry_new(); + gtk_widget_set_hexpand(assistant_entry_widget, TRUE); + gtk_entry_set_placeholder_text(GTK_ENTRY(assistant_entry_widget), + "Ask the assistant, e.g. \"load the tutorial data and refine A 89\""); + g_signal_connect(assistant_entry_widget, "activate", + G_CALLBACK(on_assistant_entry_activate), nullptr); + + GtkWidget *new_chat_button = gtk_button_new_with_label("New chat"); + g_signal_connect(new_chat_button, "clicked", + G_CALLBACK(on_assistant_new_chat_clicked), nullptr); + + GtkWidget *stop_button = gtk_button_new_with_label("Stop"); + g_signal_connect(stop_button, "clicked", + G_CALLBACK(on_assistant_stop_clicked), nullptr); + + // "Thinking" spinner, hidden until a request is in flight. + assistant_spinner = gtk_spinner_new(); + gtk_widget_set_visible(assistant_spinner, FALSE); + + gtk_box_append(GTK_BOX(row), assistant_entry_widget); + gtk_box_append(GTK_BOX(row), assistant_spinner); + gtk_box_append(GTK_BOX(row), new_chat_button); + gtk_box_append(GTK_BOX(row), stop_button); + + // A readiness line (model + RPC status) and a context-usage line, both dim. + assistant_status_label = gtk_label_new(""); + gtk_widget_set_halign(assistant_status_label, GTK_ALIGN_START); + gtk_widget_add_css_class(assistant_status_label, "dim-label"); + + assistant_context_label = gtk_label_new("New conversation"); + gtk_widget_set_halign(assistant_context_label, GTK_ALIGN_START); + gtk_widget_add_css_class(assistant_context_label, "dim-label"); + + gtk_box_append(GTK_BOX(box), scrolled); + gtk_box_append(GTK_BOX(box), assistant_status_label); + gtk_box_append(GTK_BOX(box), row); + gtk_box_append(GTK_BOX(box), assistant_context_label); + + assistant_output_append( + "Coot Assistant [alpha] (local model).\n" + "Start the JSON-RPC listener yourself from Coot's remote-control menu,\n" + "then type a request, e.g. \"refine A 89 and pepflip A 32\".\n"); + gtk_label_set_text(GTK_LABEL(assistant_status_label), + "Start the RPC listener from the menu, then send a request."); + + // Nothing is auto-started here: the agent process is spawned on the first + // request (assistant_send_request), and it connects to the JSON-RPC listener + // that you start yourself. Auto-starting the listener proved unreliable. + return box; +} + void setup_claude_vte_terminal() { // Set up lazily and only once. Doing this at startup reparented the Python VTE @@ -932,6 +1297,11 @@ void setup_claude_vte_terminal() { GtkWidget *cmd_label = gtk_label_new("Command"); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), command_widget, cmd_label); + // Add the local-model Assistant tab (alpha) + GtkWidget *assistant_widget = create_assistant_tab_widget(); + GtkWidget *assistant_label = gtk_label_new("Assistant (alpha)"); + gtk_notebook_append_page(GTK_NOTEBOOK(notebook), assistant_widget, assistant_label); + // Put the notebook into the paned gtk_paned_set_end_child(GTK_PANED(vte_paned_widget), notebook); gtk_paned_set_resize_end_child(GTK_PANED(vte_paned_widget), FALSE); From 7e24858e2f6495cc3f58df754b502742d370913c Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Wed, 15 Jul 2026 13:43:04 +0100 Subject: [PATCH 03/23] Added Coot Assistant Alpha --- python/Makefile.am | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/Makefile.am b/python/Makefile.am index d14eb3a843..865964bab3 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -56,6 +56,12 @@ nobase_dist_pkgpython_PYTHON = \ coot_commands/types.py \ coot_commands/gui.py \ coot_commands/docs.py \ + coot_commands/tools.py \ + coot_commands/context_tools.py \ + coot_commands/agent.py \ + coot_commands/retrieval.py \ + coot_commands/socket_client.py \ + coot_commands/agent_serve.py \ coot_commands/new.py \ coot_commands/try.py \ coot_commands/commands/__init__.py \ From 28ad0480b69a22e7939b23fb638900ec661fa55d Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Tue, 21 Jul 2026 13:54:12 +0100 Subject: [PATCH 04/23] Added shim files --- mmdb-shim/core/backing.hh | 186 +++++++ mmdb-shim/core/bench_edits.cc | 59 +++ mmdb-shim/core/test_core.cc | 77 +++ mmdb-shim/include/mmdb2/_shim_impl.hh | 604 ++++++++++++++++++++++ mmdb-shim/include/mmdb2/mmdb_atom.h | 11 + mmdb-shim/include/mmdb2/mmdb_chain.h | 11 + mmdb-shim/include/mmdb2/mmdb_coormngr.h | 11 + mmdb-shim/include/mmdb2/mmdb_defs.h | 11 + mmdb-shim/include/mmdb2/mmdb_manager.h | 11 + mmdb-shim/include/mmdb2/mmdb_math_align.h | 11 + mmdb-shim/include/mmdb2/mmdb_math_graph.h | 11 + mmdb-shim/include/mmdb2/mmdb_mattype.h | 11 + mmdb-shim/include/mmdb2/mmdb_model.h | 11 + mmdb-shim/include/mmdb2/mmdb_selmngr.h | 11 + mmdb-shim/include/mmdb2/mmdb_tables.h | 11 + mmdb-shim/include/mmdb2/mmdb_uddata.h | 11 + mmdb-shim/include/mmdb2/mmdb_utils.h | 11 + mmdb-shim/src/contacts.cc | 86 +++ mmdb-shim/src/io.cc | 56 ++ 19 files changed, 1211 insertions(+) create mode 100644 mmdb-shim/core/backing.hh create mode 100644 mmdb-shim/core/bench_edits.cc create mode 100644 mmdb-shim/core/test_core.cc create mode 100644 mmdb-shim/include/mmdb2/_shim_impl.hh create mode 100644 mmdb-shim/include/mmdb2/mmdb_atom.h create mode 100644 mmdb-shim/include/mmdb2/mmdb_chain.h create mode 100644 mmdb-shim/include/mmdb2/mmdb_coormngr.h create mode 100644 mmdb-shim/include/mmdb2/mmdb_defs.h create mode 100644 mmdb-shim/include/mmdb2/mmdb_manager.h create mode 100644 mmdb-shim/include/mmdb2/mmdb_math_align.h create mode 100644 mmdb-shim/include/mmdb2/mmdb_math_graph.h create mode 100644 mmdb-shim/include/mmdb2/mmdb_mattype.h create mode 100644 mmdb-shim/include/mmdb2/mmdb_model.h create mode 100644 mmdb-shim/include/mmdb2/mmdb_selmngr.h create mode 100644 mmdb-shim/include/mmdb2/mmdb_tables.h create mode 100644 mmdb-shim/include/mmdb2/mmdb_uddata.h create mode 100644 mmdb-shim/include/mmdb2/mmdb_utils.h create mode 100644 mmdb-shim/src/contacts.cc create mode 100644 mmdb-shim/src/io.cc diff --git a/mmdb-shim/core/backing.hh b/mmdb-shim/core/backing.hh new file mode 100644 index 0000000000..611ccc565b --- /dev/null +++ b/mmdb-shim/core/backing.hh @@ -0,0 +1,186 @@ +// mmdb-shim core — architecture B foundation. +// See ../../MMDB_SHIM_Recon_and_Plan.md. +// +// A LIVE gemmi::Structure holds the data; a PARALLEL wrapper tree provides the +// MMDB pointer semantics Coot depends on: +// * wrapper addresses are stable (pool-allocated) -> valid `mmdb::Atom*` and +// usable as std::set/map keys (identity by address); +// * GetAtom(i)/GetResidue(i) return the SAME canonical wrapper pointer every +// call (identity cache = the parent's child-pointer vector); +// * g() resolves a wrapper to its live gemmi object via parent* + a cached +// sibling index; +// * structural edits patch ONLY the shifted siblings in one container +// (localized) — not the whole pool, unlike the first spike. +// +// This is the hardened successor to mmdb-recon/spike/. + +#pragma once +#include + +#include +#include +#include + +namespace shim { + +struct Backing; +struct ModelW; +struct ChainW; +struct ResidueW; + +// --------------------------------------------------------------------------- +struct AtomW { + ResidueW *parent = nullptr; + int ai = 0; // index within parent residue's atoms (cached) + bool alive = true; + + gemmi::Atom &g() const; // resolve to live gemmi::Atom (defined below) + + // numeric fields -> reference-returning accessors (rewrite targets) + double &x() { return g().pos.x; } + double &y() { return g().pos.y; } + double &z() { return g().pos.z; } + // occ/b_iso are float in gemmi -> value get + setter (can't bind double&) + double occupancy() const { return g().occ; } + void set_occupancy(double v) { g().occ = (float)v; } + double tempFactor() const { return g().b_iso; } + void set_tempFactor(double v) { g().b_iso = (float)v; } + // char-array fields -> const char* getter + setter (strcpy sites rewrite here) + const char *name() const { return g().name.c_str(); } + void set_name(const char *s) { g().name = s; } +}; + +// --------------------------------------------------------------------------- +struct ResidueW { + ChainW *parent = nullptr; + int ri = 0; // index within parent chain's residues + bool alive = true; + std::vector atoms_w; // canonical child wrappers (identity cache) + + gemmi::Residue &g() const; + + int GetNumberOfAtoms() const { return (int)atoms_w.size(); } + AtomW *GetAtom(int i) { return (i >= 0 && i < (int)atoms_w.size()) ? atoms_w[i] : nullptr; } + + AtomW *AddAtom(Backing &b, gemmi::Atom a); // append: O(1), no sibling shift + void DeleteAtom(int pos); // O(atoms in this residue) +}; + +// --------------------------------------------------------------------------- +struct ChainW { + ModelW *parent = nullptr; + int ci = 0; + bool alive = true; + std::vector residues_w; + + gemmi::Chain &g() const; + + int GetNumberOfResidues() const { return (int)residues_w.size(); } + ResidueW *GetResidue(int i) { return (i >= 0 && i < (int)residues_w.size()) ? residues_w[i] : nullptr; } + + ResidueW *AddResidue(Backing &b, gemmi::Residue r); // append: O(1) + ResidueW *InsResidue(Backing &b, int pos, gemmi::Residue r); // O(residues in chain) +}; + +// --------------------------------------------------------------------------- +struct ModelW { + Backing *b = nullptr; + int mi = 0; + std::vector chains_w; + + gemmi::Model &g() const; + + int GetNumberOfChains() const { return (int)chains_w.size(); } + ChainW *GetChain(int i) { return (i >= 0 && i < (int)chains_w.size()) ? chains_w[i] : nullptr; } +}; + +// --------------------------------------------------------------------------- +struct Backing { + gemmi::Structure st; + // Pools: std::deque keeps element addresses stable across growth. + std::deque atom_pool; + std::deque res_pool; + std::deque chain_pool; + std::deque model_pool; + std::vector models_w; + + AtomW *newAtom() { atom_pool.emplace_back(); return &atom_pool.back(); } + ResidueW *newRes() { res_pool.emplace_back(); return &res_pool.back(); } + ChainW *newChain() { chain_pool.emplace_back(); return &chain_pool.back(); } + ModelW *newModel() { model_pool.emplace_back(); return &model_pool.back(); } + + ModelW *GetModel(int i) { return (i >= 0 && i < (int)models_w.size()) ? models_w[i] : nullptr; } + int GetNumberOfModels() const { return (int)models_w.size(); } + + // Build the parallel wrapper tree from the current gemmi::Structure. + void build_from_gemmi() { + models_w.clear(); + for (int mi = 0; mi < (int)st.models.size(); ++mi) { + ModelW *mw = newModel(); mw->b = this; mw->mi = mi; + auto &gm = st.models[mi]; + for (int ci = 0; ci < (int)gm.chains.size(); ++ci) { + ChainW *cw = newChain(); cw->parent = mw; cw->ci = ci; + auto &gc = gm.chains[ci]; + for (int ri = 0; ri < (int)gc.residues.size(); ++ri) { + ResidueW *rw = newRes(); rw->parent = cw; rw->ri = ri; + auto &gr = gc.residues[ri]; + for (int ai = 0; ai < (int)gr.atoms.size(); ++ai) { + AtomW *aw = newAtom(); aw->parent = rw; aw->ai = ai; + rw->atoms_w.push_back(aw); + } + cw->residues_w.push_back(rw); + } + mw->chains_w.push_back(cw); + } + models_w.push_back(mw); + } + } +}; + +// ---- g() resolvers (walk parent + cached index into the live gemmi tree) ---- +inline gemmi::Model &ModelW::g() const { return b->st.models[mi]; } +inline gemmi::Chain &ChainW::g() const { return parent->g().chains[ci]; } +inline gemmi::Residue &ResidueW::g() const { return parent->g().residues[ri]; } +inline gemmi::Atom &AtomW::g() const { return parent->g().atoms[ai]; } + +// ---- edits (localized patching) ---- +inline AtomW *ResidueW::AddAtom(Backing &b, gemmi::Atom a) { + g().atoms.push_back(std::move(a)); // append -> existing ai valid + AtomW *aw = b.newAtom(); + aw->parent = this; aw->ai = (int)atoms_w.size(); + atoms_w.push_back(aw); + return aw; +} + +inline void ResidueW::DeleteAtom(int pos) { + if (pos < 0 || pos >= (int)atoms_w.size()) return; + g().atoms.erase(g().atoms.begin() + pos); + atoms_w[pos]->alive = false; atoms_w[pos]->ai = -1; // tombstone (reclaim later) + atoms_w.erase(atoms_w.begin() + pos); + for (int k = pos; k < (int)atoms_w.size(); ++k) atoms_w[k]->ai = k; // shift -1 +} + +inline ResidueW *ChainW::AddResidue(Backing &b, gemmi::Residue r) { + g().residues.push_back(std::move(r)); + ResidueW *rw = b.newRes(); + rw->parent = this; rw->ri = (int)residues_w.size(); + for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { + AtomW *aw = b.newAtom(); aw->parent = rw; aw->ai = ai; rw->atoms_w.push_back(aw); + } + residues_w.push_back(rw); + return rw; +} + +inline ResidueW *ChainW::InsResidue(Backing &b, int pos, gemmi::Residue r) { + g().residues.insert(g().residues.begin() + pos, std::move(r)); + ResidueW *rw = b.newRes(); + rw->parent = this; rw->ri = pos; + residues_w.insert(residues_w.begin() + pos, rw); + for (int k = pos + 1; k < (int)residues_w.size(); ++k) residues_w[k]->ri = k; // shift +1 + for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { + AtomW *aw = b.newAtom(); aw->parent = rw; aw->ai = ai; rw->atoms_w.push_back(aw); + } + return rw; // atoms of OTHER residues are untouched (parent ri updated, ai unchanged) +} + +} // namespace shim diff --git a/mmdb-shim/core/bench_edits.cc b/mmdb-shim/core/bench_edits.cc new file mode 100644 index 0000000000..d767016c85 --- /dev/null +++ b/mmdb-shim/core/bench_edits.cc @@ -0,0 +1,59 @@ +// Retire spike risk #1 (O(pool) patching -> quadratic edit loops). +// The hardened core patches only shifted siblings in ONE container, so edit cost +// is independent of TOTAL atom count. Prove it: hold atom count constant, vary +// per-container size, and show InsResidue cost scales with residues-in-chain (not +// total atoms), and AddAtom is ~O(1). +#include "backing.hh" +#include +#include + +using namespace shim; +using clk = std::chrono::high_resolution_clock; + +static gemmi::Atom mk(int r, int a) { + gemmi::Atom at; at.pos = gemmi::Position(r * 10.0 + a, r, a); return at; +} + +static double time_ms(const std::function &f) { + auto t0 = clk::now(); f(); + return std::chrono::duration(clk::now() - t0).count(); +} + +int main() { + // Large structure: 1 chain, N residues, 8 atoms each (~N*8 atoms total). + for (int N : {2000, 8000, 32000}) { + Backing B; + B.st.models.emplace_back(); + B.st.models[0].chains.emplace_back(); + auto &gc = B.st.models[0].chains.back(); + for (int r = 0; r < N; ++r) { + gemmi::Residue res; res.seqid = gemmi::SeqId(r + 1, ' '); + for (int a = 0; a < 8; ++a) res.atoms.push_back(mk(r, a)); + gc.residues.push_back(res); + } + B.build_from_gemmi(); + ChainW *chain = B.GetModel(0)->GetChain(0); + AtomW *held = chain->GetResidue(N / 2)->GetAtom(0); + double hx = held->x(); + + // 500 AddAtom (append -> O(1) each) + ResidueW *rmid = chain->GetResidue(N / 2); + double t_add = time_ms([&] { for (int i = 0; i < 500; ++i) rmid->AddAtom(B, mk(1, i)); }); + + // 500 InsResidue at front (worst case: shift all residues in chain) + double t_ins = time_ms([&] { + for (int i = 0; i < 500; ++i) { + gemmi::Residue r; r.seqid = gemmi::SeqId(0, ' '); r.atoms.push_back(mk(9, i)); + chain->InsResidue(B, 0, r); + } + }); + + bool ok = (held->x() == hx); // identity/correctness survived all edits + std::printf("N_res=%-6d total_atoms=%-8d AddAtom(500)=%6.2fms " + "InsResidue@front(500)=%7.2fms correct=%s\n", + N, N * 8, t_add, t_ins, ok ? "yes" : "NO"); + } + std::printf("\nAddAtom flat across N (O(1)); InsResidue@front scales with " + "residues-in-chain, NOT total atoms -> same class as MMDB arrays.\n"); + return 0; +} diff --git a/mmdb-shim/core/test_core.cc b/mmdb-shim/core/test_core.cc new file mode 100644 index 0000000000..b0c75bfabb --- /dev/null +++ b/mmdb-shim/core/test_core.cc @@ -0,0 +1,77 @@ +// Test the hardened core: identity cache + localized-patch edits + stability. +#include "backing.hh" +#include + +using namespace shim; + +static int failures = 0; +#define CHECK(cond, msg) \ + do { \ + if (!(cond)) { std::printf(" FAIL: %s\n", msg); ++failures; } \ + else { std::printf(" ok: %s\n", msg); } \ + } while (0) + +// identity-encoded coords: x = res*10 + atom +static gemmi::Atom mk(int r, int a) { + gemmi::Atom at; + at.name = "A" + std::to_string(r) + "_" + std::to_string(a); + at.pos = gemmi::Position(r * 10.0 + a, (double)r, (double)a); + return at; +} + +int main() { + Backing B; + B.st.models.emplace_back(); + auto &gm = B.st.models.back(); + gm.chains.emplace_back(); + gm.chains.back().name = "A"; + for (int r = 0; r < 3; ++r) { + gemmi::Residue res; res.name = "GLY"; res.seqid = gemmi::SeqId(r + 1, ' '); + for (int a = 0; a < 3; ++a) res.atoms.push_back(mk(r, a)); + gm.chains.back().residues.push_back(res); + } + B.build_from_gemmi(); + + ChainW *chain = B.GetModel(0)->GetChain(0); + ResidueW *res1 = chain->GetResidue(1); + AtomW *held = res1->GetAtom(1); // (res1, atom1) -> x==11 + + std::printf("held=%p x=%.1f name=%s\n", (void *)held, held->x(), held->name()); + + // --- identity cache: repeated Get* return the SAME pointer --- + CHECK(chain->GetResidue(1) == res1, "GetResidue(1) twice -> same pointer (identity)"); + CHECK(res1->GetAtom(1) == held, "GetAtom(1) twice -> same pointer (identity)"); + CHECK(held->x() == 11.0, "resolves to correct atom"); + + // --- edit 1: AddAtom x5000 (gemmi atoms vector reallocates) --- + const void *d0 = (void *)res1->g().atoms.data(); + for (int i = 0; i < 5000; ++i) res1->AddAtom(B, mk(1, 100 + i)); + CHECK(d0 != (void *)res1->g().atoms.data(), "gemmi atoms vector reallocated"); + CHECK(held->x() == 11.0, "held correct after AddAtom (append, no shift)"); + CHECK(res1->GetAtom(1) == held, "identity preserved after AddAtom"); + + // --- edit 2: InsResidue at front: only THIS chain's residue ri shifts --- + // Atom wrappers of other residues must NOT be touched. + gemmi::Residue newr; newr.name = "ACE"; newr.seqid = gemmi::SeqId(0, ' '); + newr.atoms.push_back(mk(7, 7)); + chain->InsResidue(B, 0, newr); + CHECK(res1->ri == 2, "res1 index patched 1 -> 2 (localized to chain)"); + CHECK(held->ai == 1, "held atom index UNCHANGED by residue insert (localized)"); + CHECK(held->x() == 11.0, "held still resolves to same logical atom after mid-insert"); + CHECK(chain->GetResidue(2) == res1, "chain now finds res1 at index 2 (same pointer)"); + CHECK(chain->GetResidue(0)->GetAtom(0)->x() == 77.0, "inserted residue resolves correctly"); + + // --- edit 3: DeleteAtom at index 0 of res1: atom indices shift within residue only --- + res1->DeleteAtom(0); + CHECK(held->ai == 0, "held atom index patched 1 -> 0 after delete"); + CHECK(held->x() == 11.0, "held still correct after DeleteAtom"); + CHECK(res1->GetAtom(0) == held, "identity preserved after DeleteAtom"); + + // --- edit 4: write through reference accessor reaches live gemmi --- + held->x() = 999.0; + CHECK(res1->g().atoms[0].pos.x == 999.0, "ref-accessor write reached live gemmi storage"); + + std::printf("\n=== %s (%d failures) ===\n", + failures == 0 ? "CORE PASSED" : "CORE FAILED", failures); + return failures ? 1 : 0; +} diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh new file mode 100644 index 0000000000..af359ee143 --- /dev/null +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -0,0 +1,604 @@ +// mmdb-shim — architecture B implementation header (single unit; sub-headers +// below are thin macro-guarded wrappers around this). See MMDB_SHIM_Recon_and_Plan.md. +// +// The mmdb:: hierarchy classes ARE the stable wrapper nodes from the hardened +// core (mmdb-recon/spike -> mmdb-shim/core): each holds Manager* + parent* + a +// cached sibling index, resolves to live gemmi via g(), and exposes children as +// a canonical vector (= the identity cache AND the PPAtom/PPResidue table). +// +// Field access is via accessors (pure B): numeric -> reference-returning x()/...; +// float occ/b_iso -> value get + set_*; char[] -> pstr getter + set_*. +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace mmdb { + +// ---- basic MMDB scalar/typedefs (real MMDB: mmdb_mattype.h / mmdb_defs.h) ---- +typedef double realtype; +typedef char *pstr; +typedef const char *cpstr; +typedef unsigned short word; +typedef char AtomName[20]; +typedef char ResName[20]; +typedef char InsCode[10]; +typedef char ChainID[10]; +typedef char Element[10]; +typedef char AltLoc[20]; +typedef char SegID[10]; + +enum ERROR_CODE { + Error_NoError = 0, + Error_CantOpenFile = 12, // matches real MMDB's value + Error_GeneralError1 = 1 +}; + +// ---- UDData (user-defined data) — real MMDB values (mmdb_uddata.h) ---- +enum UDR_TYPE { UDR_ATOM = 0, UDR_RESIDUE = 1, UDR_CHAIN = 2, UDR_MODEL = 3, + UDR_HIERARCHY = 4 }; +enum UDDATA_CODE { UDDATA_Ok = 0, UDDATA_WrongHandle = -1, + UDDATA_WrongUDRType = -2, UDDATA_NoData = -3 }; + +// ---- Selection (real MMDB values: mmdb_selmngr.h) ---- +enum SELECTION_TYPE { STYPE_INVALID = -1, STYPE_UNDEFINED = 0, STYPE_ATOM = 1, + STYPE_RESIDUE = 2, STYPE_CHAIN = 3, STYPE_MODEL = 4 }; +enum SELECTION_KEY { SKEY_NEW = 0, SKEY_OR = 1, SKEY_AND = 2, SKEY_XOR = 3, + SKEY_CLR = 4, SKEY_XAND = 100 }; +inline const long int MinInt4 = -2147483647; +inline const int ANY_RES = -2147483647; // real MMDB: extern const == MinInt4 + +// Per-object UDData slots + selection membership bits. Each registered UDData +// handle maps to a (type,kind,slot); the object stores contiguous vectors +// indexed by slot. `_inSel[selHnd-1]` = is this object in selection selHnd +// (maintained by Manager::Select/SelectSphere/DeleteSelection). +struct UDStore { + std::vector _udi; + std::vector _udr; + std::vector _uds; + std::vector _inSel; + bool isInSelection(int selHnd) const { + return selHnd >= 1 && selHnd <= (int)_inSel.size() && _inSel[selHnd - 1]; + } + void _setInSel(int selHnd, bool v) { + if ((int)_inSel.size() < selHnd) _inSel.resize(selHnd, false); + _inSel[selHnd - 1] = v; + } +}; + +class Atom; class Residue; class Chain; class Model; class Manager; +typedef Atom *PAtom; typedef Atom **PPAtom; +typedef Residue *PResidue; typedef Residue **PPResidue; +typedef Chain *PChain; typedef Chain **PPChain; +typedef Model *PModel; typedef Model **PPModel; + +struct Contact { int id1, id2; long group; realtype dist; }; +typedef Contact *PContact; + +// LINK record. Public data members mirror real MMDB (Coot reads them directly). +// Not gemmi-backed yet — Model::GetNumberOfLinks currently returns 0 (TODO: map +// gemmi Structure connections), so these are declared for compilation. +class Link { +public: + AtomName atName1{}, atName2{}; + AltLoc aloc1{}, aloc2{}; + ResName resName1{}, resName2{}; + ChainID chainID1{}, chainID2{}; + InsCode insCode1{}, insCode2{}; + int seqNum1 = 0, seqNum2 = 0; + realtype dist = 0; +}; +typedef Link *PLink; typedef Link **PPLink; + +[[noreturn]] inline void unimpl(const char *w) { + throw std::logic_error(std::string("mmdb-shim: unimplemented: ") + w); +} + +// UDData helpers (defined after Manager); each class forwards with its UDR type. +int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int v); +int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype v); +int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, cpstr v); +int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int &v); +int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype &v); + +// =========================================================================== +class Atom : public UDStore { +public: + Manager *mgr = nullptr; + Residue *res = nullptr; // parent + int ai = 0; // cached index within parent residue's atoms + bool alive = true; + + gemmi::Atom &g() const; // resolve to live gemmi (defined after Manager) + + // --- rewritten field accessors (pure B) --- + // Scalar fields -> reference-returning accessors, so a uniform `->field`-> + // `->field()` rewrite covers both reads and writes. (occ/b_iso/charge are + // narrower than realtype in gemmi, so those refs are float/schar-typed — the + // rare take-address-of-realtype sites surface at Coot build time.) + realtype &x() { return g().pos.x; } + realtype &y() { return g().pos.y; } + realtype &z() { return g().pos.z; } + float &occupancy() { return g().occ; } + float &tempFactor() { return g().b_iso; } + char &altLoc() { return g().altloc; } + signed char &charge() { return g().charge; } + int &serNum() { return g().serial; } + void set_occupancy(realtype v) { g().occ = (float)v; } + void set_tempFactor(realtype v) { g().b_iso = (float)v; } + void set_altLoc(char c) { g().altloc = c; } + + // --- method surface (hot subset; rest stubbed) --- + pstr GetAtomName(); // aligned name, MMDB semantics + void SetAtomName(const AtomName aName); + pstr GetElementName(); + void SetElementName(const Element elName); + cpstr GetChainID(); + int GetSeqNum(); + pstr GetInsCode(); + pstr GetResName(); + Residue *GetResidue() { return res; } + int GetModelNum(); + bool isTer() const { return false; } // gemmi has no TER atoms; see notes + void SetCoordinates(realtype xx, realtype yy, realtype zz, + realtype occ, realtype tF); + int GetIndex(); + // UDData + int PutUDData(int h, int v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } + int PutUDData(int h, realtype v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } + int PutUDData(int h, cpstr v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } + int GetUDData(int h, int &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } + int GetUDData(int h, realtype &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } + +private: + AtomName _name_buf{}; Element _elem_buf{}; +}; + +// =========================================================================== +class Residue : public UDStore { +public: + Manager *mgr = nullptr; + Chain *chain = nullptr; // parent + int ri = 0; + bool alive = true; + std::vector atoms; // canonical child wrappers == PPAtom table + + gemmi::Residue &g() const; + + int GetNumberOfAtoms() { return (int)atoms.size(); } + int GetNumberOfAtoms(bool /*countTers*/) { return (int)atoms.size(); } + PAtom GetAtom(int atomNo) { + return (atomNo >= 0 && atomNo < (int)atoms.size()) ? atoms[atomNo] : nullptr; + } + PAtom GetAtom(const AtomName aname, const Element elname = nullptr, + const AltLoc aloc = nullptr); + void GetAtomTable(PPAtom &atomTable, int &n) { atomTable = atoms.data(); n = (int)atoms.size(); } + PAtom AddAtom(Manager &m, gemmi::Atom a); // append: O(1) + int AddAtom(PAtom /*atm*/) { unimpl("Residue::AddAtom(PAtom)"); } + void DeleteAtom(int pos); + + pstr GetResName(); + void SetResName(const ResName n) { g().name = n; } + int GetSeqNum(); + pstr GetInsCode(); + cpstr GetChainID(); + int GetModelNum(); + int GetIndex() { return ri; } + Chain *GetChain() { return chain; } + Residue *next = nullptr; // MMDB has this; wired lazily if needed + // UDData + int PutUDData(int h, int v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } + int PutUDData(int h, realtype v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } + int PutUDData(int h, cpstr v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } + int GetUDData(int h, int &v) { return ud_get(mgr, UDR_RESIDUE, *this, h, v); } + int GetUDData(int h, realtype &v) { return ud_get(mgr, UDR_RESIDUE, *this, h, v); } + +private: + ResName _resname_buf{}; InsCode _inscode_buf{}; +}; + +// =========================================================================== +class Chain : public UDStore { +public: + Manager *mgr = nullptr; + Model *model = nullptr; // parent + int ci = 0; + bool alive = true; + std::vector residues; + + gemmi::Chain &g() const; + + int GetNumberOfResidues() { return (int)residues.size(); } + PResidue GetResidue(int resNo) { + return (resNo >= 0 && resNo < (int)residues.size()) ? residues[resNo] : nullptr; + } + void GetResidueTable(PPResidue &t, int &n) { t = residues.data(); n = (int)residues.size(); } + cpstr GetChainID(); + PResidue AddResidue(Manager &m, gemmi::Residue r); // append + PResidue InsResidue(Manager &m, int pos, gemmi::Residue r); + +private: + ChainID _chainid_buf{}; +}; + +// =========================================================================== +class Model : public UDStore { +public: + Manager *mgr = nullptr; + int mi = 0; // 0-based internal; GetModel is 1-based externally + std::vector chains; + + gemmi::Model &g() const; + + int GetNumberOfChains() { return (int)chains.size(); } + PChain GetChain(int chainNo) { + return (chainNo >= 0 && chainNo < (int)chains.size()) ? chains[chainNo] : nullptr; + } + PChain GetChain(const ChainID chID); + int GetSerNum() { return mi + 1; } + // LINK records — TODO: map from gemmi Structure connections. + int GetNumberOfLinks() { return 0; } + PLink GetLink(int /*i*/) { return nullptr; } +}; + +// =========================================================================== +class Manager { +public: + gemmi::Structure st; + // stable-address pools + std::deque atom_pool; + std::deque res_pool; + std::deque chain_pool; + std::deque model_pool; + std::vector models; + + Atom *newAtom() { atom_pool.emplace_back(); return &atom_pool.back(); } + Residue *newRes() { res_pool.emplace_back(); return &res_pool.back(); } + Chain *newChain(){ chain_pool.emplace_back();return &chain_pool.back();} + Model *newModel(){ model_pool.emplace_back();return &model_pool.back();} + + int GetNumberOfModels() { return (int)models.size(); } + PModel GetModel(int modelNo) { // MMDB: 1 <= modelNo <= nModels + int i = modelNo - 1; + return (i >= 0 && i < (int)models.size()) ? models[i] : nullptr; + } + + void build_from_gemmi(); + + // ---- selection ---- + struct Selection { + SELECTION_TYPE type = STYPE_UNDEFINED; + std::vector atoms; + std::vector residues; + }; + std::vector selections; // handle is 1-based index + + int NewSelection() { selections.emplace_back(); return (int)selections.size(); } + void DeleteSelection(int selHnd) { + if (selHnd < 1 || selHnd > (int)selections.size()) return; + Selection &s = selections[selHnd - 1]; + for (Atom *a : s.atoms) a->_setInSel(selHnd, false); + for (Residue *r : s.residues) r->_setInSel(selHnd, false); + s = Selection(); + } + void GetSelIndex(int selHnd, PPAtom &SelAtom, int &n) { + Selection &s = selections[selHnd - 1]; SelAtom = s.atoms.data(); n = (int)s.atoms.size(); + } + void GetSelIndex(int selHnd, PPResidue &SelRes, int &n) { + Selection &s = selections[selHnd - 1]; SelRes = s.residues.data(); n = (int)s.residues.size(); + } + // primary CID-range selection (STYPE via Select; SelectAtoms forwards as STYPE_ATOM) + void Select(int selHnd, SELECTION_TYPE sType, int iModel, cpstr Chains, + int ResNo1, cpstr Ins1, int ResNo2, cpstr Ins2, cpstr RNames, + cpstr ANames, cpstr Elements, cpstr altLocs, SELECTION_KEY selKey = SKEY_OR); + void SelectAtoms(int selHnd, int iModel, cpstr Chains, int ResNo1, cpstr Ins1, + int ResNo2, cpstr Ins2, cpstr RNames, cpstr ANames, + cpstr Elements, cpstr altLocs, SELECTION_KEY selKey = SKEY_OR) { + Select(selHnd, STYPE_ATOM, iModel, Chains, ResNo1, Ins1, ResNo2, Ins2, + RNames, ANames, Elements, altLocs, selKey); + } + void SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, realtype y, + realtype z, realtype r, SELECTION_KEY sKey = SKEY_OR); + + // ---- contacts (gemmi-free uniform-grid search) ---- + void SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, + realtype d2, int seqDist, PContact &contact, int &ncontacts, + int maxlen = 0, long group = 0); + void SeekContacts(PPAtom A, int n, realtype d1, realtype d2, int seqDist, + PContact &contact, int &ncontacts, int maxlen = 0, long group = 0); + + int FinishStructEdit() { return 0; } // no-op: wrappers stay in sync eagerly + + // ---- UDData registry ---- + struct UDReg { UDR_TYPE type; int kind; std::string name; int slot; }; // kind:0=int,1=real,2=str + std::vector ud_regs; + int ud_counts[5][3] = {{0}}; // [UDR_TYPE][kind] -> next slot + + int RegisterUDInteger(UDR_TYPE t, cpstr name) { return _regUD(t, 0, name); } + int RegisterUDReal (UDR_TYPE t, cpstr name) { return _regUD(t, 1, name); } + int RegisterUDString (UDR_TYPE t, cpstr name) { return _regUD(t, 2, name); } + int GetUDDHandle(UDR_TYPE t, cpstr name) { + for (int i = 0; i < (int)ud_regs.size(); ++i) + if (ud_regs[i].type == t && ud_regs[i].name == name) return i; + return -1; + } +private: + int _regUD(UDR_TYPE t, int kind, cpstr name) { + ud_regs.push_back({t, kind, name ? name : "", ud_counts[t][kind]++}); + return (int)ud_regs.size() - 1; + } +public: + + // ---- I/O (defined in mmdb-shim/src/io.cc; keeps heavy gemmi write/read + // headers out of the ~229 Coot TUs that include mmdb_manager.h) ---- + ERROR_CODE ReadPDBASCII(cpstr fname); + ERROR_CODE ReadCoorFile(cpstr fname); // auto-detects PDB / mmCIF + ERROR_CODE WritePDBASCII(cpstr fname); + ERROR_CODE WriteCIFASCII(cpstr fname); +}; + +// ---- g() resolvers ---- +inline gemmi::Model &Model::g() const { return mgr->st.models[mi]; } +inline gemmi::Chain &Chain::g() const { return model->g().chains[ci]; } +inline gemmi::Residue &Residue::g() const { return chain->g().residues[ri]; } +inline gemmi::Atom &Atom::g() const { return res->g().atoms[ai]; } + +// ---- UDData helpers ---- +inline Manager::UDReg *_ud_desc(Manager *mgr, UDR_TYPE myType, int handle, int kind, + int &err) { + if (!mgr || handle < 0 || handle >= (int)mgr->ud_regs.size()) { err = UDDATA_WrongHandle; return nullptr; } + Manager::UDReg &d = mgr->ud_regs[handle]; + if (d.type != myType || d.kind != kind) { err = UDDATA_WrongUDRType; return nullptr; } + err = UDDATA_Ok; return &d; +} +inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, int v) { + int e; auto *d = _ud_desc(mgr, t, h, 0, e); if (!d) return e; + if ((int)s._udi.size() <= d->slot) s._udi.resize(d->slot + 1, 0); + s._udi[d->slot] = v; return UDDATA_Ok; +} +inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, realtype v) { + int e; auto *d = _ud_desc(mgr, t, h, 1, e); if (!d) return e; + if ((int)s._udr.size() <= d->slot) s._udr.resize(d->slot + 1, 0.0); + s._udr[d->slot] = v; return UDDATA_Ok; +} +inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, cpstr v) { + int e; auto *d = _ud_desc(mgr, t, h, 2, e); if (!d) return e; + if ((int)s._uds.size() <= d->slot) s._uds.resize(d->slot + 1); + s._uds[d->slot] = v ? v : ""; return UDDATA_Ok; +} +inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, int &v) { + int e; auto *d = _ud_desc(mgr, t, h, 0, e); if (!d) return e; + if ((int)s._udi.size() <= d->slot) return UDDATA_NoData; + v = s._udi[d->slot]; return UDDATA_Ok; +} +inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, realtype &v) { + int e; auto *d = _ud_desc(mgr, t, h, 1, e); if (!d) return e; + if ((int)s._udr.size() <= d->slot) return UDDATA_NoData; + v = s._udr[d->slot]; return UDDATA_Ok; +} + +// ---- Atom out-of-line ---- +inline pstr Atom::GetAtomName() { + std::snprintf(_name_buf, sizeof(_name_buf), "%s", g().name.c_str()); + return _name_buf; +} +inline void Atom::SetAtomName(const AtomName aName) { g().name = aName; } +inline pstr Atom::GetElementName() { + std::snprintf(_elem_buf, sizeof(_elem_buf), "%s", g().element.name()); + return _elem_buf; +} +inline void Atom::SetElementName(const Element elName) { g().element = gemmi::Element(elName); } +inline cpstr Atom::GetChainID() { return res->GetChainID(); } +inline int Atom::GetSeqNum() { return res->GetSeqNum(); } +inline pstr Atom::GetInsCode() { return res->GetInsCode(); } +inline pstr Atom::GetResName() { return res->GetResName(); } +inline int Atom::GetModelNum() { return res->GetModelNum(); } +inline int Atom::GetIndex() { return ai; } +inline void Atom::SetCoordinates(realtype xx, realtype yy, realtype zz, + realtype occ, realtype tF) { + auto &a = g(); a.pos = gemmi::Position(xx, yy, zz); a.occ = (float)occ; a.b_iso = (float)tF; +} + +// ---- Residue out-of-line ---- +inline pstr Residue::GetResName() { + std::snprintf(_resname_buf, sizeof(_resname_buf), "%s", g().name.c_str()); + return _resname_buf; +} +inline int Residue::GetSeqNum() { return g().seqid.num.value; } +inline pstr Residue::GetInsCode() { + _inscode_buf[0] = g().seqid.icode == ' ' ? '\0' : g().seqid.icode; _inscode_buf[1] = '\0'; + return _inscode_buf; +} +inline cpstr Residue::GetChainID() { return chain->GetChainID(); } +inline int Residue::GetModelNum() { return chain->model->GetSerNum(); } +inline PAtom Residue::GetAtom(const AtomName aname, const Element elname, const AltLoc aloc) { + for (Atom *a : atoms) { + if (a->g().name != aname) continue; + if (elname && *elname && a->g().element.name() != std::string(elname)) continue; + if (aloc && *aloc && a->g().altloc != aloc[0]) continue; + return a; + } + return nullptr; +} +inline PAtom Residue::AddAtom(Manager &m, gemmi::Atom a) { + g().atoms.push_back(std::move(a)); + Atom *aw = m.newAtom(); aw->mgr = &m; aw->res = this; aw->ai = (int)atoms.size(); + atoms.push_back(aw); + return aw; +} +inline void Residue::DeleteAtom(int pos) { + if (pos < 0 || pos >= (int)atoms.size()) return; + g().atoms.erase(g().atoms.begin() + pos); + atoms[pos]->alive = false; atoms[pos]->ai = -1; + atoms.erase(atoms.begin() + pos); + for (int k = pos; k < (int)atoms.size(); ++k) atoms[k]->ai = k; +} + +// ---- Chain out-of-line ---- +inline cpstr Chain::GetChainID() { + std::snprintf(_chainid_buf, sizeof(_chainid_buf), "%s", g().name.c_str()); + return _chainid_buf; +} +inline PResidue Chain::AddResidue(Manager &m, gemmi::Residue r) { + g().residues.push_back(std::move(r)); + Residue *rw = m.newRes(); rw->mgr = &m; rw->chain = this; rw->ri = (int)residues.size(); + for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { + Atom *aw = m.newAtom(); aw->mgr = &m; aw->res = rw; aw->ai = ai; rw->atoms.push_back(aw); + } + residues.push_back(rw); + return rw; +} +inline PResidue Chain::InsResidue(Manager &m, int pos, gemmi::Residue r) { + g().residues.insert(g().residues.begin() + pos, std::move(r)); + Residue *rw = m.newRes(); rw->mgr = &m; rw->chain = this; rw->ri = pos; + residues.insert(residues.begin() + pos, rw); + for (int k = pos + 1; k < (int)residues.size(); ++k) residues[k]->ri = k; + for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { + Atom *aw = m.newAtom(); aw->mgr = &m; aw->res = rw; aw->ai = ai; rw->atoms.push_back(aw); + } + return rw; +} + +// ---- Model out-of-line ---- +inline PChain Model::GetChain(const ChainID chID) { + for (Chain *c : chains) if (c->g().name == chID) return c; + return nullptr; +} + +// ---- Manager out-of-line ---- +inline void Manager::build_from_gemmi() { + models.clear(); + for (int mi = 0; mi < (int)st.models.size(); ++mi) { + Model *mw = newModel(); mw->mgr = this; mw->mi = mi; + auto &gm = st.models[mi]; + for (int ci = 0; ci < (int)gm.chains.size(); ++ci) { + Chain *cw = newChain(); cw->mgr = this; cw->model = mw; cw->ci = ci; + auto &gc = gm.chains[ci]; + for (int ri = 0; ri < (int)gc.residues.size(); ++ri) { + Residue *rw = newRes(); rw->mgr = this; rw->chain = cw; rw->ri = ri; + auto &gr = gc.residues[ri]; + for (int ai = 0; ai < (int)gr.atoms.size(); ++ai) { + Atom *aw = newAtom(); aw->mgr = this; aw->res = rw; aw->ai = ai; + rw->atoms.push_back(aw); + } + cw->residues.push_back(rw); + } + mw->chains.push_back(cw); + } + models.push_back(mw); + } +} + +// ---- selection matching ---- +namespace detail { +inline bool inList(cpstr list, const std::string &v) { + if (!list || !*list || std::strcmp(list, "*") == 0) return true; + const char *p = list; + while (*p) { + const char *c = std::strchr(p, ','); + std::string tok(p, c ? (size_t)(c - p) : std::strlen(p)); + size_t a = tok.find_first_not_of(' '), b = tok.find_last_not_of(' '); + tok = (a == std::string::npos) ? std::string() : tok.substr(a, b - a + 1); + if (tok == v) return true; + if (!c) break; p = c + 1; + } + return false; +} +inline bool altMatch(cpstr list, char alt) { + if (!list || std::strcmp(list, "*") == 0) return true; + std::string a = alt ? std::string(1, alt) : std::string(); + if (!*list) return a.empty(); // "" -> only blank altLoc + return inList(list, a); +} +} // namespace detail + +inline void Manager::Select(int selHnd, SELECTION_TYPE sType, int iModel, + cpstr Chains, int ResNo1, cpstr Ins1, int ResNo2, cpstr Ins2, cpstr RNames, + cpstr ANames, cpstr Elements, cpstr altLocs, SELECTION_KEY selKey) { + (void)Ins1; (void)Ins2; // insertion-code range filtering: TODO (rare in Coot) + Selection &sel = selections[selHnd - 1]; + if (sel.type == STYPE_UNDEFINED) sel.type = sType; + std::vector oldA = sel.atoms; std::vector oldR = sel.residues; + + std::vector mAtoms; std::vector mResidues; + for (Model *mw : models) { + if (iModel > 0 && mw->GetSerNum() != iModel) continue; + for (Chain *cw : mw->chains) { + if (!detail::inList(Chains, cw->g().name)) continue; + for (Residue *rw : cw->residues) { + int sn = rw->g().seqid.num.value; + if (ResNo1 != ANY_RES && sn < ResNo1) continue; + if (ResNo2 != ANY_RES && sn > ResNo2) continue; + if (!detail::inList(RNames, rw->g().name)) continue; + bool anyAtom = false; + for (Atom *aw : rw->atoms) { + if (!detail::inList(ANames, aw->g().name)) continue; + if (!detail::inList(Elements, aw->g().element.name())) continue; + if (!detail::altMatch(altLocs, aw->g().altloc)) continue; + anyAtom = true; + if (sType == STYPE_ATOM) mAtoms.push_back(aw); + } + if (anyAtom && sType == STYPE_RESIDUE) mResidues.push_back(rw); + } + } + } + auto combine = [&](auto &cur, auto &matched) { + using Vec = typename std::decay::type; + std::set curset(cur.begin(), cur.end()); + std::set mset(matched.begin(), matched.end()); + if (selKey == SKEY_NEW) { cur = matched; } + else if (selKey == SKEY_OR) { for (auto *x : matched) if (!curset.count(x)) cur.push_back(x); } + else if (selKey == SKEY_AND) { Vec o; for (auto *x : cur) if (mset.count(x)) o.push_back(x); cur = o; } + else if (selKey == SKEY_XOR) { Vec o; for (auto *x : cur) if (!mset.count(x)) o.push_back(x); + for (auto *x : matched) if (!curset.count(x)) o.push_back(x); cur = o; } + else if (selKey == SKEY_CLR) { Vec o; for (auto *x : cur) if (!mset.count(x)) o.push_back(x); cur = o; } + }; + if (sType == STYPE_ATOM) combine(sel.atoms, mAtoms); + else if (sType == STYPE_RESIDUE) combine(sel.residues, mResidues); + for (Atom *a : oldA) a->_setInSel(selHnd, false); + for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); + for (Residue *r : oldR) r->_setInSel(selHnd, false); + for (Residue *r : sel.residues) r->_setInSel(selHnd, true); +} + +inline void Manager::SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, + realtype y, realtype z, realtype r, SELECTION_KEY sKey) { + Selection &sel = selections[selHnd - 1]; + if (sel.type == STYPE_UNDEFINED) sel.type = sType; + std::vector oldA = sel.atoms; std::vector oldR = sel.residues; + gemmi::Position c(x, y, z); double r2 = r * r; + std::vector mAtoms; std::vector mResidues; + for (Model *mw : models) + for (Chain *cw : mw->chains) + for (Residue *rw : cw->residues) { + bool any = false; + for (Atom *aw : rw->atoms) + if (aw->g().pos.dist_sq(c) <= r2) { any = true; if (sType == STYPE_ATOM) mAtoms.push_back(aw); } + if (any && sType == STYPE_RESIDUE) mResidues.push_back(rw); + } + auto combine = [&](auto &cur, auto &m) { + std::set::type::value_type> cs(cur.begin(), cur.end()); + if (sKey == SKEY_NEW) cur = m; + else if (sKey == SKEY_OR) { for (auto *p : m) if (!cs.count(p)) cur.push_back(p); } + }; + if (sType == STYPE_ATOM) combine(sel.atoms, mAtoms); + else if (sType == STYPE_RESIDUE) combine(sel.residues, mResidues); + for (Atom *a : oldA) a->_setInSel(selHnd, false); + for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); + for (Residue *r : oldR) r->_setInSel(selHnd, false); + for (Residue *r : sel.residues) r->_setInSel(selHnd, true); +} + +// SeekContacts (both overloads) is defined in mmdb-shim/src/contacts.cc using +// gemmi::NeighborSearch — keeps the heavy neighbor.hpp out of Coot's many TUs. + +} // namespace mmdb diff --git a/mmdb-shim/include/mmdb2/mmdb_atom.h b/mmdb-shim/include/mmdb2/mmdb_atom.h new file mode 100644 index 0000000000..1c85475ad5 --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_atom.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_atom_H +#define COOT_MMDB_SHIM_mmdb_atom_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/include/mmdb2/mmdb_chain.h b/mmdb-shim/include/mmdb2/mmdb_chain.h new file mode 100644 index 0000000000..2b8a0940de --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_chain.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_chain_H +#define COOT_MMDB_SHIM_mmdb_chain_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/include/mmdb2/mmdb_coormngr.h b/mmdb-shim/include/mmdb2/mmdb_coormngr.h new file mode 100644 index 0000000000..36f8af4efc --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_coormngr.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_coormngr_H +#define COOT_MMDB_SHIM_mmdb_coormngr_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/include/mmdb2/mmdb_defs.h b/mmdb-shim/include/mmdb2/mmdb_defs.h new file mode 100644 index 0000000000..3765f7795f --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_defs.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_defs_H +#define COOT_MMDB_SHIM_mmdb_defs_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/include/mmdb2/mmdb_manager.h b/mmdb-shim/include/mmdb2/mmdb_manager.h new file mode 100644 index 0000000000..be05d71526 --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_manager.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_manager_H +#define COOT_MMDB_SHIM_mmdb_manager_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/include/mmdb2/mmdb_math_align.h b/mmdb-shim/include/mmdb2/mmdb_math_align.h new file mode 100644 index 0000000000..e3ed007f1e --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_math_align.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_math_align_H +#define COOT_MMDB_SHIM_mmdb_math_align_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/include/mmdb2/mmdb_math_graph.h b/mmdb-shim/include/mmdb2/mmdb_math_graph.h new file mode 100644 index 0000000000..0e40f6721b --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_math_graph.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_math_graph_H +#define COOT_MMDB_SHIM_mmdb_math_graph_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/include/mmdb2/mmdb_mattype.h b/mmdb-shim/include/mmdb2/mmdb_mattype.h new file mode 100644 index 0000000000..fc9a94a271 --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_mattype.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_mattype_H +#define COOT_MMDB_SHIM_mmdb_mattype_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/include/mmdb2/mmdb_model.h b/mmdb-shim/include/mmdb2/mmdb_model.h new file mode 100644 index 0000000000..070e0f1a40 --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_model.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_model_H +#define COOT_MMDB_SHIM_mmdb_model_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/include/mmdb2/mmdb_selmngr.h b/mmdb-shim/include/mmdb2/mmdb_selmngr.h new file mode 100644 index 0000000000..1028c48ecb --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_selmngr.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_selmngr_H +#define COOT_MMDB_SHIM_mmdb_selmngr_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/include/mmdb2/mmdb_tables.h b/mmdb-shim/include/mmdb2/mmdb_tables.h new file mode 100644 index 0000000000..aeee5d9dcd --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_tables.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_tables_H +#define COOT_MMDB_SHIM_mmdb_tables_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/include/mmdb2/mmdb_uddata.h b/mmdb-shim/include/mmdb2/mmdb_uddata.h new file mode 100644 index 0000000000..36444b2760 --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_uddata.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_uddata_H +#define COOT_MMDB_SHIM_mmdb_uddata_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/include/mmdb2/mmdb_utils.h b/mmdb-shim/include/mmdb2/mmdb_utils.h new file mode 100644 index 0000000000..c60636697e --- /dev/null +++ b/mmdb-shim/include/mmdb2/mmdb_utils.h @@ -0,0 +1,11 @@ +// mmdb-shim public header. When COOT_USE_MMDB_SHIM is defined, resolves to the +// gemmi-backed shim; otherwise falls through to the real MMDB header via +// #include_next (requires this dir to precede real mmdb2 on the include path). +#ifndef COOT_MMDB_SHIM_mmdb_utils_H +#define COOT_MMDB_SHIM_mmdb_utils_H +# ifdef COOT_USE_MMDB_SHIM +# include "_shim_impl.hh" +# else +# include_next +# endif +#endif diff --git a/mmdb-shim/src/contacts.cc b/mmdb-shim/src/contacts.cc new file mode 100644 index 0000000000..7572ffaf0d --- /dev/null +++ b/mmdb-shim/src/contacts.cc @@ -0,0 +1,86 @@ +// mmdb-shim contact search — Manager::SeekContacts via gemmi::NeighborSearch +// (grid-accelerated; handles crystallographic PBC and non-crystal bounding box). +// Compiled separately so gemmi/neighbor.hpp stays out of Coot's many TUs. +#define COOT_USE_MMDB_SHIM 1 +#include + +#include + +#include +#include + +namespace mmdb { +namespace { + +bool seqNeglect(Atom *a, Atom *b, int seqDist) { + if (seqDist <= 0) return false; + if (a->res->chain != b->res->chain) return false; + return std::abs(a->GetSeqNum() - b->GetSeqNum()) < seqDist; +} +void alloc_contacts(std::vector &v, PContact &out, int &n) { + n = (int)v.size(); + out = n ? new Contact[n] : nullptr; // caller delete[]s (MMDB semantics) + for (int i = 0; i < n; ++i) out[i] = v[i]; +} +// Map a NeighborSearch Mark back to the shim wrapper via the parallel tree. +inline Atom *mark_to_atom(Model *mw, const gemmi::NeighborSearch::Mark *m) { + return mw->chains[m->chain_idx]->residues[m->residue_idx]->atoms[m->atom_idx]; +} + +} // namespace + +void Manager::SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, + realtype d2, int seqDist, PContact &contact, int &ncontacts, int /*maxlen*/, + long group) { + std::vector found; + if (n1 > 0 && n2 > 0) { + Model *mw = A1[0]->res->chain->model; // NeighborSearch is per-model + gemmi::NeighborSearch ns(mw->g(), st.cell, d2); + ns.populate(true); + std::unordered_map a2idx; + a2idx.reserve(n2 * 2); + for (int j = 0; j < n2; ++j) a2idx.emplace(A2[j], j); + + for (int i = 0; i < n1; ++i) { + if (A1[i]->res->chain->model != mw) continue; // single-model contact search + for (auto *m : ns.find_atoms(A1[i]->g().pos, '\0', d1, d2)) { + if (m->image_idx != 0) continue; // exclude symmetry mates + Atom *b = mark_to_atom(mw, m); + if (A1[i] == b) continue; + auto it = a2idx.find(b); + if (it == a2idx.end()) continue; + if (seqNeglect(A1[i], b, seqDist)) continue; + found.push_back({i, it->second, group, A1[i]->g().pos.dist(b->g().pos)}); + } + } + } + alloc_contacts(found, contact, ncontacts); +} + +void Manager::SeekContacts(PPAtom A, int n, realtype d1, realtype d2, + int seqDist, PContact &contact, int &ncontacts, int /*maxlen*/, long group) { + std::vector found; + if (n > 0) { + Model *mw = A[0]->res->chain->model; + gemmi::NeighborSearch ns(mw->g(), st.cell, d2); + ns.populate(true); + std::unordered_map idx; + idx.reserve(n * 2); + for (int i = 0; i < n; ++i) idx.emplace(A[i], i); + + for (int i = 0; i < n; ++i) { + if (A[i]->res->chain->model != mw) continue; + for (auto *m : ns.find_atoms(A[i]->g().pos, '\0', d1, d2)) { + if (m->image_idx != 0) continue; + Atom *b = mark_to_atom(mw, m); + auto it = idx.find(b); + if (it == idx.end() || it->second <= i) continue; // unordered pairs, once + if (seqNeglect(A[i], b, seqDist)) continue; + found.push_back({i, it->second, group, A[i]->g().pos.dist(b->g().pos)}); + } + } + } + alloc_contacts(found, contact, ncontacts); +} + +} // namespace mmdb diff --git a/mmdb-shim/src/io.cc b/mmdb-shim/src/io.cc new file mode 100644 index 0000000000..17356fa34c --- /dev/null +++ b/mmdb-shim/src/io.cc @@ -0,0 +1,56 @@ +// mmdb-shim I/O — Manager read/write via gemmi (architecture B: gemmi is the +// live store, so read = parse + build wrapper tree; write = serialize st). +// Compiled once (links libgemmi_cpp) so the heavy gemmi write/read headers stay +// out of the many Coot TUs that include . +#define COOT_USE_MMDB_SHIM 1 +#include + +#include // read_structure_file (auto-detect) +#include // read_pdb_file +#include // write_pdb +#include // make_mmcif_document +#include // write_cif_to_stream + +#include + +namespace mmdb { + +// Rebuild the wrapper tree from a freshly loaded gemmi::Structure. We do NOT run +// gemmi's setup_entities()/subchain splitting — MMDB parity wants the raw chains +// as they appear in the file. +ERROR_CODE Manager::ReadPDBASCII(cpstr fname) { + try { + st = gemmi::read_pdb_file(fname); + } catch (const std::exception &) { + return Error_CantOpenFile; + } + build_from_gemmi(); + return Error_NoError; +} + +ERROR_CODE Manager::ReadCoorFile(cpstr fname) { + try { + st = gemmi::read_structure_file(fname); + } catch (const std::exception &) { + return Error_CantOpenFile; + } + build_from_gemmi(); + return Error_NoError; +} + +ERROR_CODE Manager::WritePDBASCII(cpstr fname) { + std::ofstream os(fname); + if (!os) return Error_CantOpenFile; + gemmi::write_pdb(st, os); + return Error_NoError; +} + +ERROR_CODE Manager::WriteCIFASCII(cpstr fname) { + std::ofstream os(fname); + if (!os) return Error_CantOpenFile; + gemmi::cif::Document doc = gemmi::make_mmcif_document(st); + gemmi::cif::write_cif_to_stream(os, doc); + return Error_NoError; +} + +} // namespace mmdb From fff49751dc937540a5bfe4f5004118b917e7d329 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Tue, 21 Jul 2026 20:02:00 +0100 Subject: [PATCH 05/23] Updated source code and MMDB implementation --- .../CXXClasses/AtomPropertyRampColorRule.h | 2 +- .../CXXClasses/BondsPrimitive.cpp | 4 +- .../CXXClasses/CylindersPrimitive.cpp | 4 +- .../CXXClasses/DiscreteSegment.h | 8 +- .../CXXClasses/FlatFanPrimitive.cpp | 6 +- .../CXXClasses/MolecularRepresentation.cpp | 44 +- .../CXXClasses/MyMolecule.cpp | 30 +- .../CXXClasses/SecondaryColorScheme.h | 2 +- .../CXXClasses/SticksPrimitive.cpp | 8 +- MoleculesToTriangles/CXXSurface/CXXBall.h | 2 +- MoleculesToTriangles/CXXSurface/CXXCircle.cpp | 2 +- .../CXXSurface/CXXCircleNode.cpp | 12 +- .../CXXSurface/CXXCreator.cpp | 14 +- .../CXXSurface/CXXNewHood.cpp | 6 +- MoleculesToTriangles/CXXSurface/CXXNewHood.h | 2 +- .../CXXSurface/CXXQADSurface.cpp | 38 +- .../CXXSurface/CXXSphereElement.cpp | 14 +- .../CXXSurface/CXXSurface.cpp | 4 +- .../CXXSurface/CXXSurfaceMaker.cpp | 2 +- MoleculesToTriangles/CXXSurface/CXXUtils.cpp | 16 +- analysis/b-factor-histogram.cc | 8 +- analysis/bfkurt.cc | 8 +- analysis/cablam.cc | 16 +- analysis/daca.cc | 112 +- analysis/mogul.cc | 10 +- analysis/typed-distances.cc | 2 +- api/add-terminal-residue.cc | 40 +- api/coot-molecule-bonds-instanced.cc | 16 +- api/coot-molecule-bonds.cc | 12 +- api/coot-molecule-json.cc | 20 +- api/coot-molecule-maps.cc | 14 +- api/coot-molecule-merge-molecules.cc | 16 +- api/coot-molecule-modelling.cc | 4 +- api/coot-molecule-refine.cc | 8 +- api/coot-molecule-replace-fragment.cc | 18 +- api/coot-molecule-validation.cc | 26 +- api/coot-molecule.cc | 324 +++--- api/filo-tests.cc | 4 +- api/model-analysis.cc | 4 +- api/molecules-container-ligand-fitting.cc | 24 +- api/molecules-container-maps.cc | 4 +- api/molecules-container-modelling.cc | 8 +- ...molecules-container-molecular-placement.cc | 2 +- api/molecules-container-nanobind.cc | 38 +- api/molecules-container-superpose.cc | 6 +- api/molecules-container.cc | 26 +- api/moorhen-h-bonds.cc | 22 +- api/rama-plot-phi-psi.cc | 40 +- api/rigid-body-fit.cc | 8 +- api/test-molecules-container.cc | 108 +- coords/Bond_lines.cc | 738 +++++++------- coords/Bond_lines.hh | 2 +- coords/Bond_lines_ext.cc | 18 +- coords/graphical-bonds-container.hh | 4 +- coords/graphics-line.cc | 4 +- coords/loop-path.cc | 4 +- coords/mmdb-crystal.cc | 70 +- coords/mmdb-extras.cc | 10 +- coords/mmdb.cc | 16 +- coords/phenix-geo-bonds.cc | 16 +- coot-utils/atom-overlaps.cc | 74 +- coot-utils/atom-selection-container.cc | 46 +- coot-utils/atom-selection-container.hh | 14 +- coot-utils/bonded-pairs.cc | 2 +- coot-utils/c-beta-deviations.cc | 10 +- coot-utils/cablam-markup.cc | 10 +- coot-utils/cfc.cc | 10 +- coot-utils/contact-info.cc | 42 +- coot-utils/contacts-by-bricks.cc | 34 +- coot-utils/coot-coord-extras.cc | 96 +- coot-utils/coot-coord-lsq.cc | 36 +- coot-utils/coot-coord-utils-glyco.cc | 52 +- coot-utils/coot-coord-utils-nucleotides.cc | 62 +- coot-utils/coot-coord-utils.cc | 678 ++++++------- coot-utils/coot-fffear.cc | 10 +- coot-utils/coot-h-bonds.cc | 34 +- coot-utils/coot-map-heavy.cc | 64 +- coot-utils/coot-map-utils.cc | 72 +- coot-utils/coot-rama.cc | 40 +- coot-utils/coot-shelx-ins.cc | 102 +- coot-utils/coot-tree-extras.cc | 62 +- coot-utils/coot_shiftfield.cpp | 18 +- coot-utils/dict-link-info.cc | 4 +- coot-utils/edcalc.cc | 8 +- coot-utils/find-water-baddies.cc | 24 +- coot-utils/gaussian-atom-map-for-mask.cc | 2 +- coot-utils/glyco-torsions.cc | 6 +- coot-utils/helix-analysis.cc | 4 +- coot-utils/helix-like.cc | 4 +- coot-utils/hole.cc | 10 +- coot-utils/jed-flip.cc | 2 +- coot-utils/lsq-improve.cc | 2 +- coot-utils/merge-C-and-N-terminii.cc | 10 +- coot-utils/merge-atom-selections.cc | 36 +- coot-utils/mutate.cc | 62 +- coot-utils/peak-search.cc | 2 +- coot-utils/pepflip-using-difference-map.cc | 8 +- coot-utils/plane-utils.cc | 4 +- coot-utils/polar-atoms.cc | 6 +- coot-utils/q-score.hh | 2 +- coot-utils/read-sm-cif.cc | 18 +- coot-utils/reduce.cc | 50 +- coot-utils/secondary-structure-headers.cc | 4 +- coot-utils/stack-and-pair.cc | 44 +- coot-utils/trim.cc | 6 +- coot-utils/water-coordination.cc | 20 +- db-main/db-strands.cc | 18 +- density-contour/gaussian-surface.cc | 2 +- docking/haddock-utils.cc | 16 +- docking/intermolecular-energy.cc | 20 +- docking/test-docking.cc | 60 +- geometry/dict-utils.cc | 2 +- geometry/dictionary-residue.cc | 30 +- geometry/dreiding.cc | 24 +- geometry/hydrophobic.cc | 2 +- geometry/link.cc | 16 +- geometry/main-chain.cc | 8 +- geometry/mol-utils.cc | 4 +- geometry/protein-geometry.cc | 28 +- geometry/residue-and-atom-specs.cc | 10 +- geometry/residue-and-atom-specs.hh | 8 +- high-res/high-res.cc | 26 +- high-res/sequence-assignment.cc | 22 +- ideal/add-linked-cho.cc | 40 +- ideal/chirals.cc | 48 +- ideal/crankshaft.cc | 20 +- ideal/distortion.cc | 40 +- ideal/extra-restraints-kk.cc | 4 +- ideal/extra-restraints.cc | 42 +- ideal/flanking.cc | 4 +- ideal/gradients.cc | 4 +- ideal/link-restraints.cc | 132 +-- ideal/make-restraints.cc | 204 ++-- ideal/mods.cc | 62 +- ideal/ng.cc | 86 +- ideal/pepflip.cc | 36 +- ideal/pull-restraint.cc | 16 +- ideal/simple-restraint.cc | 148 +-- ideal/simple-restraint.hh | 10 +- ideal/torsion-bonds.cc | 34 +- ideal/trans-peptide.cc | 32 +- lidia-core/bond-record-container-t.hh | 2 +- lidia-core/chemical-feature-clusters.hh | 2 +- lidia-core/get-residue.cc | 2 +- lidia-core/lbg-molfile.cc | 16 +- lidia-core/rdkit-interface.cc | 56 +- ligand/backrub-rotamer.cc | 78 +- ligand/base-pairing.cc | 8 +- ligand/chi-angles.cc | 50 +- ligand/dipole.cc | 16 +- ligand/ideal-rna.cc | 18 +- ligand/libres-tracer.cc | 50 +- ligand/ligand-extras.cc | 10 +- ligand/ligand.cc | 10 +- ligand/molecular-replacement.cc | 34 +- ligand/monomer-utils.cc | 14 +- ligand/new-residue-by-3-phi-psi.cc | 2 +- ligand/primitive-chi-angles.cc | 28 +- ligand/rama-rsr-extend-fragments.cc | 10 +- ligand/residue_by_phi_psi.cc | 2 +- ligand/rotamer.cc | 28 +- ligand/side-chain-densities.cc | 12 +- ligand/side-chain.cc | 14 +- ligand/torsion-general.cc | 48 +- mini-mol/atom-quads.cc | 72 +- mini-mol/mini-mol.cc | 86 +- mmdb-shim/build-shimlib.sh | 23 + mmdb-shim/build.sh | 54 + mmdb-shim/core/bench_edits | Bin 0 -> 61992 bytes mmdb-shim/core/test_core | Bin 0 -> 579000 bytes mmdb-shim/include/mmdb2/_mmcif_impl.hh | 601 +++++++++++ mmdb-shim/include/mmdb2/_shim_impl.hh | 957 +++++++++++++++++- mmdb-shim/shim-cxx | 9 + mmdb-shim/src/contacts.cc | 44 +- pli/dots-representation-info.cc | 34 +- pli/flev-annotations.hh | 2 +- pli/flev-attached-hydrogens.cc | 62 +- pli/flev.cc | 10 +- pli/pi-stacking.cc | 34 +- pli/protein-ligand-interactions.cc | 56 +- python/coot_commands/mic.py | 124 +++ python/coot_commands/tts.py | 100 ++ skeleton/BuildCas.cc | 30 +- src/coot-nomenclature.cc | 66 +- 184 files changed, 4960 insertions(+), 3128 deletions(-) create mode 100755 mmdb-shim/build-shimlib.sh create mode 100755 mmdb-shim/build.sh create mode 100755 mmdb-shim/core/bench_edits create mode 100755 mmdb-shim/core/test_core create mode 100644 mmdb-shim/include/mmdb2/_mmcif_impl.hh create mode 100755 mmdb-shim/shim-cxx create mode 100644 python/coot_commands/mic.py create mode 100644 python/coot_commands/tts.py diff --git a/MoleculesToTriangles/CXXClasses/AtomPropertyRampColorRule.h b/MoleculesToTriangles/CXXClasses/AtomPropertyRampColorRule.h index 179fec24cb..b1f1e3b30d 100644 --- a/MoleculesToTriangles/CXXClasses/AtomPropertyRampColorRule.h +++ b/MoleculesToTriangles/CXXClasses/AtomPropertyRampColorRule.h @@ -220,7 +220,7 @@ class AtomPropertyRampColorRule : public ColorRule { if (value > endValue) value = endValue; } else if (rampType == BFactor){ - value= atom->tempFactor; + value= atom->tempFactor(); if (value < startValue) value = startValue; if (value > endValue) value = endValue; } else { diff --git a/MoleculesToTriangles/CXXClasses/BondsPrimitive.cpp b/MoleculesToTriangles/CXXClasses/BondsPrimitive.cpp index 9c9d8c9bb4..9c317ac8c3 100644 --- a/MoleculesToTriangles/CXXClasses/BondsPrimitive.cpp +++ b/MoleculesToTriangles/CXXClasses/BondsPrimitive.cpp @@ -45,7 +45,7 @@ void BondsPrimitive::evaluateGLPrimitives(std::map, i unsigned long midpointIndex = 0; int iBond = 0; for (; centralAtomPntr != bonds.end(); ++centralAtomPntr, iAtom++){ - FCXXCoord atom1Coord(centralAtomPntr->first->x, centralAtomPntr->first->y, centralAtomPntr->first->z, 0.); + FCXXCoord atom1Coord(centralAtomPntr->first->x(), centralAtomPntr->first->y(), centralAtomPntr->first->z(), 0.); FCXXCoord atom1Color = colorScheme->colorForAtom(centralAtomPntr->first, handles); for (int i=0; i<4; i++) { vertexColorArray[iAtom].vertex[i] = atom1Coord[i]; @@ -54,7 +54,7 @@ void BondsPrimitive::evaluateGLPrimitives(std::map, i std::vector::iterator bondedAtomPntr = centralAtomPntr->second.begin(); for (; bondedAtomPntr != centralAtomPntr->second.end(); ++bondedAtomPntr, iMidpoint++){ midpointIndex = bonds.size() + iMidpoint; - FCXXCoord atom2Coord((*bondedAtomPntr)->x, (*bondedAtomPntr)->y, (*bondedAtomPntr)->z, 0.); + FCXXCoord atom2Coord((*bondedAtomPntr)->x(), (*bondedAtomPntr)->y(), (*bondedAtomPntr)->z(), 0.); FCXXCoord midpoint = (atom1Coord + atom2Coord) / 2.; for (int i=0; i<4; i++) { vertexColorArray[midpointIndex].vertex[i] = midpoint[i]; diff --git a/MoleculesToTriangles/CXXClasses/CylindersPrimitive.cpp b/MoleculesToTriangles/CXXClasses/CylindersPrimitive.cpp index 3594f55552..5b08553c98 100644 --- a/MoleculesToTriangles/CXXClasses/CylindersPrimitive.cpp +++ b/MoleculesToTriangles/CXXClasses/CylindersPrimitive.cpp @@ -28,8 +28,8 @@ void CylindersPrimitive::addHalfAtomBond(mmdb::Atom* atom1, FCXXCoord &atom1Color, mmdb::Atom* atom2, FCXXCoord &atom2Color, float cylinderRadius) { - FCXXCoord coord1(atom1->x, atom1->y, atom1->z); - FCXXCoord coord2(atom2->x, atom2->y, atom2->z); + FCXXCoord coord1(atom1->x(), atom1->y(), atom1->z()); + FCXXCoord coord2(atom2->x(), atom2->y(), atom2->z()); addHalfAtomBondWithCoords(coord1, atom1, atom1Color, coord2,atom2, atom2Color, cylinderRadius); } diff --git a/MoleculesToTriangles/CXXClasses/DiscreteSegment.h b/MoleculesToTriangles/CXXClasses/DiscreteSegment.h index 62be785a4b..6d3e2ada1f 100644 --- a/MoleculesToTriangles/CXXClasses/DiscreteSegment.h +++ b/MoleculesToTriangles/CXXClasses/DiscreteSegment.h @@ -54,17 +54,17 @@ class DiscreteSegment { } void addCalpha(mmdb::Atom* calpha){ calphas.push_back(calpha); - calphaCoords.push_back(FCXXCoord (calpha->x, calpha->y, calpha->z, 1.0f)); + calphaCoords.push_back(FCXXCoord (calpha->x(), calpha->y(), calpha->z(), 1.0f)); anisoValues.push_back(std::make_tuple(1.0f, 1.0f, 1.0f)); } void addCalpha(mmdb::Atom* calpha, float radius){ calphas.push_back(calpha); - calphaCoords.push_back(FCXXCoord (calpha->x, calpha->y, calpha->z, radius)); + calphaCoords.push_back(FCXXCoord (calpha->x(), calpha->y(), calpha->z(), radius)); anisoValues.push_back(std::make_tuple(1.0f, 1.0f, 1.0f)); } void addCalpha(mmdb::Atom* calpha, float ax, float ay, float az){ calphas.push_back(calpha); - calphaCoords.push_back(FCXXCoord (calpha->x, calpha->y, calpha->z, 1.0f)); + calphaCoords.push_back(FCXXCoord (calpha->x(), calpha->y(), calpha->z(), 1.0f)); anisoValues.push_back(std::make_tuple(ax, ay, az)); } std::tuple anisoFor(float xVal) { @@ -72,7 +72,7 @@ class DiscreteSegment { return std::make_tuple(aniso.x(), aniso.y(), aniso.z()); } FCXXCoord operator [] (int i) { - return FCXXCoord (calphas[i]->x, calphas[i]->y, calphas[i]->z); + return FCXXCoord (calphas[i]->x(), calphas[i]->y(), calphas[i]->z()); } int nCalphas() { return int(calphas.size()); diff --git a/MoleculesToTriangles/CXXClasses/FlatFanPrimitive.cpp b/MoleculesToTriangles/CXXClasses/FlatFanPrimitive.cpp index eb42ccb320..cc49cfc9a8 100644 --- a/MoleculesToTriangles/CXXClasses/FlatFanPrimitive.cpp +++ b/MoleculesToTriangles/CXXClasses/FlatFanPrimitive.cpp @@ -40,17 +40,17 @@ void FlatFanPrimitive::generateArrays() int index = 0; for (; iAtomx, atom->y, atom->z); + FCXXCoord atomCoord(atom->x(), atom->y(), atom->z()); centre += atomCoord; size_t lastIAtom = iAtom-1; if (iAtom == 0) lastIAtom = atoms.size()-1; mmdb::Atom* lastAtom = atoms[lastIAtom]; - FCXXCoord lastAtomCoord(lastAtom->x, lastAtom->y, lastAtom->z); + FCXXCoord lastAtomCoord(lastAtom->x(), lastAtom->y(), lastAtom->z()); size_t nextIAtom = iAtom+1; if (nextIAtom == atoms.size()) nextIAtom = 0; mmdb::Atom* nextAtom = atoms[nextIAtom]; - FCXXCoord nextAtomCoord(nextAtom->x, nextAtom->y, nextAtom->z); + FCXXCoord nextAtomCoord(nextAtom->x(), nextAtom->y(), nextAtom->z()); FCXXCoord vecAB(lastAtomCoord-atomCoord); FCXXCoord vecAC(nextAtomCoord-atomCoord); diff --git a/MoleculesToTriangles/CXXClasses/MolecularRepresentation.cpp b/MoleculesToTriangles/CXXClasses/MolecularRepresentation.cpp index f368c7dff8..4f5e98dee7 100644 --- a/MoleculesToTriangles/CXXClasses/MolecularRepresentation.cpp +++ b/MoleculesToTriangles/CXXClasses/MolecularRepresentation.cpp @@ -63,7 +63,7 @@ int MolecularRepresentation::drawSpheres() for (int i=0; icolorForAtom(atom1, handles); - FCXXCoord atom1Coord(atom1->x,atom1->y, atom1->z); + FCXXCoord atom1Coord(atom1->x(),atom1->y(), atom1->z()); float atomRadius = CXXUtils::getAtomRadius(mmdb, atom1) * radiusMultiplier; balls->addBall(atom1Coord, atom1Color, atomRadius); @@ -147,7 +147,7 @@ int MolecularRepresentation::drawBondsAsCylinders() if (atom1->isInSelection(selHnd)){ FCXXCoord atom1Color = colorScheme->colorForAtom(atom1, handles); - FCXXCoord atom1Coord(atom1->x,atom1->y, atom1->z); + FCXXCoord atom1Coord(atom1->x(),atom1->y(), atom1->z()); balls->addBall(atom1Coord, atom1Color, ballRadius); //Because we might be restricted to GL_SHORT_INTs in the index array (don't ask !) @@ -165,21 +165,21 @@ int MolecularRepresentation::drawBondsAsCylinders() int nBondedAtoms; mmdb::AtomBond* bondedAtoms; atom1->GetBonds(bondedAtoms, nBondedAtoms); - FCXXCoord coord1(atom1->x, atom1->y, atom1->z); + FCXXCoord coord1(atom1->x(), atom1->y(), atom1->z()); for (int iOtherAtom = 0; iOtherAtom < nBondedAtoms; iOtherAtom++){ mmdb::Atom* atom2 = bondedAtoms[iOtherAtom].atom; if (atom2->GetIndex()>iAtom && atom2->isInSelection(selHnd)){ //Nasty kludge here...MMDB's MakeBonds screws up where there are multiple conformations bool doContinue = false; - if (!strcmp(atom1->altLoc,"") && - !strcmp(atom2->altLoc,"")) { + if (!strcmp(atom1->altLoc(),"") && + !strcmp(atom2->altLoc(),"")) { doContinue = true; } else { - float dx = atom1->x - atom2->x; - float dy = atom1->y - atom2->y; - float dz = atom1->z - atom2->z; + float dx = atom1->x() - atom2->x(); + float dy = atom1->y() - atom2->y(); + float dz = atom1->z() - atom2->z(); float dist = sqrtf (dx*dx + dy*dy + dz*dz); if (dist < 1.9f) doContinue = true; } @@ -242,8 +242,8 @@ int MolecularRepresentation::drawHydrogenBonds() mmdb::Atom* atom2 = selAtoms[contact.id2]; mmdb::Residue* residue1 = atom1->GetResidue(); mmdb::Residue* residue2 = atom2->GetResidue(); - std::string atom1Name = std::string(atom1->name); - std::string atom2Name = std::string(atom2->name); + std::string atom1Name = std::string(atom1->GetAtomName()); + std::string atom2Name = std::string(atom2->GetAtomName()); #ifdef DEBUG_MINE std::cout << residue1->GetSeqNum() << " [" << atom1Name << "]" << residue2->GetSeqNum() << "[" << atom2Name << "[" << std::string(" N ") << "]\n"; #endif @@ -256,8 +256,8 @@ int MolecularRepresentation::drawHydrogenBonds() (atom1Name.compare(std::string(" O "))==0 && atom2Name.compare(std::string(" N "))==0) ) ){ - FCXXCoord atom1Coord(atom1->x, atom1->y, atom1->z); - FCXXCoord atom2Coord(atom2->x, atom2->y, atom2->z); + FCXXCoord atom1Coord(atom1->x(), atom1->y(), atom1->z()); + FCXXCoord atom2Coord(atom2->x(), atom2->y(), atom2->z()); FCXXCoord diff = atom2Coord - atom1Coord; for (int iStep = 1; iStep < 7; iStep++){ float step = (float)iStep / 8.; @@ -308,15 +308,15 @@ int MolecularRepresentation::drawBondsAsNewSticks() atom2->isInSelection(selHnd)){ //Nasty kludge here...MMDB's MakeBonds screws up where there are multiple conformations - if (!strcmp(atom1->altLoc,"") && - !strcmp(atom2->altLoc,"")) { + if (!strcmp(atom1->altLoc(),"") && + !strcmp(atom2->altLoc(),"")) { sticks->addPair(atom1, atom2); nBonds++; } else { - float dx = atom1->x - atom2->x; - float dy = atom1->y - atom2->y; - float dz = atom1->z - atom2->z; + float dx = atom1->x() - atom2->x(); + float dy = atom1->y() - atom2->y(); + float dz = atom1->z() - atom2->z(); float dist = sqrtf (dx*dx + dy*dy + dz*dz); if (dist < 1.9f) { sticks->addPair(atom1, atom2); @@ -384,7 +384,7 @@ int MolecularRepresentation::drawDishyBases() auto riboseAtomIter = dishyBaseIter->ribose_atoms.begin(); for (; riboseAtomIter!= dishyBaseIter->ribose_atoms.end(); ++ riboseAtomIter){ - FCXXCoord coord((*riboseAtomIter)->x, (*riboseAtomIter)->y, (*riboseAtomIter)->z); + FCXXCoord coord((*riboseAtomIter)->x(), (*riboseAtomIter)->y(), (*riboseAtomIter)->z()); FCXXCoord atomColor = colorScheme->colorForAtom(*riboseAtomIter, handles); balls->addBall(coord, atomColor, ballRadius); if (balls->getBalls().size()%100 == 0){ @@ -403,9 +403,9 @@ int MolecularRepresentation::drawDishyBases() } // Draw a stick from ribose_atoms[1] to 1/3 of the way to // centre. - FCXXCoord atom1Coord(dishyBaseIter->ribose_atoms[1]->x, - dishyBaseIter->ribose_atoms[1]->y, - dishyBaseIter->ribose_atoms[1]->z); + FCXXCoord atom1Coord(dishyBaseIter->ribose_atoms[1]->x(), + dishyBaseIter->ribose_atoms[1]->y(), + dishyBaseIter->ribose_atoms[1]->z()); FCXXCoord basePseudoAtomPosition = atom1Coord + (dishyBaseIter->centre - atom1Coord) / 3.; cylinder->addHalfAtomBondWithCoords(atom1Coord, dishyBaseIter->ribose_atoms[1], atom1Color, basePseudoAtomPosition, dishyBaseIter->ribose_atoms[1], atom1Color, @@ -500,7 +500,7 @@ int MolecularRepresentation::drawStickBases() { FCXXCoord atom1Color = colorScheme->colorForAtom(atom_1, handles); FCXXCoord atom2Color = colorScheme->colorForAtom(atom_2, handles); cylinder->addHalfAtomBond(atom_1, atom1Color, atom_2, atom2Color, cylinderRadius); - FCXXCoord atom1Coord(atom_2->x,atom_2->y, atom_2->z); + FCXXCoord atom1Coord(atom_2->x(),atom_2->y(), atom_2->z()); balls->addBall(atom1Coord, atom1Color, ballRadius); } } diff --git a/MoleculesToTriangles/CXXClasses/MyMolecule.cpp b/MoleculesToTriangles/CXXClasses/MyMolecule.cpp index 521e338922..e02c69f80e 100644 --- a/MoleculesToTriangles/CXXClasses/MyMolecule.cpp +++ b/MoleculesToTriangles/CXXClasses/MyMolecule.cpp @@ -326,13 +326,13 @@ int MyMolecule::identifySegments(std::vector &segments, int s mmdb::Atom* calpha = atomsOfResidue[iAtom]; if (std::string(calpha->segID) == *segIDIter){ //std::cout << calpha->segID << "oops\n"; - if (!strcmp(calpha->name," CA ") && + if (!strcmp(calpha->GetAtomName()," CA ") && calpha->isInSelection(selHnd)){ //Consider only the main alternative location - if (!strcmp(calpha->altLoc,"") || - !strcmp(calpha->altLoc,"A") || - calpha->occupancy > 0.5){ - FCXXCoord calphaPosition(calpha->x, calpha->y, calpha->z); + if (!strcmp(calpha->altLoc(),"") || + !strcmp(calpha->altLoc(),"A") || + calpha->occupancy() > 0.5){ + FCXXCoord calphaPosition(calpha->x(), calpha->y(), calpha->z()); FCXXCoord difference = calphaPosition - lastCoord; float distance = difference.get3DLength(); if (distance > 4.1){ @@ -370,11 +370,11 @@ int MyMolecule::identifySegments(std::vector &segments, int s residue_p->GetAtomTable(residue_atoms, nAtoms); for (int iAtom=0; iAtom < nAtoms; iAtom++){ mmdb::Atom* atom_p = residue_atoms[iAtom]; - std::string atom_name(atom_p->name); + std::string atom_name(atom_p->GetAtomName()); // if (atom_name == " P ") { if (atom_name == " C3'") { if (atom_p->isInSelection(selHnd)) { - FCXXCoord atom_pos(atom_p->x, atom_p->y, atom_p->z); + FCXXCoord atom_pos(atom_p->x(), atom_p->y(), atom_p->z()); FCXXCoord difference = atom_pos - lastCoord; float distance = difference.get3DLength(); // std::cout << "distance " << distance << std::endl; almost all less than 7.5A @@ -475,7 +475,7 @@ int MyMolecule::identifyDishyBases(std::map for (int iAtom=0; iAtom < nAtoms; iAtom++){ mmdb::Atom* atom_p = residue_atoms[iAtom]; if (! atom_p->isTer()) { - std::string atom_alt_conf(atom_p->altLoc); + std::string atom_alt_conf(atom_p->altLoc()); residue_alt_confs_set.insert(atom_alt_conf); } } @@ -503,8 +503,8 @@ int MyMolecule::identifyDishyBases(std::map std::vector ribose_atoms(5,0); for (int iAtom=0; iAtom < nAtoms; iAtom++){ mmdb::Atom* atom_p = residue_atoms[iAtom]; - std::string atom_name(atom_p->name); - std::string atom_alt_conf(atom_p->altLoc); + std::string atom_name(atom_p->GetAtomName()); + std::string atom_alt_conf(atom_p->altLoc()); if (atom_alt_conf.empty() || (residue_alt_confs_set.find(atom_alt_conf) != residue_alt_confs_set.end())) { if (std::find(ref_base_names.begin(), ref_base_names.end(), atom_name) != ref_base_names.end()) { @@ -530,19 +530,19 @@ int MyMolecule::identifyDishyBases(std::map // FCXXCoord ribose_centre; for (std::size_t i=0; i<5; i++) { - FCXXCoord pos(ribose_atoms[i]->x, ribose_atoms[i]->y, ribose_atoms[i]->z); + FCXXCoord pos(ribose_atoms[i]->x(), ribose_atoms[i]->y(), ribose_atoms[i]->z()); ribose_centre += pos; } ribose_centre *= 0.2; FCXXCoord base_centre; for (std::size_t i=0; ix, base_atoms[i]->y, base_atoms[i]->z); + FCXXCoord pos(base_atoms[i]->x(), base_atoms[i]->y(), base_atoms[i]->z()); base_centre += pos; } base_centre /= float(base_atoms.size()); std::vector base_atom_positions(base_atoms.size()); for (unsigned int i=0; ix, base_atoms[i]->y, base_atoms[i]->z); + base_atom_positions[i] = FCXXCoord(base_atoms[i]->x(), base_atoms[i]->y(), base_atoms[i]->z()); DishyPlaneLSQ_t lsq(base_atom_positions); FCXXCoord base_normal = lsq.normal(); DishyBase_t db(base_centre, base_normal, radius, ribose_atoms, ribose_centre); @@ -598,8 +598,8 @@ int MyMolecule::identifyBonds() mmdb::Atom* CA_i = residue->GetAtom("CA", " C", "*"); mmdb::Atom* CA_i_minus_1 = lastResidue->GetAtom("CA", " C", "*"); if (CA_i != 0 && CA_i_minus_1 != 0) { - FCXXCoord Coord_CA_i( CA_i->x, CA_i->y, CA_i->z); - FCXXCoord Coord_CA_i_minus_1( CA_i_minus_1->x, CA_i_minus_1->y, CA_i_minus_1->z); + FCXXCoord Coord_CA_i( CA_i->x(), CA_i->y(), CA_i->z()); + FCXXCoord Coord_CA_i_minus_1( CA_i_minus_1->x(), CA_i_minus_1->y(), CA_i_minus_1->z()); FCXXCoord delta = (Coord_CA_i-Coord_CA_i_minus_1); if(delta.get3DLength()<4.1){ mmdb::Atom* N_i = residue->GetAtom("N", " N", "*"); diff --git a/MoleculesToTriangles/CXXClasses/SecondaryColorScheme.h b/MoleculesToTriangles/CXXClasses/SecondaryColorScheme.h index ab3d033036..2c3673e195 100644 --- a/MoleculesToTriangles/CXXClasses/SecondaryColorScheme.h +++ b/MoleculesToTriangles/CXXClasses/SecondaryColorScheme.h @@ -53,7 +53,7 @@ class SecondaryColorScheme : public ColorScheme { FCXXCoord result = FCXXCoord (1.,1.,1.,0.); std::vector::iterator pair = pairs.begin(); while (pair != pairs.end()){ - if (atom->residue->SSE == pair->getSecondary()){ + if (atom->GetResidue()->SSE == pair->getSecondary()){ result = pair->getColor(); } pair++; diff --git a/MoleculesToTriangles/CXXClasses/SticksPrimitive.cpp b/MoleculesToTriangles/CXXClasses/SticksPrimitive.cpp index aca3e0c11a..dcbcc26c60 100644 --- a/MoleculesToTriangles/CXXClasses/SticksPrimitive.cpp +++ b/MoleculesToTriangles/CXXClasses/SticksPrimitive.cpp @@ -50,7 +50,7 @@ void SticksPrimitive::generateArrays() if (atom1Iter == vcLookup.end()){ FCXXCoord color1 = colorScheme->colorForAtom(atom1, handles); VertexColor vc1 = { - {static_cast(atom1->x), static_cast(atom1->y), static_cast(atom1->z), 0.}, + {static_cast(atom1->x()), static_cast(atom1->y()), static_cast(atom1->z()), 0.}, {static_cast(color1[0]), static_cast(color1[1]), static_cast(color1[2]), static_cast(color1[3])} }; vcLookup[atom1] = vc1; @@ -67,7 +67,7 @@ void SticksPrimitive::generateArrays() if (atom2Iter == vcLookup.end()){ FCXXCoord color2 = colorScheme->colorForAtom(atom2, handles); VertexColor vc2 = { - {static_cast(atom2->x), static_cast(atom2->y), static_cast(atom2->z), 0.}, + {static_cast(atom2->x()), static_cast(atom2->y()), static_cast(atom2->z()), 0.}, {static_cast(color2[0]), static_cast(color2[1]), static_cast(color2[2]), static_cast(color2[3])} }; vcLookup[atom2] = vc2; @@ -102,7 +102,7 @@ void SticksPrimitive::generateArrays() for (; mapIter != mapEnd; ++mapIter){ mmdb::Atom *atom1 = mapIter->first; unsigned long atom1Index = indexLookup[atom1]; - FCXXCoord atom1Coord(atom1->x, atom1->y, atom1->z); + FCXXCoord atom1Coord(atom1->x(), atom1->y(), atom1->z()); FCXXCoord color1 = colorScheme->colorForAtom(atom1, handles); std::vector &bondsOfAtom(mapIter->second); @@ -111,7 +111,7 @@ void SticksPrimitive::generateArrays() for (; vecIter != vecEnd; ++vecIter){ mmdb::Atom *atom2 = *vecIter; unsigned long atom2Index = indexLookup[atom2]; - FCXXCoord atom2Coord(atom2->x, atom2->y, atom2->z); + FCXXCoord atom2Coord(atom2->x(), atom2->y(), atom2->z()); FCXXCoord color2 = colorScheme->colorForAtom(atom2, handles); FCXXCoord midCoord((atom1Coord + atom2Coord) * 0.5); diff --git a/MoleculesToTriangles/CXXSurface/CXXBall.h b/MoleculesToTriangles/CXXSurface/CXXBall.h index c07e760521..1284590cd9 100644 --- a/MoleculesToTriangles/CXXSurface/CXXBall.h +++ b/MoleculesToTriangles/CXXSurface/CXXBall.h @@ -72,7 +72,7 @@ class CXXAtomBall: public CXXBall { static CXXSphereElement unitSphereAtOrigin; public: CXXAtomBall(mmdb::Atom* theAtom_in, const double &radius_in) : theAtom (theAtom_in), theRadius(radius_in){ - theCoord=CXXCoord(theAtom->x, theAtom->y, theAtom->z); + theCoord=CXXCoord(theAtom->x(), theAtom->y(), theAtom->z()); }; virtual const double &getRadius() const{ return theRadius; diff --git a/MoleculesToTriangles/CXXSurface/CXXCircle.cpp b/MoleculesToTriangles/CXXSurface/CXXCircle.cpp index 85950932e9..ec8565c4d7 100644 --- a/MoleculesToTriangles/CXXSurface/CXXCircle.cpp +++ b/MoleculesToTriangles/CXXSurface/CXXCircle.cpp @@ -65,7 +65,7 @@ completelyEaten(0), nodeNumber(0), containsEatenNodes(0) { - centreOfSecondSphere = CXXCoord(theAtomJ->x, theAtomJ->y, theAtomJ->z); + centreOfSecondSphere = CXXCoord(theAtomJ->x(), theAtomJ->y(), theAtomJ->z()); theNormal = centreOfSecondSphere - getCentreOfSphere(); radiusOfSecondSphere = radiusOfAtom2 + probeRadius; diff --git a/MoleculesToTriangles/CXXSurface/CXXCircleNode.cpp b/MoleculesToTriangles/CXXSurface/CXXCircleNode.cpp index 094fac0176..3fc4ce9636 100644 --- a/MoleculesToTriangles/CXXSurface/CXXCircleNode.cpp +++ b/MoleculesToTriangles/CXXSurface/CXXCircleNode.cpp @@ -235,13 +235,13 @@ bool CXXCircleNode::shouldDeletePointer(CXXCircleNode* &aNodePointer){ bool CXXCircleNode::equals(CXXCircleNode &node1, CXXCircleNode &node2){ std::vectorijkCentral(3); std::vectorijkOther(3); - ijkCentral[0] = node1.getAtomI()->serNum; - ijkCentral[1] = node1.getAtomJ()->serNum; - ijkCentral[2] = node1.getAtomK()->serNum; + ijkCentral[0] = node1.getAtomI()->serNum(); + ijkCentral[1] = node1.getAtomJ()->serNum(); + ijkCentral[2] = node1.getAtomK()->serNum(); sort(ijkCentral.begin(), ijkCentral.end()); - ijkOther[0] = node2.getAtomI()->serNum; - ijkOther[1] = node2.getAtomJ()->serNum; - ijkOther[2] = node2.getAtomK()->serNum; + ijkOther[0] = node2.getAtomI()->serNum(); + ijkOther[1] = node2.getAtomJ()->serNum(); + ijkOther[2] = node2.getAtomK()->serNum(); sort(ijkOther.begin(), ijkOther.end()); if (ijkCentral[0] != ijkOther[0]) return false; if (ijkCentral[1] != ijkOther[1]) return false; diff --git a/MoleculesToTriangles/CXXSurface/CXXCreator.cpp b/MoleculesToTriangles/CXXSurface/CXXCreator.cpp index ed1681a5b9..7fdfb8afed 100644 --- a/MoleculesToTriangles/CXXSurface/CXXCreator.cpp +++ b/MoleculesToTriangles/CXXSurface/CXXCreator.cpp @@ -134,9 +134,9 @@ CXXCoordCXXCreator::getAtomCoord(int atomNr) { if(SelAtom){ mmdb::Atom* theAtom = SelAtom[atomNr]; if(theAtom){ - theCoord.setX(theAtom->x); - theCoord.setY(theAtom->y); - theCoord.setZ(theAtom->z); + theCoord.setX(theAtom->x()); + theCoord.setY(theAtom->y()); + theCoord.setZ(theAtom->z()); } } return theCoord; @@ -153,7 +153,7 @@ double CXXCreator::getAtomRadius(int atomNr) { if(SelAtom){ mmdb::Atom* theAtom = SelAtom[atomNr]; if(theAtom){ - radius = mmdb::getVdWaalsRadius(theAtom->element); + radius = mmdb::getVdWaalsRadius(theAtom->GetElementName()); } } return radius; @@ -170,7 +170,7 @@ string CXXCreator::getAtomElement(int atomNr) { } mmdb::Atom* theAtom = SelAtom[atomNr]; - theElement = theAtom->element; + theElement = theAtom->GetElementName(); return theElement; } @@ -184,7 +184,7 @@ string CXXCreator::getAtomName(int atomNr) { throw theException; } mmdb::Atom* theAtom = SelAtom[atomNr]; - theName = theAtom->name; + theName = theAtom->GetAtomName(); return theName; @@ -217,7 +217,7 @@ double CXXCreator::lookUpCharge(int atomNr) { if(SelAtom){ mmdb::Atom* theAtom = SelAtom[atomNr]; if(theAtom){ - theCharge = SelAtom[atomNr]->charge; + theCharge = SelAtom[atomNr]->charge(); } } return theCharge; diff --git a/MoleculesToTriangles/CXXSurface/CXXNewHood.cpp b/MoleculesToTriangles/CXXSurface/CXXNewHood.cpp index 69c5a795f9..aa6430eda7 100644 --- a/MoleculesToTriangles/CXXSurface/CXXNewHood.cpp +++ b/MoleculesToTriangles/CXXSurface/CXXNewHood.cpp @@ -49,7 +49,7 @@ CXXNewHood::CXXNewHood(mmdb::Atom* centralAtom, double radiusOfAtom1, double pro theAtomI(centralAtom), theRadius(radiusOfAtom1+probeRadius), theProbeRadius(probeRadius){ - theCentre = CXXCoord(theAtomI->x, theAtomI->y, theAtomI->z); + theCentre = CXXCoord(theAtomI->x(), theAtomI->y(), theAtomI->z()); } void CXXNewHood::initWith(const CXXCircleNode &aNode, double probeRadius) { @@ -67,12 +67,12 @@ void CXXNewHood::initWith(const CXXBall *aBall){ }; int CXXNewHood::addAtom(mmdb::Atom* anAtomJ, double radiusOfAtom2){ - if (anAtomJ->serNum == theAtomI->serNum) { + if (anAtomJ->serNum() == theAtomI->serNum()) { // std::cout << "Rejecting self " << anAtomJ->serNum << " " << theAtomI->serNum << endl; return 0; //Worried this might not be unique } double radiusOfAtomJ = radiusOfAtom2 + theProbeRadius; - CXXCoordcentreOfAtomJ = CXXCoord(anAtomJ->x, anAtomJ->y, anAtomJ->z); + CXXCoordcentreOfAtomJ = CXXCoord(anAtomJ->x(), anAtomJ->y(), anAtomJ->z()); CXXCoordcentreOfAtomI = theCentre; //This test is to deal with unlikely but possible event of being fed asphere with identical coordinates diff --git a/MoleculesToTriangles/CXXSurface/CXXNewHood.h b/MoleculesToTriangles/CXXSurface/CXXNewHood.h index d3b73ef13c..0add6d08e9 100644 --- a/MoleculesToTriangles/CXXSurface/CXXNewHood.h +++ b/MoleculesToTriangles/CXXSurface/CXXNewHood.h @@ -61,7 +61,7 @@ class CXXNewHood{ theAtomI= atomI; theRadius = radiusOfAtom1 + probeRadius; theProbeRadius = probeRadius; - theCentre = CXXCoord(atomI->x, atomI->y, atomI->z); + theCentre = CXXCoord(atomI->x(), atomI->y(), atomI->z()); }; void initWith(const CXXCircleNode &aNode, double probeRadius); void initWith(const CXXBall *aBall); diff --git a/MoleculesToTriangles/CXXSurface/CXXQADSurface.cpp b/MoleculesToTriangles/CXXSurface/CXXQADSurface.cpp index 84002b24bf..d6ef97ba9e 100644 --- a/MoleculesToTriangles/CXXSurface/CXXQADSurface.cpp +++ b/MoleculesToTriangles/CXXSurface/CXXQADSurface.cpp @@ -143,12 +143,12 @@ int CXXQADSurface::prepareGrids (){ xyzMax[i] = -1e30; } for (int i=0; i< nSelectedAtoms; i++){ - xyzMin[0] = fmin(xyzMin[0], selectedAtoms[i]->x); - xyzMin[1] = fmin(xyzMin[1], selectedAtoms[i]->y); - xyzMin[2] = fmin(xyzMin[2], selectedAtoms[i]->z); - xyzMax[0] = fmax(xyzMax[0], selectedAtoms[i]->x); - xyzMax[1] = fmax(xyzMax[1], selectedAtoms[i]->y); - xyzMax[2] = fmax(xyzMax[2], selectedAtoms[i]->z); + xyzMin[0] = fmin(xyzMin[0], selectedAtoms[i]->x()); + xyzMin[1] = fmin(xyzMin[1], selectedAtoms[i]->y()); + xyzMin[2] = fmin(xyzMin[2], selectedAtoms[i]->z()); + xyzMax[0] = fmax(xyzMax[0], selectedAtoms[i]->x()); + xyzMax[1] = fmax(xyzMax[1], selectedAtoms[i]->y()); + xyzMax[2] = fmax(xyzMax[2], selectedAtoms[i]->z()); } //Expand max and min coordinates by maximum estimated atom radius + probe radius + 1 grid point @@ -211,9 +211,9 @@ int CXXQADSurface::makeDistanceSqMap(){ Grid_range gd (clipperCell, clipperGridSampling, accessibleRadius); - Coord_orth atomCoordOrth(selectedAtoms[iAtom]->x, - selectedAtoms[iAtom]->y, - selectedAtoms[iAtom]->z); + Coord_orth atomCoordOrth(selectedAtoms[iAtom]->x(), + selectedAtoms[iAtom]->y(), + selectedAtoms[iAtom]->z()); Coord_frac uvw = atomCoordOrth.coord_frac( clipperCell); Coord_grid g0 = uvw.coord_grid(clipperGridSampling) + gd.min(); @@ -270,9 +270,9 @@ int CXXQADSurface::addProbesFromVdwSurface(){ for (int iAtom = 0; iAtom < nSelectedAtoms; iAtom++){ double vdwRadius = fastGetAtomRadius(iAtom); - Coord_orth atomCoordOrth(selectedAtoms[iAtom]->x, - selectedAtoms[iAtom]->y, - selectedAtoms[iAtom]->z); + Coord_orth atomCoordOrth(selectedAtoms[iAtom]->x(), + selectedAtoms[iAtom]->y(), + selectedAtoms[iAtom]->z()); Coord_frac uvw = atomCoordOrth.coord_frac( clipperCell); Grid_range gd (clipperCell, clipperGridSampling, vdwRadius); @@ -536,7 +536,7 @@ int CXXQADSurface::coordIsBuriedByNeighbours(Coord_orth &point,int iAtom1){ for (unsigned iAtom2 = 0; iAtom2x, Atom2->y, Atom2->z); + Coord_orth atomCoordOrth(Atom2->x(), Atom2->y(), Atom2->z()); double accessibleRadius = fastGetAtomRadius(iAtom2)+probeRadius; double accessibleRadiusSq = accessibleRadius * accessibleRadius; double dx = point[0] - atomCoordOrth[0]; @@ -824,9 +824,9 @@ double CXXQADSurface::getAtomRadius(mmdb::Atom* theAtom){ double theRadius; if (iRadiusHandle>0){ int success = theAtom->GetUDData (iRadiusHandle, theRadius); - if (success != mmdb::UDDATA_Ok) theRadius = mmdb::getVdWaalsRadius(theAtom->element); + if (success != mmdb::UDDATA_Ok) theRadius = mmdb::getVdWaalsRadius(theAtom->GetElementName()); } - else theRadius = mmdb::getVdWaalsRadius(theAtom->element); + else theRadius = mmdb::getVdWaalsRadius(theAtom->GetElementName()); return theRadius; } @@ -899,7 +899,7 @@ int CXXQADSurface::toruses() for (int atomNr = 0;atomNr < nSelectedAtoms; atomNr++) { mmdb::Atom* centralAtom = selectedAtoms[atomNr]; - Coord_orth atomCoordOrth(centralAtom->x, centralAtom->y, centralAtom->z); + Coord_orth atomCoordOrth(centralAtom->x(), centralAtom->y(), centralAtom->z()); Coord_frac uvw = atomCoordOrth.coord_frac(clipperCell); Grid_range gd (clipperCell, clipperGridSampling, getAtomRadius(centralAtom)+probeRadius); Coord_grid g0 = uvw.coord_grid(clipperGridSampling) + gd.min(); @@ -927,7 +927,7 @@ int CXXQADSurface::toruses() ++circleIter){ CXXCircle &theCircle(*circleIter); - if (centralAtom->serNum < theCircle.getAtomJ()->serNum){ + if (centralAtom->serNum() < theCircle.getAtomJ()->serNum()){ if (theCircle.nSegments()>0){ const CXXCoord&torusCentre(theCircle.getCentreOfCircle()); const CXXCoord&torusAxis(theCircle.getNormal()); @@ -1046,8 +1046,8 @@ int CXXQADSurface::toruses() ++nodeIter){ const CXXCircleNode &aNode(*nodeIter); if (!aNode.isDeleted()){ - if (aNode.getAtomK()->serNum > aNode.getAtomJ()->serNum && - aNode.getAtomJ()->serNum > aNode.getAtomI()->serNum){ + if (aNode.getAtomK()->serNum() > aNode.getAtomJ()->serNum() && + aNode.getAtomJ()->serNum() > aNode.getAtomI()->serNum()){ CXXCoordnodeCXXCoord(aNode.getCoord()); Coord_orth newProbe(nodeCXXCoord[0], nodeCXXCoord[1], nodeCXXCoord[2]); allowProbeToEatWithinGridRange(newProbe, gdAtom); diff --git a/MoleculesToTriangles/CXXSurface/CXXSphereElement.cpp b/MoleculesToTriangles/CXXSurface/CXXSphereElement.cpp index 559945d722..874cddc095 100644 --- a/MoleculesToTriangles/CXXSurface/CXXSphereElement.cpp +++ b/MoleculesToTriangles/CXXSurface/CXXSphereElement.cpp @@ -61,7 +61,7 @@ theAtom(anAtom), deltaRadians(del) { init(); - theCentre = CXXCoord(anAtom->x, anAtom->y, anAtom->z); + theCentre = CXXCoord(anAtom->x(), anAtom->y(), anAtom->z()); calculate(); } @@ -293,9 +293,9 @@ void CXXSphereElement::initWith(const CXXCircleNode &aNode, double delta, mmdb::Atom* atomJ=aNode.getAtomJ(); mmdb::Atom* atomI=aNode.getAtomI(); - CXXCoordu1(atomK->x, atomK->y, atomK->z); - CXXCoordu2(atomJ->x, atomJ->y, atomJ->z); - CXXCoordu3(atomI->x, atomI->y, atomI->z); + CXXCoordu1(atomK->x(), atomK->y(), atomK->z()); + CXXCoordu2(atomJ->x(), atomJ->y(), atomJ->z()); + CXXCoordu3(atomI->x(), atomI->y(), atomI->z()); u1 = u1 - theCentre; u1.normalise(); @@ -349,9 +349,9 @@ void CXXSphereElement::initWith(const CXXCoord&aCentre, mmdb::At deltaRadians=delta; init(); - CXXCoordu1(atomK->x, atomK->y, atomK->z); - CXXCoordu2(atomJ->x, atomJ->y, atomJ->z); - CXXCoordu3(atomI->x, atomI->y, atomI->z); + CXXCoordu1(atomK->x(), atomK->y(), atomK->z()); + CXXCoordu2(atomJ->x(), atomJ->y(), atomJ->z()); + CXXCoordu3(atomI->x(), atomI->y(), atomI->z()); u1 = u1 - theCentre; u1.normalise(); diff --git a/MoleculesToTriangles/CXXSurface/CXXSurface.cpp b/MoleculesToTriangles/CXXSurface/CXXSurface.cpp index 7f9ea7b6e1..d2dfd011f9 100644 --- a/MoleculesToTriangles/CXXSurface/CXXSurface.cpp +++ b/MoleculesToTriangles/CXXSurface/CXXSurface.cpp @@ -465,7 +465,7 @@ int CXXSurface::assignAtom (mmdb::Manager* allAtomsManager_in, int selHnd){ const CXXCoord&vertex = coordRef(vectors["vertices"], i); int j; for (j = 0, minDistSq=1e30; jatom (selAtom[j]->x, selAtom[j]->y, selAtom[j]->z); + CXXCoordatom (selAtom[j]->x(), selAtom[j]->y(), selAtom[j]->z()); CXXCoorddiff = atom - vertex; double dxsq = diff.x() * diff.x(); if (dxsqname[1]){ + switch (theAtom->GetAtomName()[1]){ case 'C': vertices[i].setXyz(vectors["colour"], greenColour); break; diff --git a/MoleculesToTriangles/CXXSurface/CXXSurfaceMaker.cpp b/MoleculesToTriangles/CXXSurface/CXXSurfaceMaker.cpp index 6ceda9d219..c85caad36f 100644 --- a/MoleculesToTriangles/CXXSurface/CXXSurfaceMaker.cpp +++ b/MoleculesToTriangles/CXXSurface/CXXSurfaceMaker.cpp @@ -79,7 +79,7 @@ double CXXSurfaceMaker::getAtomRadius(mmdb::Atom *theAtom) theRadius = 1.8; } else - theRadius = mmdb::getVdWaalsRadius(theAtom->element); + theRadius = mmdb::getVdWaalsRadius(theAtom->GetElementName()); return theRadius; } diff --git a/MoleculesToTriangles/CXXSurface/CXXUtils.cpp b/MoleculesToTriangles/CXXSurface/CXXUtils.cpp index ef8ea45973..a069c2a7ad 100644 --- a/MoleculesToTriangles/CXXSurface/CXXUtils.cpp +++ b/MoleculesToTriangles/CXXSurface/CXXUtils.cpp @@ -33,11 +33,11 @@ int CXXUtils::assignCharge(mmdb::Manager* theManager, int selHnd, CXXChargeTable //Assign atom charges for (int iAtom = 0; iAtom < nSelAtoms; iAtom++) { mmdb::Atom* theAtom = SelAtom[iAtom]; - string atomName(theAtom->name); - string residueName(theAtom->residue->name); + string atomName(theAtom->GetAtomName()); + string residueName(theAtom->GetResidue()->GetResName()); double theAtomCharge; theAtomCharge = theChargeTable->getCharge(residueName, atomName); - theAtom->charge = theAtomCharge; + theAtom->charge() = theAtomCharge; } return 0; } @@ -83,10 +83,10 @@ int CXXUtils::assignUnitedAtomRadius (mmdb::Manager* theManager, int selHnd) { for (int iAtom = 0; iAtom < nSelAtoms; iAtom++) { mmdb::Atom* anAtom = SelAtom[iAtom]; - std::string atomName(anAtom->name); + std::string atomName(anAtom->GetAtomName()); std::string residueName("* "); - if (anAtom->residue != NULL){ - residueName = std::string(anAtom->residue->name); + if (anAtom->GetResidue() != NULL){ + residueName = std::string(anAtom->GetResidue()->GetResName()); } std::map >::iterator residueMapIter = mappedRadii.find(residueName); @@ -114,7 +114,7 @@ double CXXUtils::getAtomRadius(mmdb::Manager* theManager, mmdb::Atom* theAtom){ int success = theAtom->GetUDData (iRadiusHandle, theRadius); if (success != mmdb::UDDATA_Ok) theRadius = 1.8; } - else theRadius = mmdb::getVdWaalsRadius(theAtom->element); + else theRadius = mmdb::getVdWaalsRadius(theAtom->GetElementName()); return theRadius; } @@ -188,7 +188,7 @@ int CXXUtils::unCharge(mmdb::Manager* theManager, int selHnd){ //Assign atom charges for (int iAtom = 0; iAtom < nSelAtoms; iAtom++) { mmdb::Atom* theAtom = SelAtom[iAtom]; - theAtom->charge = 0.; + theAtom->charge() = 0.; } return 0; } diff --git a/analysis/b-factor-histogram.cc b/analysis/b-factor-histogram.cc index 08072366c5..7d56f2dfaf 100644 --- a/analysis/b-factor-histogram.cc +++ b/analysis/b-factor-histogram.cc @@ -45,7 +45,7 @@ coot::b_factor_histogram::b_factor_histogram(mmdb::Manager *mol) { int n_atoms_in_residue = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - const float &b = at->tempFactor; + const float &b = at->tempFactor(); if (b >= 0.0) { n_atoms++; if (b > b_max) { @@ -76,7 +76,7 @@ coot::b_factor_histogram::b_factor_histogram(mmdb::Manager *mol) { int n_atoms_in_residue = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - const float &b = at->tempFactor; + const float &b = at->tempFactor(); if (b >= 0.0) { int bin_idx = b_to_bin(b); b_vector[bin_idx].push_back(b); @@ -100,7 +100,7 @@ coot::b_factor_histogram::b_factor_histogram(mmdb::Manager *mol, int atom_select mol->GetSelIndex(atom_selection_handle, atom_selection, n_selection_atoms); for (int i=0; itempFactor; + const float &b = at->tempFactor(); if (b >= 0.0) { n_atoms++; if (b > b_max) { @@ -115,7 +115,7 @@ coot::b_factor_histogram::b_factor_histogram(mmdb::Manager *mol, int atom_select b_vector.resize(n_bins); for (int i=0; itempFactor; + const float &b = at->tempFactor(); if (b >= 0.0) { int bin_idx = b_to_bin(b); b_vector[bin_idx].push_back(b); diff --git a/analysis/bfkurt.cc b/analysis/bfkurt.cc index 59bad012c3..68be369231 100644 --- a/analysis/bfkurt.cc +++ b/analysis/bfkurt.cc @@ -160,10 +160,10 @@ coot_extras::b_factor_analysis::stats(mmdb::Residue *residue_p) const { residue_p->GetAtomTable(residue_atoms, nResidueAtoms); if (nResidueAtoms > 0) { for (int i=0; ielement; + std::string ele = residue_atoms[i]->GetElementName(); if ((ele != " H") && (ele != " D")) { - bf = residue_atoms[i]->tempFactor; - occ = residue_atoms[i]->occupancy; + bf = residue_atoms[i]->tempFactor(); + occ = residue_atoms[i]->occupancy(); // ignore atoms with silly (or shelx?) B factors and occs if (((bf > 0.0) && (occ >= 0.0) && (occ <= 1.0)) || (is_mol_from_shelx_flag && (occ < 11.001) && (occ>10.999))) { @@ -181,7 +181,7 @@ coot_extras::b_factor_analysis::stats(mmdb::Residue *residue_p) const { } } mmdb::Atom *intel_at = coot::util::intelligent_this_residue_mmdb_atom(residue_p); - my_stats.atom_name = intel_at->name; + my_stats.atom_name = intel_at->GetAtomName(); double div = occ_sum; if (div > 0) { mean = running_sum / div; diff --git a/analysis/cablam.cc b/analysis/cablam.cc index 427b83a27b..52fb148c08 100644 --- a/analysis/cablam.cc +++ b/analysis/cablam.cc @@ -32,9 +32,9 @@ coot::cablam::get_closest_CA_CA_approach(const coot::torsion_atom_quad &quad) co // // get_closest_CA_CA_approach(CA_pos_p, CA_pos_t, O_pos_p); - clipper::Coord_orth CA_p(quad.atom_1->x, quad.atom_1->y, quad.atom_1->z); - clipper::Coord_orth CA_t(quad.atom_2->x, quad.atom_2->y, quad.atom_2->z); - clipper::Coord_orth O_t(quad.atom_4->x, quad.atom_4->y, quad.atom_4->z); + clipper::Coord_orth CA_p(quad.atom_1->x(), quad.atom_1->y(), quad.atom_1->z()); + clipper::Coord_orth CA_t(quad.atom_2->x(), quad.atom_2->y(), quad.atom_2->z()); + clipper::Coord_orth O_t(quad.atom_4->x(), quad.atom_4->y(), quad.atom_4->z()); clipper::Coord_orth PT = CA_t - CA_p; clipper::Coord_orth PT_unit(PT.unit()); @@ -135,11 +135,11 @@ coot::cablam::cablam(mmdb::PResidue *residues, int n_sel_residues) { if (CA_m_2 && CA_m_1 && CA_0 && CA_p_1 && CA_p_2) { - std::string ac_m_2 = CA_m_2->altLoc; - std::string ac_m_1 = CA_m_1->altLoc; - std::string ac_0 = CA_0->altLoc; - std::string ac_p_1 = CA_p_1->altLoc; - std::string ac_p_2 = CA_p_2->altLoc; + std::string ac_m_2 = CA_m_2->altLoc(); + std::string ac_m_1 = CA_m_1->altLoc(); + std::string ac_0 = CA_0->altLoc(); + std::string ac_p_1 = CA_p_1->altLoc(); + std::string ac_p_2 = CA_p_2->altLoc(); if (ac_m_2 == "") { if (ac_m_1 == "") { diff --git a/analysis/daca.cc b/analysis/daca.cc index d1aebf661c..26f945851a 100644 --- a/analysis/daca.cc +++ b/analysis/daca.cc @@ -307,12 +307,12 @@ coot::daca::make_symmetry_typed_atoms(mmdb::Manager *mol, for (int i=0; ix < xmin) xmin = at->x; - if (at->x > xmax) xmax = at->x; - if (at->y < ymin) ymin = at->y; - if (at->y > ymax) ymax = at->y; - if (at->z < zmin) zmin = at->z; - if (at->z > zmax) zmax = at->z; + if (at->x() < xmin) xmin = at->x(); + if (at->x() > xmax) xmax = at->x(); + if (at->y() < ymin) ymin = at->y(); + if (at->y() > ymax) ymax = at->y(); + if (at->z() < zmin) zmin = at->z(); + if (at->z() > zmax) zmax = at->z(); } // Expand bounding box by contact search distance xmin -= expansion_radius; xmax += expansion_radius; @@ -365,9 +365,9 @@ coot::daca::make_symmetry_typed_atoms(mmdb::Manager *mol, if (! at) continue; // Transform the atom position - float tx = mat[0][0]*at->x + mat[0][1]*at->y + mat[0][2]*at->z + mat[0][3]; - float ty = mat[1][0]*at->x + mat[1][1]*at->y + mat[1][2]*at->z + mat[1][3]; - float tz = mat[2][0]*at->x + mat[2][1]*at->y + mat[2][2]*at->z + mat[2][3]; + float tx = mat[0][0]*at->x() + mat[0][1]*at->y() + mat[0][2]*at->z() + mat[0][3]; + float ty = mat[1][0]*at->x() + mat[1][1]*at->y() + mat[1][2]*at->z() + mat[1][3]; + float tz = mat[2][0]*at->x() + mat[2][1]*at->y() + mat[2][2]*at->z() + mat[2][3]; // Quick bounding box test if (tx < xmin || tx > xmax) continue; @@ -377,9 +377,9 @@ coot::daca::make_symmetry_typed_atoms(mmdb::Manager *mol, // This atom is close enough — create a copy with transformed coords mmdb::Atom *new_at = new mmdb::Atom; new_at->Copy(at); - new_at->x = tx; - new_at->y = ty; - new_at->z = tz; + new_at->x() = tx; + new_at->y() = ty; + new_at->z() = tz; new_at->SetResidue(nullptr); // not part of the ASU symm_atom_store_p->push_back(new_at); @@ -597,7 +597,7 @@ coot::daca::get_daca_fragments(mmdb::Residue *reference_residue_p) const { int n_residue_atoms; reference_residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iataltLoc); + std::string alt_loc(residue_atoms[iat]->altLoc()); if (! alt_loc.empty()) { first_alt_conf = alt_loc; break; @@ -617,7 +617,7 @@ coot::daca::get_daca_fragments(mmdb::Residue *reference_residue_p) const { mmdb::Atom *at = residue_atoms[iat]; std::string this_atom_name(at->GetAtomName()); if (atom_name == this_atom_name) { - std::string alt_loc(at->altLoc); + std::string alt_loc(at->altLoc()); if (alt_loc.empty()) { atom_vec.push_back(at); break; @@ -637,7 +637,7 @@ coot::daca::get_daca_fragments(mmdb::Residue *reference_residue_p) const { mmdb::Atom *at = residue_atoms[iat]; std::string this_atom_name(at->GetAtomName()); if (atom_name == this_atom_name) { - std::string alt_loc(at->altLoc); + std::string alt_loc(at->altLoc()); if (alt_loc.empty() || alt_loc == first_alt_conf) { atom_vec.push_back(at); break; @@ -963,9 +963,9 @@ coot::daca::atom_is_close_to_a_residue_atom(mmdb::Atom *at, mmdb::Residue *refer for (int iat=0; iatx - ref_at->x) * (at->x - ref_at->x) + - (at->y - ref_at->y) * (at->y - ref_at->y) + - (at->z - ref_at->z) * (at->z - ref_at->z); + (at->x() - ref_at->x()) * (at->x() - ref_at->x()) + + (at->y() - ref_at->y()) * (at->y() - ref_at->y()) + + (at->z() - ref_at->z()) * (at->z() - ref_at->z()); if (dd < dd_close) { status = true; break; @@ -978,9 +978,9 @@ coot::daca::atom_is_close_to_a_residue_atom(mmdb::Atom *at, mmdb::Residue *refer bool coot::daca::atom_is_neighbour_mainchain(mmdb::Atom *at, mmdb::Residue *reference_residue_p) const { bool status = false; - if (! at->residue) return false; // symmetry atom — not a neighbour - int idx_res_1 = reference_residue_p->index; - int idx_res_2 = at->residue->index; + if (! at->GetResidue()) return false; // symmetry atom — not a neighbour + int idx_res_1 = reference_residue_p->GetIndex(); + int idx_res_2 = at->GetResidue()->GetIndex(); int idx_delta = abs(idx_res_2 - idx_res_1); if (idx_delta < 2) { std::string atom_name(at->GetAtomName()); @@ -1071,23 +1071,23 @@ coot::daca::calculate_daca(mmdb::Residue *reference_residue_p, const std::string &atom_type = typed_atoms[ita].second; // don't consider atoms in this residue, of course - if (at->residue == reference_residue_p) + if (at->GetResidue() == reference_residue_p) continue; // don't consider peptide neighbour mainchain // (symmetry atoms have residue set to nullptr — skip this check for them) - if (at->residue) { - int res_no_delta = at->residue->GetSeqNum() - reference_residue_seqnum; + if (at->GetResidue()) { + int res_no_delta = at->GetResidue()->GetSeqNum() - reference_residue_seqnum; if (std::abs(res_no_delta) < 2) - if (at->residue->chain == reference_residue_p->chain) + if (at->GetResidue()->chain == reference_residue_p->chain) if (is_main_chain_p(at)) continue; } double dd = - (at->x - frag_centre.x()) * (at->x - frag_centre.x()) + - (at->y - frag_centre.y()) * (at->y - frag_centre.y()) + - (at->z - frag_centre.z()) * (at->z - frag_centre.z()); + (at->x() - frag_centre.x()) * (at->x() - frag_centre.x()) + + (at->y() - frag_centre.y()) * (at->y() - frag_centre.y()) + + (at->z() - frag_centre.z()) * (at->z() - frag_centre.z()); if (dd < dd_crit) { // Good, found something if (atom_is_close_to_a_residue_atom(at, reference_residue_p)) { @@ -1620,16 +1620,16 @@ coot::daca::self_test(const std::string &pdb_file_name) { for (unsigned int ita=0; itaresidue == residue_p) continue; - int res_no_delta = at->residue->GetSeqNum() - seqnum; + if (at->GetResidue() == residue_p) continue; + int res_no_delta = at->GetResidue()->GetSeqNum() - seqnum; if (std::abs(res_no_delta) < 2) - if (at->residue->chain == residue_p->chain) + if (at->GetResidue()->chain == residue_p->chain) if (is_main_chain_p(at)) continue; double dd = - (at->x - frag_centre.x()) * (at->x - frag_centre.x()) + - (at->y - frag_centre.y()) * (at->y - frag_centre.y()) + - (at->z - frag_centre.z()) * (at->z - frag_centre.z()); + (at->x() - frag_centre.x()) * (at->x() - frag_centre.x()) + + (at->y() - frag_centre.y()) * (at->y() - frag_centre.y()) + + (at->z() - frag_centre.z()) * (at->z() - frag_centre.z()); if (dd < 64.0) { // 8.0^2 if (atom_is_close_to_a_residue_atom(at, residue_p)) { if (! atom_is_neighbour_mainchain(at, residue_p)) { @@ -1710,9 +1710,9 @@ coot::daca::self_test_perturbed(const std::string &pdb_file_name, float perturba float dx = perturbation * (2.0f * static_cast(rand()) / static_cast(RAND_MAX) - 1.0f); float dy = perturbation * (2.0f * static_cast(rand()) / static_cast(RAND_MAX) - 1.0f); float dz = perturbation * (2.0f * static_cast(rand()) / static_cast(RAND_MAX) - 1.0f); - at->x += dx; - at->y += dy; - at->z += dz; + at->x() += dx; + at->y() += dy; + at->z() += dz; } } @@ -1750,16 +1750,16 @@ coot::daca::self_test_perturbed(const std::string &pdb_file_name, float perturba for (unsigned int ita=0; itaresidue == residue_p) continue; - int res_no_delta = at->residue->GetSeqNum() - seqnum; + if (at->GetResidue() == residue_p) continue; + int res_no_delta = at->GetResidue()->GetSeqNum() - seqnum; if (std::abs(res_no_delta) < 2) - if (at->residue->chain == residue_p->chain) + if (at->GetResidue()->chain == residue_p->chain) if (is_main_chain_p(at)) continue; double dd = - (at->x - frag_centre.x()) * (at->x - frag_centre.x()) + - (at->y - frag_centre.y()) * (at->y - frag_centre.y()) + - (at->z - frag_centre.z()) * (at->z - frag_centre.z()); + (at->x() - frag_centre.x()) * (at->x() - frag_centre.x()) + + (at->y() - frag_centre.y()) * (at->y() - frag_centre.y()) + + (at->z() - frag_centre.z()) * (at->z() - frag_centre.z()); if (dd < 64.0) { // 8.0^2 if (atom_is_close_to_a_residue_atom(at, residue_p)) { if (! atom_is_neighbour_mainchain(at, residue_p)) { @@ -2091,13 +2091,13 @@ coot::daca::solvent_exposure(mmdb::Manager *mol, bool side_chain_only) const { // we could do the selection wthout waters, but also filter out waters this way std::vector is_water(n_atoms, false); for (int iat=0; iatresidue->GetResName()); + std::string rn(atom_selection[iat]->GetResidue()->GetResName()); if (rn == "HOH") is_water[iat] = true; } std::vector radius(n_atoms); for (int iat=0; iatelement); + std::string ele(atom_selection[iat]->GetElementName()); radius[iat] = get_radius(ele); // could be more clever, use atom type. } for (int i=0; iresidue->GetResName()); + std::string rn(at->GetResidue()->GetResName()); if (rn == "HOH") { - std::cout << "HOH " << residue_spec_t(at->residue) + std::cout << "HOH " << residue_spec_t(at->GetResidue()) << " with n-neighbs " << neighbour_atoms.size() << " returning " << count << std::endl; } @@ -2180,7 +2180,7 @@ coot::daca::solvent_exposure(mmdb::Manager *mol, bool side_chain_only) const { n_dots_for_atom = dot_count(atom_index, neighbours, radius[atom_index], atom_selection, unit_sphere_points); - residue_count_map[at->residue] += n_dots_for_atom; + residue_count_map[at->GetResidue()] += n_dots_for_atom; } { @@ -2256,7 +2256,7 @@ coot::daca::solvent_exposure_old_version_v2(mmdb::Manager *mol, mmdb::Residue *residue_p_2 = at_2->GetResidue(); if (residue_p_2 == residue_p_1) continue; std::string res_name_1(residue_p_1->GetResName()); - std::string res_name_2(at_2->residue->GetResName()); + std::string res_name_2(at_2->GetResidue()->GetResName()); if (res_name_1 == "HOH") continue; if (res_name_2 == "HOH") continue; if (! util::is_standard_amino_acid_name(res_name_1)) continue; @@ -2316,7 +2316,7 @@ coot::daca::solvent_exposure_old_version(int SelHnd_in, mmdb::Manager *mol) cons std::vector radius(n_atoms); for (int iat=0; iatelement); + std::string ele(atoms[iat]->GetElementName()); radius[iat] = get_radius(ele); } @@ -2328,9 +2328,9 @@ coot::daca::solvent_exposure_old_version(int SelHnd_in, mmdb::Manager *mol) cons for (int iatom=0; iatomisTer()) { - clipper::Coord_orth centre(atoms[iatom]->x, - atoms[iatom]->y, - atoms[iatom]->z); + clipper::Coord_orth centre(atoms[iatom]->x(), + atoms[iatom]->y(), + atoms[iatom]->z()); bool even = 1; int n_points = 0; int n_sa = 0; @@ -2355,11 +2355,11 @@ coot::daca::solvent_exposure_old_version(int SelHnd_in, mmdb::Manager *mol) cons std::string other_res_name = other_at->GetResName(); if (other_res_name != "HOH") { if (atoms[iatom] != other_at) { - std::string other_ele = other_at->element; + std::string other_ele = other_at->GetElementName(); if (other_ele != " H") { double other_atom_r = fudge * (get_radius(other_ele) + water_radius); double other_atom_r_sq = other_atom_r * other_atom_r; - clipper::Coord_orth pt_other(other_at->x, other_at->y, other_at->z); + clipper::Coord_orth pt_other(other_at->x(), other_at->y(), other_at->z()); if ((pt-pt_other).lengthsq() < other_atom_r_sq) { is_solvent_accessible = 0; break; @@ -2377,7 +2377,7 @@ coot::daca::solvent_exposure_old_version(int SelHnd_in, mmdb::Manager *mol) cons double exposure_frac = double(n_sa)/double(n_points); if (0) - std::cout << "Atom " << atoms[iatom]->name << " has exposure " << n_sa << "/" << n_points + std::cout << "Atom " << atoms[iatom]->GetAtomName() << " has exposure " << n_sa << "/" << n_points << " = " << exposure_frac << std::endl; std::pair p(atoms[iatom], exposure_frac); v.push_back(p); diff --git a/analysis/mogul.cc b/analysis/mogul.cc index 02e558096e..6c2c306c92 100644 --- a/analysis/mogul.cc +++ b/analysis/mogul.cc @@ -387,8 +387,8 @@ coot::mogul::make_restraints(mmdb::Residue *residue_p, int idx_2 = items[i].idx_2 - 1; if (idx_1 >= 0 && idx_1 < n_residue_atoms) { if (idx_2 >= 0 && idx_2 < n_residue_atoms) { - std::string name_1(residue_atoms[idx_1]->name); - std::string name_2(residue_atoms[idx_2]->name); + std::string name_1(residue_atoms[idx_1]->GetAtomName()); + std::string name_2(residue_atoms[idx_2]->GetAtomName()); std::string type; if (current_restraints.first) type = get_bond_type(current_restraints.second, name_1, name_2); @@ -408,9 +408,9 @@ coot::mogul::make_restraints(mmdb::Residue *residue_p, if (idx_1 >= 0 && idx_1 < n_residue_atoms) { if (idx_2 >= 0 && idx_2 < n_residue_atoms) { if (idx_3 >= 0 && idx_3 < n_residue_atoms) { - std::string name_1(residue_atoms[idx_1]->name); - std::string name_2(residue_atoms[idx_2]->name); - std::string name_3(residue_atoms[idx_3]->name); + std::string name_1(residue_atoms[idx_1]->GetAtomName()); + std::string name_2(residue_atoms[idx_2]->GetAtomName()); + std::string name_3(residue_atoms[idx_3]->GetAtomName()); float angle = items[i].median; float esd = items[i].std_dev; dict_angle_restraint_t rest(name_1, name_2, name_3, angle, esd); diff --git a/analysis/typed-distances.cc b/analysis/typed-distances.cc index f7da63b502..a6eae4c594 100644 --- a/analysis/typed-distances.cc +++ b/analysis/typed-distances.cc @@ -186,7 +186,7 @@ coot::typed_distances::atom_type_t coot::typed_distances::get_type(mmdb::Atom *at) const { atom_type_t t1(NONE); - std::string ele(at->element); + std::string ele(at->GetElementName()); if (ele == " C") t1 = atom_type_t(C); if (ele == " O") t1 = atom_type_t(O); if (ele == " S") t1 = atom_type_t(O); diff --git a/api/add-terminal-residue.cc b/api/add-terminal-residue.cc index b0b8586b1b..10b876501b 100644 --- a/api/add-terminal-residue.cc +++ b/api/add-terminal-residue.cc @@ -400,11 +400,11 @@ move_atom(const std::string &atom_name_in, mmdb::Residue *res_p, const clipper:: res_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iname); + std::string atom_name(at->GetAtomName()); if (atom_name == atom_name_in) { - at->x = new_O_pos.x(); - at->y = new_O_pos.y(); - at->z = new_O_pos.z(); + at->x() = new_O_pos.x(); + at->y() = new_O_pos.y(); + at->z() = new_O_pos.z(); done = true; break; } @@ -444,23 +444,23 @@ move_std_residue(mmdb::Residue *moving_residue, const mmdb::Residue *reference_r if (false) std::cout << "DEBUG:: move_std_residue: " << nResidueAtoms << " atoms in residue " - << moving_residue << " " << moving_residue->seqNum << " " + << moving_residue << " " << moving_residue->GetSeqNum() << " " << moving_residue->GetChainID() << std::endl; for (int iat=0; iatx, - residue_atoms[iat]->y, - residue_atoms[iat]->z); - std::string alt_conf = residue_atoms[iat]->altLoc; + clipper::Coord_orth co(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); + std::string alt_conf = residue_atoms[iat]->altLoc(); std::map::const_iterator it = rtops.find(alt_conf); if (it != rtops.end()) { clipper::Coord_orth rotted = co.transform(it->second); // an rtop - residue_atoms[iat]->x = rotted.x(); - residue_atoms[iat]->y = rotted.y(); - residue_atoms[iat]->z = rotted.z(); + residue_atoms[iat]->x() = rotted.x(); + residue_atoms[iat]->y() = rotted.y(); + residue_atoms[iat]->z() = rotted.z(); } } else { istat = 0; @@ -571,7 +571,7 @@ coot::add_side_chain_to_terminal_res(atom_selection_container_t asc, // set the b factor for the new atoms. for(int i=0; itempFactor = b_factor_for_new_atoms; + std_residue_atoms[i]->tempFactor() = b_factor_for_new_atoms; }; bool verb = false; @@ -589,13 +589,13 @@ coot::add_side_chain_to_terminal_res(atom_selection_container_t asc, } for(int i=0; iname); + std::string residue_this_atom (residue_atoms[i]->GetAtomName()); if (residue_this_atom != " O ") residue_p->DeleteAtom(i); }; for(int i=0; iname); + std::string std_residue_this_atom (std_residue_atoms[i]->GetAtomName()); if (std_residue_this_atom != " O ") { // std::cout << "Adding atom " << std_residue_atoms[i] << std::endl; residue_p->AddAtom(std_residue_atoms[i]); @@ -749,16 +749,16 @@ coot::add_terminal_residue(int imol_no, const std::string &terminus_type, mmdb:: mmdb::Residue *res_tmp_p = residue_p; res_tmp_p->GetAtomTable(residue_atoms, nResidueAtoms); for (int i=0; iname) { + if (atom_name == residue_atoms[i]->GetAtomName()) { terminal_at = residue_atoms[i]; break; } if (terminal_at) { mol->SelectSphere(SelHndSphere, mmdb::STYPE_ATOM, - terminal_at->x, - terminal_at->y, - terminal_at->z, + terminal_at->x(), + terminal_at->y(), + terminal_at->z(), radius, mmdb::SKEY_NEW); mol->GetSelIndex(SelHndSphere, atom_sel, n_selected_atoms); @@ -902,7 +902,7 @@ coot::add_terminal_residue(int imol_no, const std::string &terminus_type, mmdb:: if (is_from_shelx_ins) { for (int i=0; ioccupancy = 11.0; + tmp_asc.atom_selection[i]->occupancy() = 11.0; } } diff --git a/api/coot-molecule-bonds-instanced.cc b/api/coot-molecule-bonds-instanced.cc index 531b3dfe9e..b22f69d2fc 100644 --- a/api/coot-molecule-bonds-instanced.cc +++ b/api/coot-molecule-bonds-instanced.cc @@ -242,7 +242,7 @@ make_instanced_graphical_bonds_spherical_atoms(coot::instanced_mesh_t &m, // add if (sar > 0.65) sar = 0.65f; glm::vec3 sc(sar, sar, sar); - glm::vec3 t(at->x, at->y, at->z); + glm::vec3 t(at->x(), at->y(), at->z()); bool atom_is_aniso = at->WhatIsSet & mmdb::ASET_Anis_tFac; // std::cout << " " << coot::atom_spec_t(at) << " atom_is_aniso " << atom_is_aniso << std::endl; @@ -256,9 +256,9 @@ make_instanced_graphical_bonds_spherical_atoms(coot::instanced_mesh_t &m, // add sc = glm::vec3(sar); - GL_matrix mat(at->u11, at->u12, at->u13, - at->u12, at->u22, at->u23, - at->u13, at->u23, at->u33); + GL_matrix mat(at->u11(), at->u12(), at->u13(), + at->u12(), at->u22(), at->u23(), + at->u13(), at->u23(), at->u33()); std::pair chol_pair = mat.eigensystem(); if (chol_pair.first) { @@ -269,7 +269,7 @@ make_instanced_graphical_bonds_spherical_atoms(coot::instanced_mesh_t &m, // add 0.0f, 0.0f, 0.0f, 1.0f); if (false) std::cout << "atom at " << at << " ori:: " << glm::to_string(ori) - << " Us: " << at->u11 << " " << at->u22 << " " << at->u33 << std::endl; + << " Us: " << at->u11() << " " << at->u22() << " " << at->u33() << std::endl; coot::instancing_data_type_B_t idB(t, col, sc, ori); if (render_aniso_atoms_as_ortep) ig_ortep.instancing_data_B.push_back(idB); @@ -377,7 +377,7 @@ make_instanced_graphical_bonds_hemispherical_atoms(coot::instanced_mesh_t &m, // for (unsigned int i=0; ix, at->y, at->z); + glm::vec3 t(at->x(), at->y(), at->z()); glm::mat4 ori(1.0); // 20230114-PE needs fixing. float scale = 1.0; if (at_info.is_hydrogen_atom) scale *= 0.5; @@ -422,7 +422,7 @@ void make_graphical_bonds_spherical_atoms_with_vdw_radii_instanced(coot::instanc for (unsigned int i=0; ielement); + std::string ele(at->GetElementName()); std::map::const_iterator it = ele_to_radius_map.find(ele); float atom_radius = 1.0; if (it != ele_to_radius_map.end()) { @@ -434,7 +434,7 @@ void make_graphical_bonds_spherical_atoms_with_vdw_radii_instanced(coot::instanc ele_to_radius_map[ele] = atom_radius; } - glm::vec3 t(at->x, at->y, at->z); + glm::vec3 t(at->x(), at->y(), at->z()); glm::vec3 sc(atom_radius, atom_radius, atom_radius); coot::instancing_data_type_A_t id(t, col, sc); ig.instancing_data_A.push_back(id); diff --git a/api/coot-molecule-bonds.cc b/api/coot-molecule-bonds.cc index 11c0e03eea..9f48d645df 100644 --- a/api/coot-molecule-bonds.cc +++ b/api/coot-molecule-bonds.cc @@ -155,7 +155,7 @@ coot::molecule_t::apply_user_defined_atom_colour_selections(const std::vector 0) { for(int iat=0; iatelement); + std::string element(at->GetElementName()); if (element == " C" || colour_applies_to_non_carbon_atoms_also) { int ierr = at->PutUDData(udd_handle, colour_index); if (ierr != mmdb::UDDATA_Ok) { @@ -201,7 +201,7 @@ coot::molecule_t::add_to_non_drawn_bonds(const std::string &atom_selection_cid) if (nSelAtoms > 0) { for(int iat=0; iatresidue); + selected_residues.insert(at->GetResidue()); } } atom_sel.mol->DeleteSelection(selHnd); @@ -569,7 +569,7 @@ void make_graphical_bonds_spherical_atoms_with_vdw_radii(coot::simple_mesh_t &m, for (unsigned int i=0; ielement); + std::string ele(at->GetElementName()); std::map::const_iterator it = ele_to_radius_map.find(ele); float atom_radius = 1.0; if (it != ele_to_radius_map.end()) { @@ -581,7 +581,7 @@ void make_graphical_bonds_spherical_atoms_with_vdw_radii(coot::simple_mesh_t &m, ele_to_radius_map[ele] = atom_radius; } - glm::vec3 t(at->x, at->y, at->z); + glm::vec3 t(at->x(), at->y(), at->z()); glm::vec3 sc(atom_radius, atom_radius, atom_radius); std::vector local_vertices(octosphere_geom.first.size()); @@ -750,7 +750,7 @@ make_graphical_bonds_hemispherical_atoms(coot::simple_mesh_t &m, // fill m mmdb::Atom *other_at = index_to_atom[other_atom_index]; if (other_at) { // std::cout << " other_at " << other_at << " " << coot::atom_spec_t(other_at) << std::endl; - glm::vec3 other_atom_pos(other_at->x, other_at->y, other_at->z); + glm::vec3 other_atom_pos(other_at->x(), other_at->y(), other_at->z()); glm::mat4 mm = get_octahemi_matrix(t, other_atom_pos, bond_radius); // a rotation matrix std::vector local_vertices(octasphere_geom.first.size()); @@ -1920,7 +1920,7 @@ coot::molecule_t::get_simple_molecule(int imol, mmdb::Residue *residue_p, bool d const graphical_bonds_atom_info_t &at_info = gbc.consolidated_atom_centres[icol].points[i]; int fc = 0; bool arom = false; - sm.add_atom(simple::atom_t(at_info.atom_p->GetAtomName(), at_info.atom_p->element, at_info.position, fc, arom)); + sm.add_atom(simple::atom_t(at_info.atom_p->GetAtomName(), at_info.atom_p->GetElementName(), at_info.position, fc, arom)); } } diff --git a/api/coot-molecule-json.cc b/api/coot-molecule-json.cc index 0c269767aa..705c7caeb7 100644 --- a/api/coot-molecule-json.cc +++ b/api/coot-molecule-json.cc @@ -13,13 +13,13 @@ std::string coot::molecule_t::get_molecule_selection_as_json(const std::string & auto atom_to_json = [] (mmdb::Atom *at) { nlohmann::json j; // 2025-10-10-PE add more attributes later - std::string se = util::remove_whitespace(std::string(at->element)); - std::string sn = util::remove_whitespace(std::string(at->name)); - j["x"] = at->x; - j["y"] = at->y; - j["z"] = at->z; - j["tempFactor"] = at->tempFactor; - j["occupancy"] = at->occupancy; + std::string se = util::remove_whitespace(std::string(at->GetElementName())); + std::string sn = util::remove_whitespace(std::string(at->GetAtomName())); + j["x"] = at->x(); + j["y"] = at->y(); + j["z"] = at->z(); + j["tempFactor"] = at->tempFactor(); + j["occupancy"] = at->occupancy(); j["name"] = sn; j["element"] = se; return j; @@ -100,7 +100,7 @@ coot::molecule_t::get_torsions_for_residues_in_chain_as_json(const std::string & for (int i=0; iGetAtom(i); if (at->isTer()) continue; - if (std::string(at->altLoc) != "") + if (std::string(at->altLoc()) != "") return true; } return false; @@ -111,8 +111,8 @@ coot::molecule_t::get_torsions_for_residues_in_chain_as_json(const std::string & for (int i=0; iGetAtom(i); if (!at->isTer()) { - if (std::string(at->name) == name) - return {true, clipper::Coord_orth(at->x, at->y, at->z)}; + if (std::string(at->GetAtomName()) == name) + return {true, clipper::Coord_orth(at->x(), at->y(), at->z())}; } } return {false, clipper::Coord_orth()}; diff --git a/api/coot-molecule-maps.cc b/api/coot-molecule-maps.cc index f4ab346553..15f515be0e 100644 --- a/api/coot-molecule-maps.cc +++ b/api/coot-molecule-maps.cc @@ -1238,9 +1238,9 @@ coot::molecule_t::fit_to_map_by_random_jiggle(mmdb::PPAtom atom_selection, // do it lots of times in jiggle_atoms. Inefficient. std::vector p(3, 0.0); for (int iat=0; iatx; - p[1] += atom_selection[iat]->y; - p[2] += atom_selection[iat]->z; + p[0] += atom_selection[iat]->x(); + p[1] += atom_selection[iat]->y(); + p[2] += atom_selection[iat]->z(); } double fact = 1.0; if (n_atoms) @@ -1526,7 +1526,7 @@ coot::molecule_t::fit_to_map_by_random_jiggle(mmdb::PPAtom atom_selection, for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - clipper::Coord_orth pt(at->x, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); float d = coot::util::density_at_point(xmap, pt); std::cout << coot::atom_spec_t(at) << " " << d << std::endl; } @@ -1589,9 +1589,9 @@ coot::molecule_t::fit_to_map_by_random_jiggle(mmdb::PPAtom atom_selection, coot::util::transform_chain(chains_for_moving[ich], bias_rtop); } else { for (int iat=0; iatx += bias.x(); - atom_selection[iat]->y += bias.y(); - atom_selection[iat]->z += bias.z(); + atom_selection[iat]->x() += bias.x(); + atom_selection[iat]->y() += bias.y(); + atom_selection[iat]->z() += bias.z(); } } } else { diff --git a/api/coot-molecule-merge-molecules.cc b/api/coot-molecule-merge-molecules.cc index 78cd07a01e..bea7927865 100644 --- a/api/coot-molecule-merge-molecules.cc +++ b/api/coot-molecule-merge-molecules.cc @@ -246,7 +246,7 @@ coot::molecule_t::merge_molecules_just_one_residue_homogeneous(atom_selection_co std::vector r = coot::util::residue_types_in_chain(this_chain_p); if (r.size() == 1) { - std::string adding_model_resname(molecule_to_add.atom_selection[0]->residue->GetResName()); + std::string adding_model_resname(molecule_to_add.atom_selection[0]->GetResidue()->GetResName()); if (r[0] == adding_model_resname) { // poly-ala helices (say) should not go into concatenated residues in the same chain if (adding_model_resname != "ALA") { @@ -260,7 +260,7 @@ coot::molecule_t::merge_molecules_just_one_residue_homogeneous(atom_selection_co if (has_single_residue_type_chain_flag) { if (molecule_to_add.n_selected_atoms > 0) { - mmdb::Residue *add_model_residue = molecule_to_add.atom_selection[0]->residue; + mmdb::Residue *add_model_residue = molecule_to_add.atom_selection[0]->GetResidue(); copy_and_add_residue_to_chain(add_residue_to_this_chain, add_model_residue); done_homogeneous_addition_flag = true; atom_sel.mol->FinishStructEdit(); @@ -301,7 +301,7 @@ coot::molecule_t::merge_molecules_just_one_residue_at_given_spec(atom_selection_ if (r) { make_backup("merge_molecules_just_one_residue_at_given_spec"); mmdb::Residue *new_residue_p = copy_and_add_residue_to_chain(this_chain_p, r); - new_residue_p->seqNum = target_spec.res_no; + new_residue_p->GetSeqNum() = target_spec.res_no; status = true; } } else { @@ -369,7 +369,7 @@ coot::molecule_t::copy_and_add_residue_to_chain(mmdb::Chain *this_model_chain, int new_res_resno = 9999; if (res_info.first) new_res_resno = res_info.second; - residue_copy->seqNum = new_res_resno; // try changing the seqNum before AddResidue(). + residue_copy->GetSeqNum() = new_res_resno; // try changing the seqNum before AddResidue(). this_model_chain->AddResidue(residue_copy); res_copied = residue_copy; } @@ -597,11 +597,11 @@ coot::molecule_t::next_residue_number_in_chain(mmdb::Chain *w, if (nres > 0) { for (int ires=nres-1; ires>=0; ires--) { residue_p = w->GetResidue(ires); - if (residue_p->seqNum > max_res_no) { - max_res_no = residue_p->seqNum; + if (residue_p->GetSeqNum() > max_res_no) { + max_res_no = residue_p->GetSeqNum(); bool is_het_residue_flag = is_het_residue(residue_p); if (is_het_residue_flag) { - p = std::pair(1, residue_p->seqNum+1); + p = std::pair(1, residue_p->GetSeqNum()+1); } else { if (new_res_no_by_hundreds) { if (max_res_no < 9999) { @@ -623,7 +623,7 @@ coot::molecule_t::next_residue_number_in_chain(mmdb::Chain *w, while (! is_clear) { is_clear = true; for (int iser=0; iserGetResidue(iser)->seqNum; + int resno_res = w->GetResidue(iser)->GetSeqNum(); if (resno_res >= test_resno_start) { if (resno_res <= (test_resno_start+10)) { is_clear = false; diff --git a/api/coot-molecule-modelling.cc b/api/coot-molecule-modelling.cc index feba8fd6a4..7faa900a50 100644 --- a/api/coot-molecule-modelling.cc +++ b/api/coot-molecule-modelling.cc @@ -201,7 +201,7 @@ coot::molecule_t::execute_simple_nucleotide_addition(const std::string &term_typ if (rtop_pair.first) { // fix up the residue number and chain id to match the clicked atom int new_resno = res_p->GetSeqNum() + interesting_resno - match_resno; - interesting_residue_p->seqNum = new_resno; + interesting_residue_p->GetSeqNum() = new_resno; // we always want to remove OP3 from the residue to which a new residue // is added when we add to the "N-terminus" @@ -214,7 +214,7 @@ coot::molecule_t::execute_simple_nucleotide_addition(const std::string &term_typ for (int iat=0; iatname); + std::string at_name(at->GetAtomName()); if (at_name == " OP3") { // PDBv3 FIXME delete at; at = NULL; diff --git a/api/coot-molecule-refine.cc b/api/coot-molecule-refine.cc index 611a7842d9..bce2e1ad3e 100644 --- a/api/coot-molecule-refine.cc +++ b/api/coot-molecule-refine.cc @@ -159,16 +159,16 @@ coot::molecule_t::generate_local_self_restraints(int selHnd, float local_dist_ma mmdb::Atom *at_1 = SelAtom[pscontact[i].id1]; mmdb::Atom *at_2 = SelAtom[pscontact[i].id2]; - std::string ele_1 = at_1->element; - std::string ele_2 = at_2->element; + std::string ele_1 = at_1->GetElementName(); + std::string ele_2 = at_2->GetElementName(); if (ele_1 != " H" && ele_2 != " H") { bool ignore_this = false; // set for bonded and angled atoms bool in_same_res = false; - if (at_1->residue == at_2->residue) + if (at_1->GetResidue() == at_2->GetResidue()) in_same_res = true; if (in_same_res) { - std::string comp_id = at_1->residue->GetResName(); + std::string comp_id = at_1->GetResidue()->GetResName(); std::string at_name_1 = at_1->GetAtomName(); std::string at_name_2 = at_2->GetAtomName(); diff --git a/api/coot-molecule-replace-fragment.cc b/api/coot-molecule-replace-fragment.cc index 89e9ad82fa..e47506c368 100644 --- a/api/coot-molecule-replace-fragment.cc +++ b/api/coot-molecule-replace-fragment.cc @@ -132,9 +132,9 @@ coot::molecule_t::replace_fragment(atom_selection_container_t asc) { if (idx != -1) { mmdb::Atom *ref_atom = atom_sel.atom_selection[idx]; - ref_atom->x = at->x; - ref_atom->y = at->y; - ref_atom->z = at->z; + ref_atom->x() = at->x(); + ref_atom->y() = at->y(); + ref_atom->z() = at->z(); } else { @@ -149,8 +149,8 @@ coot::molecule_t::replace_fragment(atom_selection_container_t asc) { mmdb::Chain *chain_p = new mmdb::Chain; chain_p->SetChainID(at->GetChainID()); residue_p = new mmdb::Residue; - residue_p->seqNum = at->GetSeqNum(); - residue_p->SetResName(at->residue->GetResName()); + residue_p->GetSeqNum() = at->GetSeqNum(); + residue_p->SetResName(at->GetResidue()->GetResName()); chain_p->AddResidue(residue_p); model_p->AddChain(chain_p); atom_sel.mol->PDBCleanup(mmdb::PDBCLEAN_SERIAL|mmdb::PDBCLEAN_INDEX); @@ -161,7 +161,7 @@ coot::molecule_t::replace_fragment(atom_selection_container_t asc) { // std::cout << " ======= found the residue " << std::endl; } else { residue_p = new mmdb::Residue; - residue_p->SetResID(at->residue->GetResName(), at->residue->seqNum, at->residue->insCode); + residue_p->SetResID(at->GetResidue()->GetResName(), at->GetResidue()->GetSeqNum(), at->GetResidue()->GetInsCode()); int res_no = at->GetSeqNum(); std::string ins_code(at->GetInsCode()); std::pair sn = @@ -225,9 +225,9 @@ coot::molecule_t::replace_fragment(mmdb::Manager *mol_ref, int old_atom_index_ha if (ierr == mmdb::UDDATA_Ok) { mmdb::Atom *at = atom_sel.atom_selection[idx]; // std::cout << "replacing position of " << atom_spec_t(at) << " from " << atom_spec_t(at_frag) << std::endl; - at->x = at_frag->x; - at->y = at_frag->y; - at->z = at_frag->z; + at->x() = at_frag->x(); + at->y() = at_frag->y(); + at->z() = at_frag->z(); status = 1; // at least one atom was found } else { std::cout << "GetUDData() failed for " << coot::atom_spec_t(at_frag) << " " << old_atom_index_handle << std::endl; diff --git a/api/coot-molecule-validation.cc b/api/coot-molecule-validation.cc index 2a70557477..23eac762aa 100644 --- a/api/coot-molecule-validation.cc +++ b/api/coot-molecule-validation.cc @@ -736,8 +736,8 @@ coot::molecule_t::get_mesh_for_ligand_validation_vs_dictionary(const std::string mmdb::Atom *at_1 = residue_p->GetAtom(rest.atom_index_1); mmdb::Atom *at_2 = residue_p->GetAtom(rest.atom_index_2); if (at_1 && at_2) { - clipper::Coord_orth p1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth p2(at_2->x, at_2->y, at_2->z); + clipper::Coord_orth p1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth p2(at_2->x(), at_2->y(), at_2->z()); double d = sqrt((p2-p1).lengthsq()); double distortion = d - rest.target_value; double pen_score = fabs(distortion/rest.sigma); @@ -764,9 +764,9 @@ coot::molecule_t::get_mesh_for_ligand_validation_vs_dictionary(const std::string mmdb::Atom *at_2 = residue_p->GetAtom(rest.atom_index_2); mmdb::Atom *at_3 = residue_p->GetAtom(rest.atom_index_3); if (at_1 && at_2 && at_3) { - clipper::Coord_orth p1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth p2(at_2->x, at_2->y, at_2->z); - clipper::Coord_orth p3(at_3->x, at_3->y, at_3->z); + clipper::Coord_orth p1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth p2(at_2->x(), at_2->y(), at_2->z()); + clipper::Coord_orth p3(at_3->x(), at_3->y(), at_3->z()); double angle_rad = clipper::Coord_orth::angle(p1, p2, p3); double angle = clipper::Util::rad2d(angle_rad); double distortion = fabs(angle - rest.target_value); @@ -794,10 +794,10 @@ coot::molecule_t::get_mesh_for_ligand_validation_vs_dictionary(const std::string mmdb::Atom *at_2 = residue_p->GetAtom(rest.atom_index_2); mmdb::Atom *at_3 = residue_p->GetAtom(rest.atom_index_3); if (at_c && at_1 && at_2 && at_3) { - clipper::Coord_orth pc(at_c->x, at_c->y, at_c->z); - clipper::Coord_orth p1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth p2(at_2->x, at_2->y, at_2->z); - clipper::Coord_orth p3(at_3->x, at_3->y, at_3->z); + clipper::Coord_orth pc(at_c->x(), at_c->y(), at_c->z()); + clipper::Coord_orth p1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth p2(at_2->x(), at_2->y(), at_2->z()); + clipper::Coord_orth p3(at_3->x(), at_3->y(), at_3->z()); clipper::Coord_orth bl_1 = 0.6 * pc + 0.4 * p1; clipper::Coord_orth bl_2 = 0.6 * pc + 0.4 * p2; clipper::Coord_orth bl_3 = 0.6 * pc + 0.4 * p3; @@ -825,7 +825,7 @@ coot::molecule_t::get_mesh_for_ligand_validation_vs_dictionary(const std::string mmdb::Atom *at_4th = coot::chiral_4th_atom(residue_p, at_c, at_1, at_2, at_3); if (at_4th) { std::cout << " " << coot::atom_spec_t(at_4th) << std::endl; - clipper::Coord_orth p4(at_4th->x, at_4th->y, at_4th->z); + clipper::Coord_orth p4(at_4th->x(), at_4th->y(), at_4th->z()); clipper::Coord_orth bl_4 = 0.6 * pc + 0.4 * p4; add_chiral_lines(obj, bl_1, bl_2, bl_3, bl_4, line_radius, col, n_slices); // add to obj } else { @@ -1093,9 +1093,9 @@ coot::molecule_t::get_distances_between_atoms_of_residues(const std::string &cid for (int jj=0; jjx - at_1->x) * (at_2->x - at_1->x) + - (at_2->y - at_1->y) * (at_2->y - at_1->y) + - (at_2->z - at_1->z) * (at_2->z - at_1->z); + (at_2->x() - at_1->x()) * (at_2->x() - at_1->x()) + + (at_2->y() - at_1->y()) * (at_2->y() - at_1->y()) + + (at_2->z() - at_1->z()) * (at_2->z() - at_1->z()); double d = std::sqrt(dd); if (d < dist_max) { atom_spec_t spec_1(at_1); diff --git a/api/coot-molecule.cc b/api/coot-molecule.cc index dfaebedbc8..f3d50cd3c4 100644 --- a/api/coot-molecule.cc +++ b/api/coot-molecule.cc @@ -344,7 +344,7 @@ coot::molecule_t::get_number_of_hydrogen_atoms() const { int n_atoms = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - std::string ele(at->element); + std::string ele(at->GetElementName()); if (ele == " H") { if (! at->isTer()) { n++; @@ -571,16 +571,16 @@ coot::molecule_t::transform_by(mmdb::mat44 mat) { } for (int i=0; ix, at->y, at->z); + co = clipper::Coord_orth(at->x(), at->y(), at->z()); trans_pos = co.transform(rtop); - at->x = trans_pos.x(); - at->y = trans_pos.y(); - at->z = trans_pos.z(); + at->x() = trans_pos.x(); + at->y() = trans_pos.y(); + at->z() = trans_pos.z(); if (false) // debugging if (co.x() < 0.0 && co.x() > -10.0) if (co.y() < 20.0 && co.y() > 10.0) if (co.z() < 30.0 && co.z() > 20.0) - std::cout << i << " from " << co.format() << " to " << at->x << " " << at->y << " " << at->z << std::endl; + std::cout << i << " from " << co.format() << " to " << at->x() << " " << at->y() << " " << at->z() << std::endl; } atom_sel.mol->PDBCleanup(mmdb::PDBCLEAN_SERIAL|mmdb::PDBCLEAN_INDEX); atom_sel.mol->FinishStructEdit(); @@ -794,15 +794,15 @@ coot::molecule_t::moving_atom_matches(mmdb::Atom *at, int this_mol_index_maybe) if (this_mol_index_maybe >= atom_sel.n_selected_atoms) { return false; } else { - std::string atom_name_mov = at->name; + std::string atom_name_mov = at->GetAtomName(); std::string ins_code_mov = at->GetInsCode(); - std::string alt_conf_mov = at->altLoc; + std::string alt_conf_mov = at->altLoc(); std::string chain_id_mov = at->GetChainID(); int resno_mov = at->GetSeqNum(); - std::string atom_name_ref = atom_sel.atom_selection[this_mol_index_maybe]->name; + std::string atom_name_ref = atom_sel.atom_selection[this_mol_index_maybe]->GetAtomName(); std::string ins_code_ref = atom_sel.atom_selection[this_mol_index_maybe]->GetInsCode(); - std::string alt_conf_ref = atom_sel.atom_selection[this_mol_index_maybe]->altLoc; + std::string alt_conf_ref = atom_sel.atom_selection[this_mol_index_maybe]->altLoc(); std::string chain_id_ref = atom_sel.atom_selection[this_mol_index_maybe]->GetChainID(); int resno_ref = atom_sel.atom_selection[this_mol_index_maybe]->GetSeqNum(); @@ -913,10 +913,10 @@ coot::molecule_t::full_atom_spec_to_atom_index(const std::string &chain, // the wildcard atom selection case "*HO2" for (int i=0; iGetChainID()) == chain) { - if (local_SelAtom[i]->residue->seqNum == resno) { + if (local_SelAtom[i]->GetResidue()->GetSeqNum() == resno) { if (std::string(local_SelAtom[i]->GetInsCode()) == insertion_code) { - if (std::string(local_SelAtom[i]->name) == atom_name) { - if (std::string(local_SelAtom[i]->altLoc) == alt_conf) { + if (std::string(local_SelAtom[i]->GetAtomName()) == atom_name) { + if (std::string(local_SelAtom[i]->altLoc()) == alt_conf) { idx = i; break; } @@ -955,8 +955,8 @@ coot::molecule_t::movable_atom(mmdb::Atom *mol_atom, bool replace_coords_with_ze bool m = true; - if ((mol_atom->occupancy < 0.0001) && - (mol_atom->occupancy > -0.0001)) + if ((mol_atom->occupancy() < 0.0001) && + (mol_atom->occupancy() > -0.0001)) if (replace_coords_with_zero_occ_flag == 0) m = 0; // zero occupancy and "dont move zero occ atoms is set" return m; @@ -979,18 +979,18 @@ coot::molecule_t::adjust_occupancy_other_residue_atoms(mmdb::Atom *at, int nResidueAtoms; mmdb::PPAtom ResidueAtoms = 0; residue->GetAtomTable(ResidueAtoms, nResidueAtoms); - float new_atom_occ = at->occupancy; - std::string new_atom_name(at->name); - std::string new_atom_altconf(at->altLoc); + float new_atom_occ = at->occupancy(); + std::string new_atom_name(at->GetAtomName()); + std::string new_atom_altconf(at->altLoc()); std::vector same_name_atoms; float sum_occ = 0; for (int i=0; iname); - std::string this_atom_altloc(ResidueAtoms[i]->altLoc); + std::string this_atom_name(ResidueAtoms[i]->GetAtomName()); + std::string this_atom_altloc(ResidueAtoms[i]->altLoc()); if (this_atom_name == new_atom_name) { if (this_atom_altloc != new_atom_altconf) { same_name_atoms.push_back(ResidueAtoms[i]); - sum_occ += ResidueAtoms[i]->occupancy; + sum_occ += ResidueAtoms[i]->occupancy(); } } } @@ -1000,16 +1000,16 @@ coot::molecule_t::adjust_occupancy_other_residue_atoms(mmdb::Atom *at, if (same_name_atoms.size() > 0) { float other_atom_occ_sum = 0.0; for (unsigned int i=0; ioccupancy; + other_atom_occ_sum += same_name_atoms[i]->occupancy(); float remainder = 1.0 - new_atom_occ; float f = remainder/other_atom_occ_sum; for (unsigned int i=0; ioccupancy + << " mulitplying occ " << same_name_atoms[i]->occupancy() << " by " << remainder << "/" << other_atom_occ_sum << "\n"; - same_name_atoms[i]->occupancy *= f; + same_name_atoms[i]->occupancy() *= f; } } } @@ -1050,12 +1050,12 @@ coot::molecule_t::replace_coords(const atom_selection_container_t &asc, bool is_ter_state = atom->isTer(); std::cout << "DEBUG:: in replace_coords, intermediate atom: " << i << " " << atom << " " << "chain-id: " - << atom->residue->GetChainID() << ": " - << atom->residue->seqNum << " inscode \"" + << atom->GetResidue()->GetChainID() << ": " + << atom->GetResidue()->GetSeqNum() << " inscode \"" << atom->GetInsCode() << "\" name \"" - << atom->name << "\" altloc \"" - << atom->altLoc << "\" occupancy: " - << atom->occupancy << " :" + << atom->GetAtomName() << "\" altloc \"" + << atom->altLoc() << "\" occupancy: " + << atom->occupancy() << " :" << " TER state: " << is_ter_state << std::endl; } } @@ -1099,21 +1099,21 @@ coot::molecule_t::replace_coords(const atom_selection_container_t &asc, idx = tmp_index; } else { // std::cout << "DEBUG:: atom index mismatch" << std::endl; - idx = full_atom_spec_to_atom_index(std::string(atom->residue->GetChainID()), - atom->residue->seqNum, + idx = full_atom_spec_to_atom_index(std::string(atom->GetResidue()->GetChainID()), + atom->GetResidue()->GetSeqNum(), std::string(atom->GetInsCode()), - std::string(atom->name), - std::string(atom->altLoc)); + std::string(atom->GetAtomName()), + std::string(atom->altLoc())); // std::cout << "DEBUG:: full_atom_spec_to_atom_index gives index: " << idx << std::endl; } } else { // This shouldn't happen. std::cout << "Good Handle, bad index found for old atom: specing" << std::endl; - idx = full_atom_spec_to_atom_index(std::string(atom->residue->GetChainID()), - atom->residue->seqNum, + idx = full_atom_spec_to_atom_index(std::string(atom->GetResidue()->GetChainID()), + atom->GetResidue()->GetSeqNum(), std::string(atom->GetInsCode()), - std::string(atom->name), - std::string(atom->altLoc)); + std::string(atom->GetAtomName()), + std::string(atom->altLoc())); } } else { @@ -1128,11 +1128,11 @@ coot::molecule_t::replace_coords(const atom_selection_container_t &asc, << asc.UDDOldAtomIndexHandle << " using full atom spec to atom index..." << std::endl; - idx = full_atom_spec_to_atom_index(std::string(atom->residue->GetChainID()), - atom->residue->seqNum, + idx = full_atom_spec_to_atom_index(std::string(atom->GetResidue()->GetChainID()), + atom->GetResidue()->GetSeqNum(), std::string(atom->GetInsCode()), - std::string(atom->name), - std::string(atom->altLoc)); + std::string(atom->GetAtomName()), + std::string(atom->altLoc())); std::cout << "full_atom_spec_to_atom_index() returned " << idx << " for " << coot::atom_spec_t(atom) << std::endl; if (idx != -1) { @@ -1143,11 +1143,11 @@ coot::molecule_t::replace_coords(const atom_selection_container_t &asc, if (idx == -1) { std::cout << "DEBUG:: idx: " << idx << "\n"; std::cout << "ERROR:: failed to find atom in molecule: chain-id :" - << std::string(atom->residue->GetChainID()) << ": res_no " - << atom->residue->seqNum << " inscode :" + << std::string(atom->GetResidue()->GetChainID()) << ": res_no " + << atom->GetResidue()->GetSeqNum() << " inscode :" << std::string(atom->GetInsCode()) << ": name :" - << std::string(atom->name) << ": altloc :" - << std::string(atom->altLoc) << ":" << std::endl; + << std::string(atom->GetAtomName()) << ": altloc :" + << std::string(atom->altLoc()) << ":" << std::endl; } } @@ -1157,11 +1157,11 @@ coot::molecule_t::replace_coords(const atom_selection_container_t &asc, if (idx >= 0) { n_atom++; mmdb::Atom *mol_atom = atom_sel.atom_selection[idx]; - float atom_occ = atom->occupancy; + float atom_occ = atom->occupancy(); // if this is a shelx molecule, then we don't change // occupancies this way. We do it by changing the FVAR if (is_from_shelx_ins_flag) { - atom_occ = mol_atom->occupancy; + atom_occ = mol_atom->occupancy(); // OK, one more go. We have an occupancy of 31 or -31 // say. Now, the alt conf atoms has been immediately @@ -1180,8 +1180,8 @@ coot::molecule_t::replace_coords(const atom_selection_container_t &asc, } if (true) { - coot::Cartesian old_pos(mol_atom->x, mol_atom->y, mol_atom->z); - coot::Cartesian new_pos(atom->x, atom->y, atom->z); + coot::Cartesian old_pos(mol_atom->x(), mol_atom->y(), mol_atom->z()); + coot::Cartesian new_pos(atom->x(), atom->y(), atom->z()); double d = (new_pos - old_pos).amplitude(); if (false) { std::cout << " changing coords for atom with idx " << idx << " " @@ -1191,23 +1191,23 @@ coot::molecule_t::replace_coords(const atom_selection_container_t &asc, } if (movable_atom(mol_atom, replace_coords_with_zero_occ_flag)) - mol_atom->SetCoordinates(atom->x, - atom->y, - atom->z, + mol_atom->SetCoordinates(atom->x(), + atom->y(), + atom->z(), atom_occ, - mol_atom->tempFactor); + mol_atom->tempFactor()); } else { if (movable_atom(mol_atom, replace_coords_with_zero_occ_flag)) - mol_atom->SetCoordinates(atom->x, - atom->y, - atom->z, + mol_atom->SetCoordinates(atom->x(), + atom->y(), + atom->z(), atom_occ, - mol_atom->tempFactor); + mol_atom->tempFactor()); } // similarly we adjust occupancy if this is not a shelx molecule if (! is_from_shelx_ins_flag) { - adjust_occupancy_other_residue_atoms(mol_atom, mol_atom->residue, 0); + adjust_occupancy_other_residue_atoms(mol_atom, mol_atom->GetResidue(), 0); } // std::cout << atom << " coords replace " << idx << " " << mol_atom << std::endl; } else { @@ -1227,8 +1227,8 @@ coot::molecule_t::replace_coords(const atom_selection_container_t &asc, bool is_movable_atom = movable_atom(mol_atom, replace_coords_with_zero_occ_flag); if (is_movable_atom) { if (debug) { // debug - coot::Cartesian old_pos(mol_atom->x, mol_atom->y, mol_atom->z); - coot::Cartesian new_pos(atom->x, atom->y, atom->z); + coot::Cartesian old_pos(mol_atom->x(), mol_atom->y(), mol_atom->z()); + coot::Cartesian new_pos(atom->x(), atom->y(), atom->z()); double d = (new_pos - old_pos).amplitude(); if (false) { // debug std::cout << " changing coords for atom with idx " << idx << " " << coot::atom_spec_t(mol_atom) @@ -1236,11 +1236,11 @@ coot::molecule_t::replace_coords(const atom_selection_container_t &asc, std::cout << " " << old_pos << " " << new_pos << " moved-by " << d << std::endl; } } - mol_atom->SetCoordinates(atom->x, - atom->y, - atom->z, - mol_atom->occupancy, - mol_atom->tempFactor); + mol_atom->SetCoordinates(atom->x(), + atom->y(), + atom->z(), + mol_atom->occupancy(), + mol_atom->tempFactor()); n_atom++; } } else { @@ -1296,7 +1296,7 @@ coot::molecule_t::ramachandran_validation(const ramachandrans_container_t &rc) c if (! at_1->isTer()) { std::string atom_name_1(at_1->GetAtomName()); if (atom_name_1 == " C ") { - coot::Cartesian pt_c(at_1->x, at_1->y, at_1->z); + coot::Cartesian pt_c(at_1->x(), at_1->y(), at_1->z()); mmdb::Atom **residue_atoms_2 = 0; int n_residue_atoms_2 = 0; // I should iterate over all alt confs @@ -1306,7 +1306,7 @@ coot::molecule_t::ramachandran_validation(const ramachandrans_container_t &rc) c if (! at_2->isTer()) { std::string atom_name_2(at_2->GetAtomName()); if (atom_name_2 == " N ") { - coot::Cartesian pt_n(at_1->x, at_1->y, at_1->z); + coot::Cartesian pt_n(at_1->x(), at_1->y(), at_1->z()); double dd = coot::Cartesian::lengthsq(pt_c, pt_n); double d = std::sqrt(dd); if (d < 3.0) { @@ -1331,10 +1331,10 @@ coot::molecule_t::ramachandran_validation(const ramachandrans_container_t &rc) c mmdb::Atom *CB = r->GetAtom(" CB "); if (CA && C && N && CB) { - coot::Cartesian ca_pos(CA->x, CA->y, CA->z); - coot::Cartesian c_pos( C->x, C->y, C->z); - coot::Cartesian n_pos( N->x, N->y, N->z); - coot::Cartesian cb_pos(CB->x, CB->y, CB->z); + coot::Cartesian ca_pos(CA->x(), CA->y(), CA->z()); + coot::Cartesian c_pos( C->x(), C->y(), C->z()); + coot::Cartesian n_pos( N->x(), N->y(), N->z()); + coot::Cartesian cb_pos(CB->x(), CB->y(), CB->z()); coot::Cartesian dir_1 = ca_pos - c_pos; coot::Cartesian dir_2 = ca_pos - n_pos; coot::Cartesian dir_3 = ca_pos - cb_pos; @@ -1343,9 +1343,9 @@ coot::molecule_t::ramachandran_validation(const ramachandrans_container_t &rc) c status = true; } else { if (CA && C && N) { - coot::Cartesian ca_pos(CA->x, CA->y, CA->z); - coot::Cartesian c_pos( C->x, C->y, C->z); - coot::Cartesian n_pos( N->x, N->y, N->z); + coot::Cartesian ca_pos(CA->x(), CA->y(), CA->z()); + coot::Cartesian c_pos( C->x(), C->y(), C->z()); + coot::Cartesian n_pos( N->x(), N->y(), N->z()); coot::Cartesian dir_1 = ca_pos - c_pos; coot::Cartesian dir_2 = ca_pos - n_pos; coot::Cartesian r = dir_1 + dir_2; @@ -1374,7 +1374,7 @@ coot::molecule_t::ramachandran_validation(const ramachandrans_container_t &rc) c if (have_close_peptide_bond(rt, rn)) { mmdb::Atom *at = rt->GetAtom(" CA "); // 20221006-PE alt-confs another day if (at) { - coot::Cartesian pos(at->x, at->y, at->z); + coot::Cartesian pos(at->x(), at->y(), at->z()); std::pair hav = get_HA_unit_vector(rt); coot::Cartesian offset(0,0,rama_ball_pos_offset_scale); if (hav.first) offset = hav.second * rama_ball_pos_offset_scale; @@ -1436,10 +1436,10 @@ coot::molecule_t::get_HA_unit_vector(mmdb::Residue *r) const { mmdb::Atom *CB = r->GetAtom(" CB "); if (CA && C && N && CB) { - coot::Cartesian ca_pos(CA->x, CA->y, CA->z); - coot::Cartesian c_pos( C->x, C->y, C->z); - coot::Cartesian n_pos( N->x, N->y, N->z); - coot::Cartesian cb_pos(CB->x, CB->y, CB->z); + coot::Cartesian ca_pos(CA->x(), CA->y(), CA->z()); + coot::Cartesian c_pos( C->x(), C->y(), C->z()); + coot::Cartesian n_pos( N->x(), N->y(), N->z()); + coot::Cartesian cb_pos(CB->x(), CB->y(), CB->z()); coot::Cartesian dir_1 = ca_pos - c_pos; coot::Cartesian dir_2 = ca_pos - n_pos; coot::Cartesian dir_3 = ca_pos - cb_pos; @@ -1448,9 +1448,9 @@ coot::molecule_t::get_HA_unit_vector(mmdb::Residue *r) const { status = true; } else { if (CA && C && N) { - coot::Cartesian ca_pos(CA->x, CA->y, CA->z); - coot::Cartesian c_pos( C->x, C->y, C->z); - coot::Cartesian n_pos( N->x, N->y, N->z); + coot::Cartesian ca_pos(CA->x(), CA->y(), CA->z()); + coot::Cartesian c_pos( C->x(), C->y(), C->z()); + coot::Cartesian n_pos( N->x(), N->y(), N->z()); coot::Cartesian dir_1 = ca_pos - c_pos; coot::Cartesian dir_2 = ca_pos - n_pos; coot::Cartesian r = dir_1 + dir_2; @@ -1721,9 +1721,9 @@ coot::molecule_t::backrub_rotamer(const std::string &chain_id, int res_no, mmdb::Atom *at = residue_atoms[i]; std::string atom_name(at->GetAtomName()); if (atom_name == atom.name) { - at->x = atom.pos.x(); - at->y = atom.pos.y(); - at->z = atom.pos.z(); + at->x() = atom.pos.x(); + at->y() = atom.pos.y(); + at->z() = atom.pos.z(); } } } @@ -2004,10 +2004,10 @@ coot::molecule_t::delete_atom(coot::atom_spec_t &atom_spec) { res->GetAtomTable(residue_atoms, nResidueAtoms); for (int iat=0; iatname; + mol_atom_name = residue_atoms[iat]->GetAtomName(); if (atname == mol_atom_name) { - if (std::string(residue_atoms[iat]->altLoc) == altconf) { + if (std::string(residue_atoms[iat]->altLoc()) == altconf) { make_backup("delete_atom"); atom_sel.mol->DeleteSelection(atom_sel.SelectionHandle); @@ -2044,7 +2044,7 @@ coot::molecule_t::delete_atom(coot::atom_spec_t &atom_spec) { int n_matching_name = 0; residue_of_deleted_atom->GetAtomTable(atoms, n_atoms); for (int iat=0; iatname; + std::string res_atom_name = atoms[iat]->GetAtomName(); if (res_atom_name == atname) { at = atoms[iat]; n_matching_name++; @@ -2053,10 +2053,10 @@ coot::molecule_t::delete_atom(coot::atom_spec_t &atom_spec) { if (n_matching_name == 1) { // one atom of this name left in the residue, so // remove its altconf string if (at) { - strncpy(at->altLoc, "", 2); + strncpy(at->altLoc(), "", 2); // set the occupancy to 1.0 of the remaining atom if it was not zero. - if (at->occupancy > 0.009) - at->occupancy = 1.0; + if (at->occupancy() > 0.009) + at->occupancy() = 1.0; } } @@ -2229,7 +2229,7 @@ coot::molecule_t::delete_residue_atoms_with_alt_conf(coot::residue_spec_t &resid residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iataltLoc); + std::string al(at->altLoc()); if (al == alt_conf) atoms_to_be_deleted.push_back(at); } @@ -2342,12 +2342,12 @@ coot::molecule_t::change_alt_locs(const std::string &cid, const std::string &cha residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iataltLoc; + std::string alt_loc = at->altLoc(); if (alt_loc == "A") atoms_with_alt_loc_A.push_back(at); if (alt_loc == "B") atoms_with_alt_loc_B.push_back(at); } - for (auto atom : atoms_with_alt_loc_A) strncpy(atom->altLoc, "B", 2); - for (auto atom : atoms_with_alt_loc_B) strncpy(atom->altLoc, "A", 2); + for (auto atom : atoms_with_alt_loc_A) strncpy(atom->altLoc(), "B", 2); + for (auto atom : atoms_with_alt_loc_B) strncpy(atom->altLoc(), "A", 2); if (! atoms_with_alt_loc_A.empty()) status = 1; if (! atoms_with_alt_loc_B.empty()) status = 1; return status; @@ -2364,13 +2364,13 @@ coot::molecule_t::change_alt_locs(const std::string &cid, const std::string &cha mmdb::Atom *at = residue_atoms[iat]; if (is_main_chain_p(at)) { } else { - std::string alt_loc = at->altLoc; + std::string alt_loc = at->altLoc(); if (alt_loc == "A") atoms_with_alt_loc_A.push_back(at); if (alt_loc == "B") atoms_with_alt_loc_B.push_back(at); } } - for (auto atom : atoms_with_alt_loc_A) strncpy(atom->altLoc, "B", 2); - for (auto atom : atoms_with_alt_loc_B) strncpy(atom->altLoc, "A", 2); + for (auto atom : atoms_with_alt_loc_A) strncpy(atom->altLoc(), "B", 2); + for (auto atom : atoms_with_alt_loc_B) strncpy(atom->altLoc(), "A", 2); if (! atoms_with_alt_loc_A.empty()) status = 1; if (! atoms_with_alt_loc_B.empty()) status = 1; return status; @@ -2386,13 +2386,13 @@ coot::molecule_t::change_alt_locs(const std::string &cid, const std::string &cha for (int iat=0; iataltLoc; + std::string alt_loc = at->altLoc(); if (alt_loc == "A") atoms_with_alt_loc_A.push_back(at); if (alt_loc == "B") atoms_with_alt_loc_B.push_back(at); } } - for (auto atom : atoms_with_alt_loc_A) strncpy(atom->altLoc, "B", 2); - for (auto atom : atoms_with_alt_loc_B) strncpy(atom->altLoc, "A", 2); + for (auto atom : atoms_with_alt_loc_A) strncpy(atom->altLoc(), "B", 2); + for (auto atom : atoms_with_alt_loc_B) strncpy(atom->altLoc(), "A", 2); if (! atoms_with_alt_loc_A.empty()) status = 1; if (! atoms_with_alt_loc_B.empty()) status = 1; return status; @@ -2413,15 +2413,15 @@ coot::molecule_t::change_alt_locs(const std::string &cid, const std::string &cha residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); + std::string atom_name(at->GetAtomName()); if (atom_name == name) { - std::string alt_loc = at->altLoc; + std::string alt_loc = at->altLoc(); if (alt_loc == "A") { - strncpy(at->altLoc, "B", 2); + strncpy(at->altLoc(), "B", 2); status = 1; } else { if (alt_loc == "B") { - strncpy(at->altLoc, "A", 2); + strncpy(at->altLoc(), "A", 2); status = 1; } } @@ -2775,9 +2775,9 @@ coot::molecule_t::move_molecule_to_new_centre(const coot::Cartesian &new_centre) for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - at->x += delta.x(); - at->y += delta.y(); - at->z += delta.z(); + at->x() += delta.x(); + at->y() += delta.y(); + at->z() += delta.z(); } } } @@ -2796,7 +2796,7 @@ coot::Cartesian coot::molecule_t::get_molecule_centre() const { auto mmdb_to_cartesian = [] (mmdb::Atom *at) { - return Cartesian(at->x, at->y, at->z); + return Cartesian(at->x(), at->y(), at->z()); }; coot::Cartesian c(0,0,0); @@ -2972,9 +2972,9 @@ coot::molecule_t::jed_flip(coot::residue_spec_t &spec, int n_residue_atoms; residue->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); + std::string an(residue_atoms[iat]->GetAtomName()); if (an == atom_name) { - std::string ac(residue_atoms[iat]->altLoc); + std::string ac(residue_atoms[iat]->altLoc()); if (ac == alt_conf) { clicked_atom = residue_atoms[iat]; clicked_atom_idx = iat; @@ -3159,7 +3159,7 @@ coot::molecule_t::apply_transformation_to_atom_selection(const std::string &atom clipper::RTop_orth &rtop) { auto mmdb_to_clipper = [] (mmdb::Atom *at) { - return clipper::Coord_orth(at->x, at->y, at->z); + return clipper::Coord_orth(at->x(), at->y(), at->z()); }; int n_atoms_moved = 0; @@ -3184,9 +3184,9 @@ coot::molecule_t::apply_transformation_to_atom_selection(const std::string &atom clipper::Coord_orth p1 = pt - rotation_centre; clipper::Coord_orth p2 = rtop * p1; clipper::Coord_orth p3 = p2 - rotation_centre; - at->x = p3.x(); - at->y = p3.y(); - at->z = p3.z(); + at->x() = p3.x(); + at->y() = p3.y(); + at->z() = p3.z(); n_atoms_moved++; } } @@ -3236,11 +3236,11 @@ coot::molecule_t::new_positions_for_residue_atoms(mmdb::Residue *residue_p, cons if (! at->isTer()) { std::string atom_name(at->GetAtomName()); if (atom_name == mva.atom_name) { - std::string alt_conf(at->altLoc); + std::string alt_conf(at->altLoc()); if (alt_conf == mva.alt_conf) { - at->x = mva.x; - at->y = mva.y; - at->z = mva.z; + at->x() = mva.x; + at->y() = mva.y; + at->z() = mva.z; n_atoms_moved++; } } @@ -3291,9 +3291,9 @@ coot::molecule_t::get_residue_closest_to(mmdb::Manager *mol, const clipper::Coor for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - double dx = at->x - co.x(); - double dy = at->y - co.y(); - double dz = at->z - co.z(); + double dx = at->x() - co.x(); + double dy = at->y() - co.y(); + double dz = at->z() - co.z(); double dd = dx * dx + dy * dy + dz * dz; if (dd < d_best) { d_best = dd; @@ -3496,7 +3496,7 @@ coot::molecule_t::insert_waters_into_molecule(const coot::minimol::molecule &wat for (unsigned int iatom=0; iatomSetResName(res_name.c_str()); - new_residue_p->seqNum = prev_max_resno + 1 + water_count; + new_residue_p->GetSeqNum() = prev_max_resno + 1 + water_count; water_count++; bf = water_mol[ifrag][ires][iatom].temperature_factor; new_atom_p = new mmdb::Atom; @@ -3508,8 +3508,8 @@ coot::molecule_t::insert_waters_into_molecule(const coot::minimol::molecule &wat << " with b " << bf << std::endl; new_atom_p->SetAtomName(water_mol[ifrag][ires][iatom].name.c_str()); new_atom_p->Het = 1; // waters are now HETATMs - strncpy(new_atom_p->element, water_mol[ifrag][ires][iatom].element.c_str(), 3); - strncpy(new_atom_p->altLoc, water_mol[ifrag][ires][iatom].altLoc.c_str(), 2); + new_atom_p->SetElementName(water_mol[ifrag][ires][iatom].element.c_str()); + strncpy(new_atom_p->altLoc(), water_mol[ifrag][ires][iatom].altLoc.c_str(), 2); // residue number, atom name, occ, coords, b factor @@ -3595,8 +3595,8 @@ coot::molecule_t::append_to_molecule(const coot::minimol::molecule &water_mol) { if (water_mol[ifrag][ires].atoms.size() > 0) { new_residue_p = new mmdb::Residue; - new_residue_p->seqNum = ires; - strcpy(new_residue_p->name, water_mol[ifrag][ires].name.c_str()); + new_residue_p->GetSeqNum() = ires; + new_residue_p->SetResName(water_mol[ifrag][ires].name.c_str()); new_chain_p->AddResidue(new_residue_p); for (unsigned int iatom=0; iatomx += o.x(); - at->y += o.y(); - at->z += o.z(); + at->x() += o.x(); + at->y() += o.y(); + at->z() += o.z(); }; auto set_offset = [] (clipper::Coord_orth &offset, mmdb::Residue *residue_p) { @@ -4006,8 +4006,8 @@ coot::molecule_t::add_alternative_conformation(const std::string &cid) { if (atom_name == " C ") c_at = at; } if (c_at && n_at) { - clipper::Coord_orth c_pos(c_at->x, c_at->y, c_at->z); - clipper::Coord_orth n_pos(n_at->x, n_at->y, n_at->z); + clipper::Coord_orth c_pos(c_at->x(), c_at->y(), c_at->z()); + clipper::Coord_orth n_pos(n_at->x(), n_at->y(), n_at->z()); clipper::Coord_orth cn_unit((c_pos-n_pos).unit()); clipper::Coord_orth arb(1,2,3); clipper::Coord_orth arb_uv(arb.unit()); @@ -4035,18 +4035,18 @@ coot::molecule_t::add_alternative_conformation(const std::string &cid) { // be more complex. Let's just use this for now - it will // handle the vast majority of cases. // - std::string current_alt_conf(at->altLoc); + std::string current_alt_conf(at->altLoc()); if (current_alt_conf.empty()) { mmdb::Atom *at_new = new mmdb::Atom; at_new->Copy(at); move(at_new, -offset); - strcpy(at_new->altLoc, "B"); - at_new->occupancy = 0.5; + strcpy(at_new->altLoc(), "B"); + at_new->occupancy() = 0.5; new_atoms.push_back(at_new); move(at, offset); - at->occupancy = 0.5; - strcpy(at->altLoc, "A"); + at->occupancy() = 0.5; + strcpy(at->altLoc(), "A"); } } } @@ -4333,16 +4333,16 @@ coot::molecule_t::set_residue_to_rotamer_move_atoms(mmdb::Residue *res, mmdb::Re int n_atoms = 0; for (int imov=0; imovname); - std::string alt_loc_mov(mov_residue_atoms[imov]->altLoc); + std::string atom_name_mov(mov_residue_atoms[imov]->GetAtomName()); + std::string alt_loc_mov(mov_residue_atoms[imov]->altLoc()); for (int iref=0; irefname); - std::string alt_loc_ref(ref_residue_atoms[iref]->altLoc); + std::string atom_name_ref(ref_residue_atoms[iref]->GetAtomName()); + std::string alt_loc_ref(ref_residue_atoms[iref]->altLoc()); if (atom_name_mov == atom_name_ref) { if (alt_loc_mov == alt_loc_ref) { - ref_residue_atoms[iref]->x = mov_residue_atoms[imov]->x; - ref_residue_atoms[iref]->y = mov_residue_atoms[imov]->y; - ref_residue_atoms[iref]->z = mov_residue_atoms[imov]->z; + ref_residue_atoms[iref]->x() = mov_residue_atoms[imov]->x(); + ref_residue_atoms[iref]->y() = mov_residue_atoms[imov]->y(); + ref_residue_atoms[iref]->z() = mov_residue_atoms[imov]->z(); n_atoms++; i_done = 1; } @@ -4401,7 +4401,7 @@ coot::molecule_t::add_target_position_restraint_and_refine(const std::string &at const auto &pp = atoms_with_position_restraints[i]; clipper::Coord_orth p = pp.second; mmdb::Atom *at = pp.first; - at->x = p.x(); at->y = p.y(); at->z = p.z(); + at->x() = p.x(); at->y() = p.y(); at->z() = p.z(); } if (n_cycles < 0) { @@ -4799,8 +4799,8 @@ coot::molecule_t::multiply_residue_temperature_factors(const std::string &cid, f for (int i=0; iisTer()) { - float new_B = at->tempFactor * factor; - at->tempFactor = new_B; + float new_B = at->tempFactor() * factor; + at->tempFactor() = new_B; } } } @@ -4865,13 +4865,13 @@ coot::molecule_t::transform_by(const clipper::RTop_orth &rtop, mmdb::Residue *re int n_residue_atoms = 0; residue_moving->GetAtomTable(residue_atoms, n_residue_atoms); for (int iatom=0; iatomx, - residue_atoms[iatom]->y, - residue_atoms[iatom]->z); + clipper::Coord_orth p(residue_atoms[iatom]->x(), + residue_atoms[iatom]->y(), + residue_atoms[iatom]->z()); clipper::Coord_orth p2 = p.transform(rtop); - residue_atoms[iatom]->x = p2.x(); - residue_atoms[iatom]->y = p2.y(); - residue_atoms[iatom]->z = p2.z(); + residue_atoms[iatom]->x() = p2.x(); + residue_atoms[iatom]->y() = p2.y(); + residue_atoms[iatom]->z() = p2.z(); } atom_sel.mol->PDBCleanup(mmdb::PDBCLEAN_SERIAL|mmdb::PDBCLEAN_INDEX); @@ -4899,9 +4899,9 @@ coot::molecule_t::transform_by(const clipper::RTop_orth &rtop) { if (! at->isTer()) { clipper::Coord_orth pos = coot::co(at); clipper::Coord_orth p2 = pos.transform(rtop); - at->x = p2.x(); - at->y = p2.y(); - at->z = p2.z(); + at->x() = p2.x(); + at->y() = p2.y(); + at->z() = p2.z(); } } } @@ -4952,7 +4952,7 @@ coot::molecule_t::get_temperature_factor_of_atom(const std::string &atom_cid) co float b = -1.1f; mmdb:: Atom *at = cid_to_atom(atom_cid); if (at) { - b = at->tempFactor; + b = at->tempFactor(); } return b; @@ -5117,9 +5117,9 @@ coot::molecule_t::get_residue_CA_position(const std::string &cid) const { if (! at->isTer()) { std::string name = at->GetAtomName(); if (name == " CA ") { - v.push_back(at->x); - v.push_back(at->y); - v.push_back(at->z); + v.push_back(at->x()); + v.push_back(at->y()); + v.push_back(at->z()); break; } } @@ -5235,7 +5235,7 @@ coot::molecule_t::set_occupancy(const std::string &cid, float occ_new) { for (int i=0; iisTer()) { - at->occupancy = occ_new; + at->occupancy() = occ_new; } } atom_sel.mol->DeleteSelection(selHnd); @@ -5411,7 +5411,7 @@ coot::molecule_t::set_temperature_factors_using_cid(const std::string &cid, floa if (nSelAtoms > 0) { for (int i=0; itempFactor = temp_fact; + atom->tempFactor() = temp_fact; } } atom_sel.mol->DeleteSelection(selHnd); diff --git a/api/filo-tests.cc b/api/filo-tests.cc index a3c5a3337f..2bdde586da 100644 --- a/api/filo-tests.cc +++ b/api/filo-tests.cc @@ -296,8 +296,8 @@ int test_change_rotamer(molecules_container_t &molecules_container) { mmdb::Residue *res_new = molecules_container.get_residue(imol_molecule, resSpec); mmdb::Atom *atom_new = res_new->GetAtom(5); - std::cout << "atom_fragment pos: " << atom_fragment->x << " " << atom_fragment->y << " " << atom_fragment->z << std::endl; - std::cout << "atom_new pos: " << atom_new->x << " " << atom_new->y << " " << atom_new->z << std::endl; + std::cout << "atom_fragment pos: " << atom_fragment->x() << " " << atom_fragment->y() << " " << atom_fragment->z() << std::endl; + std::cout << "atom_new pos: " << atom_new->x() << " " << atom_new->y() << " " << atom_new->z() << std::endl; // This fails... // expect(atom_new.x).toBe(atom_fragment.x) diff --git a/api/model-analysis.cc b/api/model-analysis.cc index 37f375ba85..e1ece3e533 100644 --- a/api/model-analysis.cc +++ b/api/model-analysis.cc @@ -37,8 +37,8 @@ molecules_container_t::get_atom_differences(int imol1, int imol2) { mmdb::Atom *atom2 = res2->GetAtom(atom_name); if (atom2) { coot::atom_spec_t as1 = coot::atom_spec_t(atom1); - coot::Cartesian pos1 = coot::Cartesian(atom1->x, atom1->y, atom1->z); - coot::Cartesian pos2 = coot::Cartesian(atom2->x, atom2->y, atom2->z); + coot::Cartesian pos1 = coot::Cartesian(atom1->x(), atom1->y(), atom1->z()); + coot::Cartesian pos2 = coot::Cartesian(atom2->x(), atom2->y(), atom2->z()); positioned_atom_spec_t pas; pas.atom_spec = as1; pas.pos1 = pos1; diff --git a/api/molecules-container-ligand-fitting.cc b/api/molecules-container-ligand-fitting.cc index 34273d4e86..e1f5271ada 100644 --- a/api/molecules-container-ligand-fitting.cc +++ b/api/molecules-container-ligand-fitting.cc @@ -507,9 +507,9 @@ get_eigenvalues(mmdb::Residue *residue_p) { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - x.push_back(at->x); - y.push_back(at->y); - z.push_back(at->z); + x.push_back(at->x()); + y.push_back(at->y()); + z.push_back(at->z()); } } if (! x.empty()) { @@ -523,12 +523,12 @@ get_eigenvalues(mmdb::Residue *residue_p) { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - mat(0,0) += (double(at->x) - x_mean) * (double(at->x) - x_mean); - mat(1,1) += (double(at->y) - y_mean) * (double(at->y) - y_mean); - mat(2,2) += (double(at->z) - z_mean) * (double(at->z) - z_mean); - mat(0,1) += (double(at->x) - x_mean) * (double(at->y) - y_mean); - mat(0,2) += (double(at->x) - x_mean) * (double(at->z) - z_mean); - mat(1,2) += (double(at->y) - y_mean) * (double(at->z) - z_mean); + mat(0,0) += (double(at->x()) - x_mean) * (double(at->x()) - x_mean); + mat(1,1) += (double(at->y()) - y_mean) * (double(at->y()) - y_mean); + mat(2,2) += (double(at->z()) - z_mean) * (double(at->z()) - z_mean); + mat(0,1) += (double(at->x()) - x_mean) * (double(at->y()) - y_mean); + mat(0,2) += (double(at->x()) - x_mean) * (double(at->z()) - z_mean); + mat(1,2) += (double(at->y()) - y_mean) * (double(at->z()) - z_mean); } } mat(1,0) = mat(0,1); @@ -581,9 +581,9 @@ molecules_container_t::get_eigenvectors_and_eigenvalues(int imol, const std::str for (int i=0; iisTer()) { - x.push_back(at->x); - y.push_back(at->y); - z.push_back(at->z); + x.push_back(at->x()); + y.push_back(at->y()); + z.push_back(at->z()); } } mol->DeleteSelection(selhandle); diff --git a/api/molecules-container-maps.cc b/api/molecules-container-maps.cc index 58f7f5c90b..1c6a8e06f6 100644 --- a/api/molecules-container-maps.cc +++ b/api/molecules-container-maps.cc @@ -506,7 +506,7 @@ molecules_container_t::get_q_score_validation_information(mmdb::Manager *mol, in at->GetUDData(udd_q_score, q); if (false) std::cout << " " << coot::atom_spec_t(at) << " B " - << at->tempFactor << " Q-Score: " << q + << at->tempFactor() << " Q-Score: " << q << std::endl; } } @@ -787,7 +787,7 @@ molecules_container_t::get_spherical_variance(int imol_map, int imol_model, coot::atom_spec_t atom_spec(at_m); mmdb::Atom *at = molecules[imol_model].get_atom(atom_spec); if (at) { - clipper::Coord_orth pt(at->x, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); float mean_d = mean_density_other_atoms; coot::ligand::spherical_density_score_t sds; float sv = sds.get_spherical_variance(pt, xmap, mean_d); diff --git a/api/molecules-container-modelling.cc b/api/molecules-container-modelling.cc index 3cab6a3cb7..b7ba72ed9d 100644 --- a/api/molecules-container-modelling.cc +++ b/api/molecules-container-modelling.cc @@ -319,7 +319,7 @@ molecules_container_t::add_compound(int imol, const std::string &tlc, int imol_d mmdb::Atom *at = residue_atoms[iat]; if (! at->isTer()) { n_atoms++; - position_sum + coot::Cartesian(at->x, at->y, at->z); + position_sum + coot::Cartesian(at->x(), at->y(), at->z()); } } if (n_atoms > 0) { @@ -328,9 +328,9 @@ molecules_container_t::add_compound(int imol, const std::string &tlc, int imol_d for (int iat=0; iatisTer()) { - at->x += position.x() - current_position.x(); - at->y += position.y() - current_position.y(); - at->z += position.z() - current_position.z(); + at->x() += position.x() - current_position.x(); + at->y() += position.y() - current_position.y(); + at->z() += position.z() - current_position.z(); } } } diff --git a/api/molecules-container-molecular-placement.cc b/api/molecules-container-molecular-placement.cc index bad5093f02..f5f1eafa66 100644 --- a/api/molecules-container-molecular-placement.cc +++ b/api/molecules-container-molecular-placement.cc @@ -84,7 +84,7 @@ molecules_container_t::molecular_placement_fit(int imol_map, int imol_model, if (n_atoms > 0) { float sum = 0.0f; for (int j=0; jx, atoms[j]->y, atoms[j]->z); + clipper::Coord_orth pt(atoms[j]->x(), atoms[j]->y(), atoms[j]->z()); sum += coot::util::density_at_point(molecules[imol_map].xmap, pt); } mean_density_ca = sum / static_cast(n_atoms); diff --git a/api/molecules-container-nanobind.cc b/api/molecules-container-nanobind.cc index 5a944b4f14..02e6aced6b 100644 --- a/api/molecules-container-nanobind.cc +++ b/api/molecules-container-nanobind.cc @@ -206,23 +206,23 @@ NB_MODULE(coot_headless_api, m) { # else nb::class_(m,"Atom") .def(nb::init<>()) - .def_prop_rw("x",[](mmdb::Atom &t) { return t.x ; },[](mmdb::Atom &t, float value) { t.x = value; }) - .def_prop_rw("y",[](mmdb::Atom &t) { return t.y ; },[](mmdb::Atom &t, float value) { t.y = value; }) - .def_prop_rw("z",[](mmdb::Atom &t) { return t.z ; },[](mmdb::Atom &t, float value) { t.z = value; }) - .def_prop_rw("serNum",[](mmdb::Atom &t) { return t.serNum ; },[](mmdb::Atom &t, float value) { t.serNum = value; }) - .def_prop_rw("occupancy",[](mmdb::Atom &t) { return t.occupancy ; },[](mmdb::Atom &t, float value) { t.occupancy = value; }) - .def_prop_rw("tempFactor",[](mmdb::Atom &t) { return t.tempFactor ; },[](mmdb::Atom &t, float value) { t.tempFactor = value; }) - .def_prop_rw("charge",[](mmdb::Atom &t) { return t.charge ; },[](mmdb::Atom &t, float value) { t.charge = value; }) - .def_prop_rw("sigX",[](mmdb::Atom &t) { return t.sigX ; },[](mmdb::Atom &t, float value) { t.sigX = value; }) - .def_prop_rw("sigY",[](mmdb::Atom &t) { return t.sigY ; },[](mmdb::Atom &t, float value) { t.sigY = value; }) - .def_prop_rw("sigZ",[](mmdb::Atom &t) { return t.sigZ ; },[](mmdb::Atom &t, float value) { t.sigZ = value; }) - .def_prop_rw("sigOcc",[](mmdb::Atom &t) { return t.sigOcc ; },[](mmdb::Atom &t, float value) { t.sigOcc = value; }) - .def_prop_rw("sigTemp",[](mmdb::Atom &t) { return t.sigTemp ; },[](mmdb::Atom &t, float value) { t.sigTemp = value; }) - .def_prop_rw("u11",[](mmdb::Atom &t) { return t.u11 ; },[](mmdb::Atom &t, float value) { t.u11 = value; }) - .def_prop_rw("u22",[](mmdb::Atom &t) { return t.u22 ; },[](mmdb::Atom &t, float value) { t.u22 = value; }) - .def_prop_rw("u33",[](mmdb::Atom &t) { return t.u33 ; },[](mmdb::Atom &t, float value) { t.u33 = value; }) - .def_prop_rw("u13",[](mmdb::Atom &t) { return t.u13 ; },[](mmdb::Atom &t, float value) { t.u13 = value; }) - .def_prop_rw("u23",[](mmdb::Atom &t) { return t.u23 ; },[](mmdb::Atom &t, float value) { t.u23 = value; }) + .def_prop_rw("x",[](mmdb::Atom &t) { return t.x() ; },[](mmdb::Atom &t, float value) { t.x() = value; }) + .def_prop_rw("y",[](mmdb::Atom &t) { return t.y() ; },[](mmdb::Atom &t, float value) { t.y() = value; }) + .def_prop_rw("z",[](mmdb::Atom &t) { return t.z() ; },[](mmdb::Atom &t, float value) { t.z() = value; }) + .def_prop_rw("serNum",[](mmdb::Atom &t) { return t.serNum() ; },[](mmdb::Atom &t, float value) { t.serNum() = value; }) + .def_prop_rw("occupancy",[](mmdb::Atom &t) { return t.occupancy() ; },[](mmdb::Atom &t, float value) { t.occupancy() = value; }) + .def_prop_rw("tempFactor",[](mmdb::Atom &t) { return t.tempFactor() ; },[](mmdb::Atom &t, float value) { t.tempFactor() = value; }) + .def_prop_rw("charge",[](mmdb::Atom &t) { return t.charge() ; },[](mmdb::Atom &t, float value) { t.charge() = value; }) + .def_prop_rw("sigX",[](mmdb::Atom &t) { return t.sigX() ; },[](mmdb::Atom &t, float value) { t.sigX() = value; }) + .def_prop_rw("sigY",[](mmdb::Atom &t) { return t.sigY() ; },[](mmdb::Atom &t, float value) { t.sigY() = value; }) + .def_prop_rw("sigZ",[](mmdb::Atom &t) { return t.sigZ() ; },[](mmdb::Atom &t, float value) { t.sigZ() = value; }) + .def_prop_rw("sigOcc",[](mmdb::Atom &t) { return t.sigOcc() ; },[](mmdb::Atom &t, float value) { t.sigOcc() = value; }) + .def_prop_rw("sigTemp",[](mmdb::Atom &t) { return t.sigTemp() ; },[](mmdb::Atom &t, float value) { t.sigTemp() = value; }) + .def_prop_rw("u11",[](mmdb::Atom &t) { return t.u11() ; },[](mmdb::Atom &t, float value) { t.u11() = value; }) + .def_prop_rw("u22",[](mmdb::Atom &t) { return t.u22() ; },[](mmdb::Atom &t, float value) { t.u22() = value; }) + .def_prop_rw("u33",[](mmdb::Atom &t) { return t.u33() ; },[](mmdb::Atom &t, float value) { t.u33() = value; }) + .def_prop_rw("u13",[](mmdb::Atom &t) { return t.u13() ; },[](mmdb::Atom &t, float value) { t.u13() = value; }) + .def_prop_rw("u23",[](mmdb::Atom &t) { return t.u23() ; },[](mmdb::Atom &t, float value) { t.u23() = value; }) .def_prop_rw("Het",[](mmdb::Atom &t) { return t.Het ; },[](mmdb::Atom &t, bool value) { t.Het = value; }) .def_prop_rw("Ter",[](mmdb::Atom &t) { return t.Ter ; },[](mmdb::Atom &t, bool value) { t.Ter = value; }) .def("GetNBonds",&mmdb::Atom::GetNBonds) @@ -248,10 +248,10 @@ NB_MODULE(coot_headless_api, m) { ; nb::class_(m,"Residue") .def(nb::init<>()) - .def_prop_rw("seqNum",[](mmdb::Residue &t) { return t.seqNum ; },[](mmdb::Residue &t, int value) { t.seqNum = value; }) + .def_prop_rw("seqNum",[](mmdb::Residue &t) { return t.GetSeqNum() ; },[](mmdb::Residue &t, int value) { t.GetSeqNum() = value; }) .def_prop_rw("label_seq_id",[](mmdb::Residue &t) { return t.label_seq_id ; },[](mmdb::Residue &t, int value) { t.label_seq_id = value; }) .def_prop_rw("label_entity_id",[](mmdb::Residue &t) { return t.label_entity_id ; },[](mmdb::Residue &t, int value) { t.label_entity_id = value; }) - .def_prop_rw("index",[](mmdb::Residue &t) { return t.index ; },[](mmdb::Residue &t, int value) { t.index = value; }) + .def_prop_rw("index",[](mmdb::Residue &t) { return t.GetIndex() ; },[](mmdb::Residue &t, int value) { t.GetIndex() = value; }) .def_prop_rw("nAtoms",[](mmdb::Residue &t) { return t.nAtoms ; },[](mmdb::Residue &t, int value) { t.nAtoms = value; }) .def("GetModelNum",&mmdb::Residue::GetModelNum) .def("GetSeqNum",&mmdb::Residue::GetSeqNum) diff --git a/api/molecules-container-superpose.cc b/api/molecules-container-superpose.cc index 94f297e6dd..78a4a5298b 100644 --- a/api/molecules-container-superpose.cc +++ b/api/molecules-container-superpose.cc @@ -539,7 +539,7 @@ molecules_container_t::get_pairs(ssm::Align *SSMAlign, if (t_index == -1) { coot::residue_validation_information_t ref; coot::residue_validation_information_t mov; - coot::residue_spec_t ref_res_spec(atom_selection1[i1]->residue); + coot::residue_spec_t ref_res_spec(atom_selection1[i1]->GetResidue()); coot::residue_spec_t mov_res_spec; ref.residue_spec = ref_res_spec; mov.residue_spec = mov_res_spec; @@ -551,8 +551,8 @@ molecules_container_t::get_pairs(ssm::Align *SSMAlign, if (s_index == i1) { coot::residue_validation_information_t ref; coot::residue_validation_information_t mov; - coot::residue_spec_t ref_res_spec(atom_selection1[i1]->residue); - coot::residue_spec_t mov_res_spec(atom_selection2[t_index]->residue); + coot::residue_spec_t ref_res_spec(atom_selection1[i1]->GetResidue()); + coot::residue_spec_t mov_res_spec(atom_selection2[t_index]->GetResidue()); ref.residue_spec = ref_res_spec; mov.residue_spec = mov_res_spec; clipper::Coord_orth pt_1 = coot::co(atom_selection1[i1]); diff --git a/api/molecules-container.cc b/api/molecules-container.cc index abd9ebdf5d..1272c619f9 100644 --- a/api/molecules-container.cc +++ b/api/molecules-container.cc @@ -605,7 +605,7 @@ molecules_container_t::get_active_atom(float x, float y, float z, const std::str s += std::string(at->GetInsCode()); s += "/"; s += std::string(at->GetAtomName()); - std::string a(at->altLoc); + std::string a(at->altLoc()); if (! a.empty()) { s += ":"; s += std::string(); @@ -648,7 +648,7 @@ molecules_container_t::get_active_atom(float x, float y, float z, const std::str for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - coot::Cartesian atom_pos(at->x, at->y, at->z); + coot::Cartesian atom_pos(at->x(), at->y(), at->z()); float dd = coot::Cartesian::lengthsq(screen_centre, atom_pos); if (dd < best_distance_sqrd) { best_distance_sqrd = dd; @@ -1622,7 +1622,7 @@ molecules_container_t::rotamer_analysis(int imol_model) const { // (GLY and ALA have <= 5 heavy atoms and so are correctly skipped here.) int n_heavy_atoms = 0; for (int iat=0; iatelement); + std::string ele(residue_atoms[iat]->GetElementName()); if (ele != " H" && ele != " D") n_heavy_atoms++; } @@ -2156,7 +2156,7 @@ molecules_container_t::get_atom_position(int imol, coot::atom_spec_t &atom_spec) mmdb::Atom *at = get_atom(imol, atom_spec); if (at) { - return std::pair (true, coot::Cartesian(at->x, at->y, at->z)); + return std::pair (true, coot::Cartesian(at->x(), at->y(), at->z())); } else { return std::pair (false, coot::Cartesian(0,0,0)); } @@ -3528,7 +3528,7 @@ molecules_container_t::create_mmdbmanager_from_res_vector(const std::vectorindex + << "had index " << flankers_in_reference_mol[ires]->GetIndex() << std::endl; // get rid of this function at some stage @@ -3539,7 +3539,7 @@ molecules_container_t::create_mmdbmanager_from_res_vector(const std::vectorPutUDData(index_from_reference_residue_handle, flankers_in_reference_mol[ires]->index); + r->PutUDData(index_from_reference_residue_handle, flankers_in_reference_mol[ires]->GetIndex()); // copy over the atom indices. UDDAtomIndexHandle in mol_n becomes UDDOldAtomIndexHandle // indices in the returned molecule @@ -3561,7 +3561,7 @@ molecules_container_t::create_mmdbmanager_from_res_vector(const std::vectorAddResidue(r); // at the end else chain_p->InsResidue(r, sni); - r->seqNum = flankers_in_reference_mol[ires]->GetSeqNum(); + r->GetSeqNum() = flankers_in_reference_mol[ires]->GetSeqNum(); r->SetResName(flankers_in_reference_mol[ires]->GetResName()); n_flanker++; @@ -3587,7 +3587,7 @@ molecules_container_t::create_mmdbmanager_from_res_vector(const std::vectorGetResidue(ires); std::cout << "create_mmdb.. ^^^ " << coot::residue_spec_t(residue_p) << " " - << residue_p << " index " << residue_p->index + << residue_p << " index " << residue_p->GetIndex() << std::endl; } } @@ -4076,7 +4076,7 @@ molecules_container_t::generate_molecule_and_refine(int imol, // needed for UDD std::cout << "DEBUG:: in generate_molecule_and_refine() residues_mol_and_res_vec mol: residue " << coot::residue_spec_t(residue_p) << " residue " << residue_p << " chain " << residue_p->chain << " index " - << residue_p->index << std::endl; + << residue_p->GetIndex() << std::endl; } } } @@ -4570,9 +4570,9 @@ molecules_container_t::apply_translation_to_molecule(int imol, float tx, float t mol->GetSelIndex(selHnd, atoms, n_atoms); if (n_atoms > 0) { for (int i=0; ix += tx; - atoms[i]->y += ty; - atoms[i]->z += tz; + atoms[i]->x() += tx; + atoms[i]->y() += ty; + atoms[i]->z() += tz; } mol->FinishStructEdit(); set_updating_maps_need_an_update(imol); @@ -4621,7 +4621,7 @@ std::vector molecules_container_t::pepflips_using_difference_map(int imol_coords, int imol_difference_map, float n_sigma) const { auto mmdb_to_clipper = [] (mmdb::Atom *at) { - return clipper::Coord_orth(at->x, at->y, at->z); + return clipper::Coord_orth(at->x(), at->y(), at->z()); }; std::vector v; diff --git a/api/moorhen-h-bonds.cc b/api/moorhen-h-bonds.cc index dd39f0d386..eb60477d68 100644 --- a/api/moorhen-h-bonds.cc +++ b/api/moorhen-h-bonds.cc @@ -35,20 +35,20 @@ molecules_container_t::get_h_bonds(int imol, const std::string &cid_str, bool mc if (atom_in) { // can be null (strange). - m_at.serial = atom_in->serNum; - m_at.x = atom_in->x; - m_at.y = atom_in->y; - m_at.z = atom_in->z; - m_at.charge = atom_in->charge; - m_at.occ = atom_in->occupancy; - m_at.b_iso = atom_in->tempFactor; - m_at.element = std::string(atom_in->element); - m_at.name = std::string(atom_in->name); + m_at.serial = atom_in->serNum(); + m_at.x = atom_in->x(); + m_at.y = atom_in->y(); + m_at.z = atom_in->z(); + m_at.charge = atom_in->charge(); + m_at.occ = atom_in->occupancy(); + m_at.b_iso = atom_in->tempFactor(); + m_at.element = std::string(atom_in->GetElementName()); + m_at.name = std::string(atom_in->GetAtomName()); m_at.model = atom_in->GetModelNum(); m_at.chain = std::string(atom_in->GetChainID()); m_at.res_no = atom_in->GetSeqNum(); - m_at.altLoc = std::string(atom_in->altLoc); - m_at.residue_name = std::string(atom_in->GetResidue()->name); + m_at.altLoc = std::string(atom_in->altLoc()); + m_at.residue_name = std::string(atom_in->GetResidue()->GetResName()); } }; diff --git a/api/rama-plot-phi-psi.cc b/api/rama-plot-phi-psi.cc index 6688c0ed97..577349b595 100644 --- a/api/rama-plot-phi-psi.cc +++ b/api/rama-plot-phi-psi.cc @@ -30,11 +30,11 @@ rama_plot::util::get_phi_psi(mmdb::Residue *residue_0, mmdb::Residue *residue_1, residue_0->GetAtomTable(res_selection, nResidueAtoms); if (nResidueAtoms > 0) { for (int j=0; jname; + std::string atom_name = res_selection[j]->GetAtomName(); if (atom_name == " C ") { - c_prev = clipper::Coord_orth(res_selection[j]->x, - res_selection[j]->y, - res_selection[j]->z); + c_prev = clipper::Coord_orth(res_selection[j]->x(), + res_selection[j]->y(), + res_selection[j]->z()); natom++; } } @@ -44,23 +44,23 @@ rama_plot::util::get_phi_psi(mmdb::Residue *residue_0, mmdb::Residue *residue_1, residue_1->GetAtomTable(res_selection, nResidueAtoms); if (nResidueAtoms > 0) { for (int j=0; jname; + std::string atom_name = res_selection[j]->GetAtomName(); if (atom_name == " C ") { - c_this = clipper::Coord_orth(res_selection[j]->x, - res_selection[j]->y, - res_selection[j]->z); + c_this = clipper::Coord_orth(res_selection[j]->x(), + res_selection[j]->y(), + res_selection[j]->z()); natom++; } if (atom_name == " CA ") { - ca_this = clipper::Coord_orth(res_selection[j]->x, - res_selection[j]->y, - res_selection[j]->z); + ca_this = clipper::Coord_orth(res_selection[j]->x(), + res_selection[j]->y(), + res_selection[j]->z()); natom++; } if (atom_name == " N ") { - n_this = clipper::Coord_orth(res_selection[j]->x, - res_selection[j]->y, - res_selection[j]->z); + n_this = clipper::Coord_orth(res_selection[j]->x(), + res_selection[j]->y(), + res_selection[j]->z()); natom++; } } @@ -71,11 +71,11 @@ rama_plot::util::get_phi_psi(mmdb::Residue *residue_0, mmdb::Residue *residue_1, is_pre_pro = 1; if (nResidueAtoms > 0) { for (int j=0; jname; + std::string atom_name = res_selection[j]->GetAtomName(); if (atom_name == " N ") { - n_next = clipper::Coord_orth(res_selection[j]->x, - res_selection[j]->y, - res_selection[j]->z); + n_next = clipper::Coord_orth(res_selection[j]->x(), + res_selection[j]->y(), + res_selection[j]->z()); natom++; } } @@ -91,13 +91,13 @@ rama_plot::util::get_phi_psi(mmdb::Residue *residue_0, mmdb::Residue *residue_1, label += " "; label += segid; label += " "; - label += residue_1->name; + label += residue_1->GetResName(); double phi = clipper::Util::rad2d(ca_this.torsion(c_prev, n_this, ca_this, c_this)); double psi = clipper::Util::rad2d(ca_this.torsion(n_this, ca_this, c_this, n_next)); phi_psi = rama_plot::phi_psi_t(phi, psi, - residue_1->name, + residue_1->GetResName(), label.c_str(), ires, inscode, diff --git a/api/rigid-body-fit.cc b/api/rigid-body-fit.cc index 2cee9ae0f3..e64112ff8a 100644 --- a/api/rigid-body-fit.cc +++ b/api/rigid-body-fit.cc @@ -56,11 +56,11 @@ coot::api::rigid_body_fit(mmdb::Manager *mol, int udd_atom_selection_fitting_ato if (! at->isTer()) { std::string this_atom_name(at->GetAtomName()); if (moved_atoms_mol[ifrag][ires][iat].name == this_atom_name) { - std::string this_atom_alt_conf(at->altLoc); + std::string this_atom_alt_conf(at->altLoc()); if (this_atom_alt_conf == moved_atoms_mol[ifrag][ires][iat].altLoc) { - at->x = moved_atoms_mol[ifrag][ires][iat].pos.x(); - at->y = moved_atoms_mol[ifrag][ires][iat].pos.y(); - at->z = moved_atoms_mol[ifrag][ires][iat].pos.z(); + at->x() = moved_atoms_mol[ifrag][ires][iat].pos.x(); + at->y() = moved_atoms_mol[ifrag][ires][iat].pos.y(); + at->z() = moved_atoms_mol[ifrag][ires][iat].pos.z(); n_moved++; } } diff --git a/api/test-molecules-container.cc b/api/test-molecules-container.cc index 71a7a7c749..21c75afd9a 100644 --- a/api/test-molecules-container.cc +++ b/api/test-molecules-container.cc @@ -310,9 +310,9 @@ int test_auto_fit_rotamer_1(molecules_container_t &mc_in) { if (r) { mmdb::Atom *cz = r->GetAtom(" CZ "); if (cz) { - coot::Cartesian pt_1(cz->x, cz->y, cz->z); + coot::Cartesian pt_1(cz->x(), cz->y(), cz->z()); status = mc.auto_fit_rotamer(imol, "A", 61, "", "", imol_map); - coot::Cartesian pt_2(cz->x, cz->y, cz->z); + coot::Cartesian pt_2(cz->x(), cz->y(), cz->z()); double dd = coot::Cartesian::lengthsq(pt_1, pt_2); double d = std::sqrt(dd); std::cout << "d " << d << std::endl; @@ -398,9 +398,9 @@ int test_pepflips(molecules_container_t &mc) { coot::atom_spec_t atom_spec(res_spec.chain_id, res_spec.res_no, res_spec.ins_code, " O ",""); mmdb::Atom *at = mc.get_atom(imol, atom_spec); if (at) { - coot::Cartesian pt_1(at->x, at->y, at->z); + coot::Cartesian pt_1(at->x(), at->y(), at->z()); mc.flip_peptide(imol, atom_spec, ""); - coot::Cartesian pt_2(at->x, at->y, at->z); + coot::Cartesian pt_2(at->x(), at->y(), at->z()); double dd = coot::Cartesian::lengthsq(pt_1, pt_2); double d = std::sqrt(dd); std::cout << "debug:: in test_pepflips() for " << atom_spec << " d is " << d << std::endl; @@ -423,9 +423,9 @@ int test_pepflips(molecules_container_t &mc) { coot::atom_spec_t atom_spec_of_moving_O("A", 99, "", " O ", ""); mmdb::Atom *at = mc.get_atom(imol, atom_spec_of_moving_O); if (at) { - coot::Cartesian pt_1(at->x, at->y, at->z); + coot::Cartesian pt_1(at->x(), at->y(), at->z()); mc.flip_peptide_using_cid(imol, atom_cid, ""); - coot::Cartesian pt_2(at->x, at->y, at->z); + coot::Cartesian pt_2(at->x(), at->y(), at->z()); double dd = coot::Cartesian::lengthsq(pt_1, pt_2); double d = std::sqrt(dd); if (d > 3.0) { @@ -500,12 +500,12 @@ int test_undo_and_redo(molecules_container_t &mc) { std::string atom_cid = "//A/14/CA"; coot::atom_spec_t atom_spec("A", 14, "", " O ", ""); mmdb::Atom *at_1 = mc.get_atom(imol, atom_spec); - coot::Cartesian pt_1(at_1->x, at_1->y, at_1->z); + coot::Cartesian pt_1(at_1->x(), at_1->y(), at_1->z()); mc.flip_peptide_using_cid(imol, atom_cid, ""); - coot::Cartesian pt_2(at_1->x, at_1->y, at_1->z); + coot::Cartesian pt_2(at_1->x(), at_1->y(), at_1->z()); mc.undo(imol); // deletes atoms so now at_1 is out of date mmdb::Atom *at_2 = mc.get_atom(imol, atom_spec); - coot::Cartesian pt_3(at_2->x, at_2->y, at_2->z); + coot::Cartesian pt_3(at_2->x(), at_2->y(), at_2->z()); double dd_1 = coot::Cartesian::lengthsq(pt_1, pt_2); double dd_2 = coot::Cartesian::lengthsq(pt_1, pt_3); @@ -519,7 +519,7 @@ int test_undo_and_redo(molecules_container_t &mc) { // now let's test redo mc.redo(imol); // deletes atoms so now at_1 is out of date mmdb::Atom *at_3 = mc.get_atom(imol, atom_spec); - coot::Cartesian pt_4(at_3->x, at_3->y, at_3->z); + coot::Cartesian pt_4(at_3->x(), at_3->y(), at_3->z()); // modified and redone should be the same: double dd_3 = coot::Cartesian::lengthsq(pt_2, pt_4); double d_3 = std::sqrt(dd_3); @@ -531,16 +531,16 @@ int test_undo_and_redo(molecules_container_t &mc) { coot::atom_spec_t atom_spec_b("A", 24, "", " O ", ""); mmdb::Atom *at_5 = mc.get_atom(imol, atom_spec_b); - coot::Cartesian pt_5(at_5->x, at_5->y, at_5->z); + coot::Cartesian pt_5(at_5->x(), at_5->y(), at_5->z()); mc.flip_peptide_using_cid(imol, "//A/24/CA", ""); mmdb::Atom *at_6 = mc.get_atom(imol, atom_spec_b); - coot::Cartesian pt_6(at_6->x, at_6->y, at_6->z); + coot::Cartesian pt_6(at_6->x(), at_6->y(), at_6->z()); mc.undo(imol); mmdb::Atom *at_7 = mc.get_atom(imol, atom_spec_b); - coot::Cartesian pt_7(at_7->x, at_7->y, at_7->z); + coot::Cartesian pt_7(at_7->x(), at_7->y(), at_7->z()); mc.redo(imol); mmdb::Atom *at_8 = mc.get_atom(imol, atom_spec_b); - coot::Cartesian pt_8(at_8->x, at_8->y, at_8->z); + coot::Cartesian pt_8(at_8->x(), at_8->y(), at_8->z()); if (true) { // debugging std::cout << "pt_4 " << pt_4 << std::endl; @@ -576,17 +576,17 @@ int test_undo_and_redo_2(molecules_container_t &mc) { coot::atom_spec_t atom_spec("A", 61, "", " CZ ", ""); mmdb::Atom *at_1 = mc.get_atom(imol, atom_spec); if (at_1) { - coot::Cartesian pt_1(at_1->x, at_1->y, at_1->z); + coot::Cartesian pt_1(at_1->x(), at_1->y(), at_1->z()); int status_af = mc.auto_fit_rotamer(imol, "A", 61, "", "", imol_map); if (status_af == 1) { - coot::Cartesian pt_2(at_1->x, at_1->y, at_1->z); + coot::Cartesian pt_2(at_1->x(), at_1->y(), at_1->z()); double dd = coot::Cartesian::lengthsq(pt_1, pt_2); double d = std::sqrt(dd); if (d > 6.0) { // OK, it moved (fitted) mc.undo(imol); mmdb::Atom *at_3 = mc.get_atom(imol, atom_spec); - coot::Cartesian pt_3(at_3->x, at_3->y, at_3->z); + coot::Cartesian pt_3(at_3->x(), at_3->y(), at_3->z()); dd = coot::Cartesian::lengthsq(pt_1, pt_3); d = std::sqrt(dd); std::cout << "debug:: in test_undo_and_redo_2() d " << d << std::endl; @@ -631,7 +631,7 @@ int test_set_residue_to_rotamer_number(molecules_container_t &mc) { mc.close_molecule(imol); return status; } - coot::Cartesian pos_start = coot::Cartesian(at_start->x, at_start->y, at_start->z); + coot::Cartesian pos_start = coot::Cartesian(at_start->x(), at_start->y(), at_start->z()); int result = mc.set_residue_to_rotamer_number(imol, residue_cid, alt_conf, rotamer_number); @@ -642,7 +642,7 @@ int test_set_residue_to_rotamer_number(molecules_container_t &mc) { mc.close_molecule(imol); return status; } - coot::Cartesian pos_end = coot::Cartesian(at_end->x, at_end->y, at_end->z); + coot::Cartesian pos_end = coot::Cartesian(at_end->x(), at_end->y(), at_end->z()); double dist_moved = std::sqrt(coot::Cartesian::lengthsq(pos_start, pos_end)); std::cout << "CG atom moved " << dist_moved << " Å by set_residue_to_rotamer_number()" << std::endl; @@ -1211,9 +1211,9 @@ int test_crowther_rotation_with_model(molecules_container_t &mc) { int n_atoms; mol->GetSelIndex(SelHnd, sel_atoms, n_atoms); for (int i=0; ix += shift.x(); - sel_atoms[i]->y += shift.y(); - sel_atoms[i]->z += shift.z(); + sel_atoms[i]->x() += shift.x(); + sel_atoms[i]->y() += shift.y(); + sel_atoms[i]->z() += shift.z(); } std::cout << "INFO:: model centre: " << mol_centre.second.format() @@ -1439,9 +1439,9 @@ int test_crowther_rotation_with_model(molecules_container_t &mc) { int na2; mol2->GetSelIndex(sel2, atoms2, na2); for (int i=0; ix += cc2.x() - mc2.second.x(); - atoms2[i]->y += cc2.y() - mc2.second.y(); - atoms2[i]->z += cc2.z() - mc2.second.z(); + atoms2[i]->x() += cc2.x() - mc2.second.x(); + atoms2[i]->y() += cc2.y() - mc2.second.y(); + atoms2[i]->z() += cc2.z() - mc2.second.z(); } clipper::Xmap model_map2 = coot::util::calc_atom_map(mol2, sel2, cell2, spacegroup, gs2); mol2->DeleteSelection(sel2); @@ -1588,9 +1588,9 @@ int test_phased_translation_function(molecules_container_t &mc) { int n_atoms; mol->GetSelIndex(SelHnd, sel_atoms, n_atoms); for (int i=0; ix += shift.x(); - sel_atoms[i]->y += shift.y(); - sel_atoms[i]->z += shift.z(); + sel_atoms[i]->x() += shift.x(); + sel_atoms[i]->y() += shift.y(); + sel_atoms[i]->z() += shift.z(); } // Compute atom map for the model, extract fragment @@ -1630,26 +1630,26 @@ int test_phased_translation_function(molecules_container_t &mc) { // Shift model back to origin (undo the cell-centre shift) for (int i=0; ix -= shift.x(); - sel_atoms[i]->y -= shift.y(); - sel_atoms[i]->z -= shift.z(); + sel_atoms[i]->x() -= shift.x(); + sel_atoms[i]->y() -= shift.y(); + sel_atoms[i]->z() -= shift.z(); } // Now centre at the true origin clipper::Coord_orth mc2 = mol_centre.second; for (int i=0; ix -= mc2.x(); - sel_atoms[i]->y -= mc2.y(); - sel_atoms[i]->z -= mc2.z(); + sel_atoms[i]->x() -= mc2.x(); + sel_atoms[i]->y() -= mc2.y(); + sel_atoms[i]->z() -= mc2.z(); } // Apply the rotation glm::mat3 rot_mat = glm::mat3_cast(best_rotation); for (int i=0; ix, sel_atoms[i]->y, sel_atoms[i]->z); + glm::vec3 pos(sel_atoms[i]->x(), sel_atoms[i]->y(), sel_atoms[i]->z()); glm::vec3 rotated = rot_mat * pos; - sel_atoms[i]->x = rotated.x; - sel_atoms[i]->y = rotated.y; - sel_atoms[i]->z = rotated.z; + sel_atoms[i]->x() = rotated.x; + sel_atoms[i]->y() = rotated.y; + sel_atoms[i]->z() = rotated.z; } std::cout << "INFO:: model centred at origin and rotated, n_atoms=" << n_atoms << std::endl; @@ -1787,7 +1787,7 @@ int test_molecular_placement_pipeline(molecules_container_t &mc) { for (int i=0; iGetAtomName()); if (aname == " CA " || aname == "CA") - ca_coords.push_back(clipper::Coord_orth(atoms[i]->x, atoms[i]->y, atoms[i]->z)); + ca_coords.push_back(clipper::Coord_orth(atoms[i]->x(), atoms[i]->y(), atoms[i]->z())); } mol_p->DeleteSelection(sel); return ca_coords; @@ -1931,7 +1931,7 @@ int test_molecular_placement_pipeline_r_chain(molecules_container_t &mc) { for (int i=0; iGetAtomName()); if (aname == " CA " || aname == "CA") - ca_coords.push_back(clipper::Coord_orth(atoms[i]->x, atoms[i]->y, atoms[i]->z)); + ca_coords.push_back(clipper::Coord_orth(atoms[i]->x(), atoms[i]->y(), atoms[i]->z())); } mol_p->DeleteSelection(sel); return ca_coords; @@ -2123,7 +2123,7 @@ int test_delete_residue(molecules_container_t &mc) { coot::Cartesian atom_to_cartesian(mmdb::Atom *at) { - return coot::Cartesian(at->x, at->y, at->z); + return coot::Cartesian(at->x(), at->y(), at->z()); } @@ -2342,20 +2342,20 @@ int test_rsr_using_multi_atom_cid(molecules_container_t &mc) { mmdb::Atom *at_1 = residue_p_1->GetAtom(iat); if (! at_1->isTer()) { std::string atom_name_1(at_1->GetAtomName()); - std::string alt_conf_1(at_1->altLoc); + std::string alt_conf_1(at_1->altLoc()); int n_atoms_2 = residue_p_2->GetNumberOfAtoms(); for (int jat=0; jatGetAtom(jat); if (! at_2->isTer()) { std::string atom_name_2(at_2->GetAtomName()); - std::string alt_conf_2(at_2->altLoc); + std::string alt_conf_2(at_2->altLoc()); if (atom_name_1 == atom_name_2) { if (alt_conf_1 == alt_conf_2) { n_checked++; - float dx = at_1->x - at_2->x; - float dy = at_1->y - at_2->y; - float dz = at_1->z - at_2->z; + float dx = at_1->x() - at_2->x(); + float dy = at_1->y() - at_2->y(); + float dz = at_1->z() - at_2->z(); if ((fabsf(dx) + fabsf(dy) + fabsf(dz)) > 0.01) n_diffs++; } @@ -2406,7 +2406,7 @@ int test_rsr_using_multi_atom_cid(molecules_container_t &mc) { int test_add_terminal_residue(molecules_container_t &mc) { auto mmdb_to_cartesian = [] (mmdb::Atom *at) { - return coot::Cartesian(at->x, at->y, at->z); + return coot::Cartesian(at->x(), at->y(), at->z()); }; auto glm_to_cartesian = [] (const glm::vec3 &gp) { @@ -4351,7 +4351,7 @@ int test_add_alt_conf(molecules_container_t &mc) { for (int iat=0; iatisTer()) { - std::cout << iat << " " << coot::atom_spec_t(at) << " " << at->x << " " << at->y << " " << at->z << std::endl; + std::cout << iat << " " << coot::atom_spec_t(at) << " " << at->x() << " " << at->y() << " " << at->z() << std::endl; } } if (n_residue_atoms > 22) @@ -6528,11 +6528,11 @@ int test_mask_atom_selection(molecules_container_t &mc) { if (n_selected_atoms > 0) { for (int i=0; ix, at->y, at->z); + clipper::Coord_orth pos(at->x(), at->y(), at->z()); std::cout << "in test_mask_atom_selection() found atom " << at->GetResName() << " " << at->GetSeqNum() << " " << ":" << at->GetAtomName() << ": " << pos.format() << std::endl; - float f = mc.get_density_at_position(imol_masked, at->x, at->y, at-> z); + float f = mc.get_density_at_position(imol_masked, at->x(), at->y(), at-> z()); if (f < 0.00001) { status = 1; } @@ -6589,7 +6589,7 @@ int test_B_factor_multiply(molecules_container_t &mc) { for (int iat=0; iatisTer()) { - B_pre.push_back(at->tempFactor); + B_pre.push_back(at->tempFactor()); } } @@ -6601,7 +6601,7 @@ int test_B_factor_multiply(molecules_container_t &mc) { for (int iat=0; iatisTer()) { - B_post.push_back(at->tempFactor); + B_post.push_back(at->tempFactor()); } } } @@ -6789,7 +6789,7 @@ int test_shiftfield_b_factor_refinement(molecules_container_t &mc) { for (int iat=0; iatisTer()) { - sum += at->tempFactor; + sum += at->tempFactor(); count++; } } @@ -7707,7 +7707,7 @@ int test_set_occupancy(molecules_container_t &mc) { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - if (at->occupancy < 0.00001) n_zero++; + if (at->occupancy() < 0.00001) n_zero++; } } } diff --git a/coords/Bond_lines.cc b/coords/Bond_lines.cc index 2686d4d34d..19874f1f27 100644 --- a/coords/Bond_lines.cc +++ b/coords/Bond_lines.cc @@ -515,14 +515,14 @@ Bond_lines_container::construct_from_atom_selection(const atom_selection_contain std::string chain_id1(atom_p_1->GetChainID()); std::string chain_id2(atom_p_2->GetChainID()); - std::string aloc_1(atom_p_1->altLoc); - std::string aloc_2(atom_p_2->altLoc); + std::string aloc_1(atom_p_1->altLoc()); + std::string aloc_2(atom_p_2->altLoc()); - element_1 = atom_p_1->element; - element_2 = atom_p_2->element; + element_1 = atom_p_1->GetElementName(); + element_2 = atom_p_2->GetElementName(); - coot::Cartesian atom_1_pos(atom_p_1->x, atom_p_1->y, atom_p_1->z); - coot::Cartesian atom_2_pos(atom_p_2->x, atom_p_2->y, atom_p_2->z); + coot::Cartesian atom_1_pos(atom_p_1->x(), atom_p_1->y(), atom_p_1->z()); + coot::Cartesian atom_2_pos(atom_p_2->x(), atom_p_2->y(), atom_p_2->z()); if (chain_id1 == chain_id2) { @@ -553,7 +553,7 @@ Bond_lines_container::construct_from_atom_selection(const atom_selection_contain if (labs(res_1 - res_2) < 2) is_neighbour = true; if (! is_neighbour) - if (labs(atom_p_1->residue->index - atom_p_2->residue->index) < 2) + if (labs(atom_p_1->GetResidue()->GetIndex() - atom_p_2->GetResidue()->GetIndex()) < 2) is_neighbour = true; // Maybe DUM-DUM needs it's own bonding selection and drawing function @@ -701,11 +701,11 @@ Bond_lines_container::construct_from_atom_selection(const atom_selection_contain // should this test be here or further up? // Don't bond water Oxygens to each other... 20210817-PE - or anything else. bool do_it = true; - if (atom_p_1->residue != atom_p_2->residue) { - std::string res_name_1(atom_p_1->residue->GetResName()); + if (atom_p_1->GetResidue() != atom_p_2->GetResidue()) { + std::string res_name_1(atom_p_1->GetResidue()->GetResName()); if (res_name_1 == "HOH") do_it = false; - std::string res_name_2(atom_p_2->residue->GetResName()); + std::string res_name_2(atom_p_2->GetResidue()->GetResName()); if (res_name_2 == "HOH") do_it = false; } @@ -766,15 +766,15 @@ Bond_lines_container::add_bond_by_dictionary_maybe(int imol, bool bond_het_residue_by_dictionary = false; if (have_dictionary && geom) - if (atom_p_1->residue == atom_p_2->residue) + if (atom_p_1->GetResidue() == atom_p_2->GetResidue()) if (atom_p_1->Het) if (atom_p_2->Het) { // Have we checked this residue type before and failed to find // a dictionary for it? If so, add it to the vector. - std::pair tp0(0, atom_p_1->residue); - std::pair tp1(1, atom_p_1->residue); + std::pair tp0(0, atom_p_1->GetResidue()); + std::pair tp1(1, atom_p_1->GetResidue()); // add this residue to the vector if it is not there already) // @@ -792,9 +792,9 @@ Bond_lines_container::add_bond_by_dictionary_maybe(int imol, if (it_2 == het_residues->end()) { - if (geom->have_at_least_minimal_dictionary_for_residue_type(atom_p_1->residue->GetResName(), imol)) { + if (geom->have_at_least_minimal_dictionary_for_residue_type(atom_p_1->GetResidue()->GetResName(), imol)) { - if (geom->atoms_match_dictionary(imol, atom_p_1->residue, true, true).first) { + if (geom->atoms_match_dictionary(imol, atom_p_1->GetResidue(), true, true).first) { het_residues->push_back(tp1); bond_het_residue_by_dictionary = true; @@ -828,23 +828,23 @@ Bond_lines_container::mark_atoms_as_bonded(mmdb::Atom *atom_p_1, mmdb::Atom *ato // if (have_udd_atoms) { if (! done_bond_udd_handle) { // already happened for bonds to Hs. - if (! ((!strcmp(atom_p_1->element, " S")) || - (!strcmp(atom_p_1->element, "SE")) || - (!strcmp(atom_p_1->element, "CL")) || - (!strcmp(atom_p_1->element, "BR")) || - (!strcmp(atom_p_1->element, "Cl")) || - (!strcmp(atom_p_1->element, "Br")) || - (!strcmp(atom_p_1->element, " P")))) { + if (! ((!strcmp(atom_p_1->GetElementName(), " S")) || + (!strcmp(atom_p_1->GetElementName(), "SE")) || + (!strcmp(atom_p_1->GetElementName(), "CL")) || + (!strcmp(atom_p_1->GetElementName(), "BR")) || + (!strcmp(atom_p_1->GetElementName(), "Cl")) || + (!strcmp(atom_p_1->GetElementName(), "Br")) || + (!strcmp(atom_p_1->GetElementName(), " P")))) { atom_p_1->PutUDData(udd_handle, graphical_bonds_container::BONDED_WITH_STANDARD_ATOM_BOND); } - if (! ((!strcmp(atom_p_2->element, " S")) || - (!strcmp(atom_p_2->element, "SE")) || - (!strcmp(atom_p_2->element, "CL")) || - (!strcmp(atom_p_2->element, "BR")) || - (!strcmp(atom_p_2->element, "Cl")) || - (!strcmp(atom_p_2->element, "Br")) || - (!strcmp(atom_p_2->element, " P")))) { + if (! ((!strcmp(atom_p_2->GetElementName(), " S")) || + (!strcmp(atom_p_2->GetElementName(), "SE")) || + (!strcmp(atom_p_2->GetElementName(), "CL")) || + (!strcmp(atom_p_2->GetElementName(), "BR")) || + (!strcmp(atom_p_2->GetElementName(), "Cl")) || + (!strcmp(atom_p_2->GetElementName(), "Br")) || + (!strcmp(atom_p_2->GetElementName(), " P")))) { atom_p_2->PutUDData(udd_handle, graphical_bonds_container::BONDED_WITH_STANDARD_ATOM_BOND); } } @@ -873,8 +873,8 @@ Bond_lines_container::add_half_bonds(const coot::Cartesian &atom_1_pos, // (dashed bonds are not double by nature) // graphics_line_t::cylinder_class_t cc = graphics_line_t::SINGLE; - mmdb::Residue *residue_p_1 = at_1->residue; - mmdb::Residue *residue_p_2 = at_2->residue; + mmdb::Residue *residue_p_1 = at_1->GetResidue(); + mmdb::Residue *residue_p_2 = at_2->GetResidue(); // is this slow? if so, pass it. // int udd_user_defined_atom_colour_index_handle = asc.mol->GetUDDHandle(mmdb::UDR_ATOM, "user-defined-atom-colour-index"); @@ -904,8 +904,8 @@ Bond_lines_container::draw_bonded_quad_atoms_rings(const std::vectorx, bq.atom_2->y, bq.atom_2->z); - coot::Cartesian p3(bq.atom_3->x, bq.atom_3->y, bq.atom_3->z); + coot::Cartesian p2(bq.atom_2->x(), bq.atom_2->y(), bq.atom_2->z()); + coot::Cartesian p3(bq.atom_3->x(), bq.atom_3->y(), bq.atom_3->z()); int atom_2_index = -1; int atom_3_index = -1; bq.atom_2->GetUDData(udd_atom_index_handle, atom_2_index); @@ -913,8 +913,8 @@ Bond_lines_container::draw_bonded_quad_atoms_rings(const std::vectorelement); - std::string ele_3(at_3->element); + std::string ele_2(at_2->GetElementName()); + std::string ele_3(at_3->GetElementName()); // std::cout << "ring quad " << i << " " << bq << " has bond_type " << bq.bond_type << std::endl; @@ -941,10 +941,10 @@ Bond_lines_container::draw_bonded_quad_atoms_rings(const std::vectorx, bq.atom_1->y, bq.atom_1->z); - coot::Cartesian pt_1(bq.atom_2->x, bq.atom_2->y, bq.atom_2->z); - coot::Cartesian pt_2(bq.atom_3->x, bq.atom_3->y, bq.atom_3->z); - coot::Cartesian pt_3(bq.atom_4->x, bq.atom_4->y, bq.atom_4->z); + coot::Cartesian pt_0(bq.atom_1->x(), bq.atom_1->y(), bq.atom_1->z()); + coot::Cartesian pt_1(bq.atom_2->x(), bq.atom_2->y(), bq.atom_2->z()); + coot::Cartesian pt_2(bq.atom_3->x(), bq.atom_3->y(), bq.atom_3->z()); + coot::Cartesian pt_3(bq.atom_4->x(), bq.atom_4->y(), bq.atom_4->z()); coot::Cartesian mp = pt_0.mid_point(pt_3); // doesn't work for cyclopropane coot::Cartesian v1 = pt_1 - mp; @@ -1015,10 +1015,10 @@ Bond_lines_container::draw_trp_rings(const std::vector &ring_atoms int col = atom_colour(at_1, atom_colour_type, udd_user_defined_atom_colour_index_handle, atom_colour_map_p); int atom_1_index = -1; int atom_2_index = -1; - coot::Cartesian p1(ring_atoms[iat]->x, ring_atoms[iat]->y, ring_atoms[iat]->z); - coot::Cartesian p2(ring_atoms[jat]->x, ring_atoms[jat]->y, ring_atoms[jat]->z); - std::string ele_1(at_1->element); - std::string ele_2(at_2->element); + coot::Cartesian p1(ring_atoms[iat]->x(), ring_atoms[iat]->y(), ring_atoms[iat]->z()); + coot::Cartesian p2(ring_atoms[jat]->x(), ring_atoms[jat]->y(), ring_atoms[jat]->z()); + std::string ele_1(at_1->GetElementName()); + std::string ele_2(at_2->GetElementName()); if (ele_1 == ele_2) { ring_atoms[iat]->GetUDData(udd_atom_index_handle, atom_1_index); ring_atoms[jat]->GetUDData(udd_atom_index_handle, atom_2_index); @@ -1042,10 +1042,10 @@ Bond_lines_container::draw_trp_rings(const std::vector &ring_atoms // find the mid point of atom 0 and 3. the innner bond ends will be on the vector from there to // atoms 1 and 2. - coot::Cartesian pt_0(ring_atoms[iat_0]->x, ring_atoms[iat_0]->y, ring_atoms[iat_0]->z); - coot::Cartesian pt_1(ring_atoms[iat_1]->x, ring_atoms[iat_1]->y, ring_atoms[iat_1]->z); - coot::Cartesian pt_2(ring_atoms[iat_2]->x, ring_atoms[iat_2]->y, ring_atoms[iat_2]->z); - coot::Cartesian pt_3(ring_atoms[iat_3]->x, ring_atoms[iat_3]->y, ring_atoms[iat_3]->z); + coot::Cartesian pt_0(ring_atoms[iat_0]->x(), ring_atoms[iat_0]->y(), ring_atoms[iat_0]->z()); + coot::Cartesian pt_1(ring_atoms[iat_1]->x(), ring_atoms[iat_1]->y(), ring_atoms[iat_1]->z()); + coot::Cartesian pt_2(ring_atoms[iat_2]->x(), ring_atoms[iat_2]->y(), ring_atoms[iat_2]->z()); + coot::Cartesian pt_3(ring_atoms[iat_3]->x(), ring_atoms[iat_3]->y(), ring_atoms[iat_3]->z()); coot::Cartesian mp = pt_0.mid_point(pt_3); coot::Cartesian v1 = pt_1 - mp; @@ -1059,8 +1059,8 @@ Bond_lines_container::draw_trp_rings(const std::vector &ring_atoms int atom_2_index = -1; ring_atoms[iat_1]->GetUDData(udd_atom_index_handle, atom_1_index); ring_atoms[iat_2]->GetUDData(udd_atom_index_handle, atom_2_index); - std::string ele_1(at_1->element); - std::string ele_2(at_2->element); + std::string ele_1(at_1->GetElementName()); + std::string ele_2(at_2->GetElementName()); graphics_line_t::cylinder_class_t cc = graphics_line_t::KEK_DOUBLE_BOND_INNER_BOND; if (ele_1 == ele_2) { bool add_end_cap = true; @@ -1094,7 +1094,7 @@ Bond_lines_container::draw_GA_rings(const std::vector &ring_atoms, for (unsigned int i=0; iresidue->GetResName(); + std::string rt = ring_atoms[0]->GetResidue()->GetResName(); // single bonds std::vector > vp_single; @@ -1128,10 +1128,10 @@ Bond_lines_container::draw_GA_rings(const std::vector &ring_atoms, int col = atom_colour(at_1, atom_colour_type, udd_user_defined_atom_colour_index_handle, atom_colour_map_p); int atom_1_index = -1; int atom_2_index = -1; - coot::Cartesian p1(ring_atoms[iat]->x, ring_atoms[iat]->y, ring_atoms[iat]->z); - coot::Cartesian p2(ring_atoms[jat]->x, ring_atoms[jat]->y, ring_atoms[jat]->z); - std::string ele_1(at_1->element); - std::string ele_2(at_2->element); + coot::Cartesian p1(ring_atoms[iat]->x(), ring_atoms[iat]->y(), ring_atoms[iat]->z()); + coot::Cartesian p2(ring_atoms[jat]->x(), ring_atoms[jat]->y(), ring_atoms[jat]->z()); + std::string ele_1(at_1->GetElementName()); + std::string ele_2(at_2->GetElementName()); graphics_line_t::cylinder_class_t cc = graphics_line_t::SINGLE; if (ele_1 == ele_2) { ring_atoms[iat]->GetUDData(udd_atom_index_handle, atom_1_index); @@ -1153,10 +1153,10 @@ Bond_lines_container::draw_GA_rings(const std::vector &ring_atoms, // find the mid point of atom 0 and 3. the innner bond ends will be on the vector from there to // atoms 1 and 2. - coot::Cartesian pt_0(ring_atoms[iat_0]->x, ring_atoms[iat_0]->y, ring_atoms[iat_0]->z); - coot::Cartesian pt_1(ring_atoms[iat_1]->x, ring_atoms[iat_1]->y, ring_atoms[iat_1]->z); - coot::Cartesian pt_2(ring_atoms[iat_2]->x, ring_atoms[iat_2]->y, ring_atoms[iat_2]->z); - coot::Cartesian pt_3(ring_atoms[iat_3]->x, ring_atoms[iat_3]->y, ring_atoms[iat_3]->z); + coot::Cartesian pt_0(ring_atoms[iat_0]->x(), ring_atoms[iat_0]->y(), ring_atoms[iat_0]->z()); + coot::Cartesian pt_1(ring_atoms[iat_1]->x(), ring_atoms[iat_1]->y(), ring_atoms[iat_1]->z()); + coot::Cartesian pt_2(ring_atoms[iat_2]->x(), ring_atoms[iat_2]->y(), ring_atoms[iat_2]->z()); + coot::Cartesian pt_3(ring_atoms[iat_3]->x(), ring_atoms[iat_3]->y(), ring_atoms[iat_3]->z()); coot::Cartesian mp = pt_0.mid_point(pt_3); coot::Cartesian v1 = pt_1 - mp; @@ -1170,8 +1170,8 @@ Bond_lines_container::draw_GA_rings(const std::vector &ring_atoms, int atom_2_index = -1; ring_atoms[iat_1]->GetUDData(udd_atom_index_handle, atom_1_index); ring_atoms[iat_2]->GetUDData(udd_atom_index_handle, atom_2_index); - std::string ele_1(at_1->element); - std::string ele_2(at_2->element); + std::string ele_1(at_1->GetElementName()); + std::string ele_2(at_2->GetElementName()); graphics_line_t::cylinder_class_t cc = graphics_line_t::KEK_DOUBLE_BOND_INNER_BOND; if (ele_1 == ele_2) { addBond(col, ip1, ip2, cc, imodel, atom_1_index, atom_2_index, true, true); @@ -1202,10 +1202,10 @@ Bond_lines_container::draw_6_membered_ring(const std::string &residue_name, if (iat == 5) jat = 0; mmdb::Atom *at_1 = ring_atoms[iat]; mmdb::Atom *at_2 = ring_atoms[jat]; - std::string ele_1(at_1->element); - std::string ele_2(at_2->element); - coot::Cartesian p1(ring_atoms[iat]->x, ring_atoms[iat]->y, ring_atoms[iat]->z); - coot::Cartesian p2(ring_atoms[jat]->x, ring_atoms[jat]->y, ring_atoms[jat]->z); + std::string ele_1(at_1->GetElementName()); + std::string ele_2(at_2->GetElementName()); + coot::Cartesian p1(ring_atoms[iat]->x(), ring_atoms[iat]->y(), ring_atoms[iat]->z()); + coot::Cartesian p2(ring_atoms[jat]->x(), ring_atoms[jat]->y(), ring_atoms[jat]->z()); int atom_1_index = -1; int atom_2_index = -1; ring_atoms[iat]->GetUDData(udd_atom_index_handle, atom_1_index); @@ -1254,10 +1254,10 @@ Bond_lines_container::draw_6_membered_ring(const std::string &residue_name, // find the mid point of atom 0 and 3. the innner bond ends will be on the vector from thre to // atoms 1 and 2. - coot::Cartesian pt_0(ring_atoms[iat_0]->x, ring_atoms[iat_0]->y, ring_atoms[iat_0]->z); - coot::Cartesian pt_1(ring_atoms[iat_1]->x, ring_atoms[iat_1]->y, ring_atoms[iat_1]->z); - coot::Cartesian pt_2(ring_atoms[iat_2]->x, ring_atoms[iat_2]->y, ring_atoms[iat_2]->z); - coot::Cartesian pt_3(ring_atoms[iat_3]->x, ring_atoms[iat_3]->y, ring_atoms[iat_3]->z); + coot::Cartesian pt_0(ring_atoms[iat_0]->x(), ring_atoms[iat_0]->y(), ring_atoms[iat_0]->z()); + coot::Cartesian pt_1(ring_atoms[iat_1]->x(), ring_atoms[iat_1]->y(), ring_atoms[iat_1]->z()); + coot::Cartesian pt_2(ring_atoms[iat_2]->x(), ring_atoms[iat_2]->y(), ring_atoms[iat_2]->z()); + coot::Cartesian pt_3(ring_atoms[iat_3]->x(), ring_atoms[iat_3]->y(), ring_atoms[iat_3]->z()); coot::Cartesian mp = pt_0.mid_point(pt_3); coot::Cartesian v1 = pt_1 - mp; @@ -1266,8 +1266,8 @@ Bond_lines_container::draw_6_membered_ring(const std::string &residue_name, coot::Cartesian ip2 = mp + v2 * 0.78; mmdb::Atom *at_1 = ring_atoms[iat_1]; mmdb::Atom *at_2 = ring_atoms[iat_2]; - std::string ele_1(at_1->element); - std::string ele_2(at_2->element); + std::string ele_1(at_1->GetElementName()); + std::string ele_2(at_2->GetElementName()); int atom_1_index = -1; int atom_2_index = -1; ring_atoms[iat_1]->GetUDData(udd_atom_index_handle, atom_1_index); @@ -1299,8 +1299,8 @@ Bond_lines_container::add_double_bond(int imol, int imodel, int iat_1, int iat_2 const std::vector &bond_restraints, bool is_deloc) { - std::string ele_1 = residue_atoms[iat_1]->element; - std::string ele_2 = residue_atoms[iat_2]->element; + std::string ele_1 = residue_atoms[iat_1]->GetElementName(); + std::string ele_2 = residue_atoms[iat_2]->GetElementName(); graphics_line_t::cylinder_class_t cc = graphics_line_t::DOUBLE; @@ -1315,8 +1315,8 @@ Bond_lines_container::add_double_bond(int imol, int imodel, int iat_1, int iat_2 // perp_n is the direction of the offset (from the atom position) of the start and // finish points in the plane of the double bond. // - clipper::Coord_orth pos_at_1(residue_atoms[iat_1]->x, residue_atoms[iat_1]->y, residue_atoms[iat_1]->z); - clipper::Coord_orth pos_at_2(residue_atoms[iat_2]->x, residue_atoms[iat_2]->y, residue_atoms[iat_2]->z); + clipper::Coord_orth pos_at_1(residue_atoms[iat_1]->x(), residue_atoms[iat_1]->y(), residue_atoms[iat_1]->z()); + clipper::Coord_orth pos_at_2(residue_atoms[iat_2]->x(), residue_atoms[iat_2]->y(), residue_atoms[iat_2]->z()); clipper::Coord_orth n_n = get_neighb_normal(imol, iat_1, iat_2, residue_atoms, n_residue_atoms); clipper::Coord_orth b(pos_at_1 - pos_at_2); clipper::Coord_orth b_n(b.unit()); @@ -1380,11 +1380,11 @@ Bond_lines_container::add_triple_bond(int imol, int imodel, int iat_1, int iat_2 graphics_line_t::cylinder_class_t cc = graphics_line_t::TRIPLE; // - std::string ele_1 = atoms[iat_1]->element; - std::string ele_2 = atoms[iat_2]->element; + std::string ele_1 = atoms[iat_1]->GetElementName(); + std::string ele_2 = atoms[iat_2]->GetElementName(); - mmdb::Residue *residue_p_1 = atoms[iat_1]->residue; - mmdb::Residue *residue_p_2 = atoms[iat_2]->residue; + mmdb::Residue *residue_p_1 = atoms[iat_1]->GetResidue(); + mmdb::Residue *residue_p_2 = atoms[iat_2]->GetResidue(); try { @@ -1399,8 +1399,8 @@ Bond_lines_container::add_triple_bond(int imol, int imodel, int iat_1, int iat_2 bool also_2nd_order = 1; // because linear nature of bonds to // atoms in triple bond means we need // more atoms. - clipper::Coord_orth pos_at_1(atoms[iat_1]->x, atoms[iat_1]->y, atoms[iat_1]->z); - clipper::Coord_orth pos_at_2(atoms[iat_2]->x, atoms[iat_2]->y, atoms[iat_2]->z); + clipper::Coord_orth pos_at_1(atoms[iat_1]->x(), atoms[iat_1]->y(), atoms[iat_1]->z()); + clipper::Coord_orth pos_at_2(atoms[iat_2]->x(), atoms[iat_2]->y(), atoms[iat_2]->z()); clipper::Coord_orth n_n = get_neighb_normal(imol, iat_1, iat_2, atoms, n_atoms, also_2nd_order); clipper::Coord_orth b(pos_at_1 - pos_at_2); clipper::Coord_orth b_n(b.unit()); @@ -1450,9 +1450,9 @@ Bond_lines_container::get_neighb_normal(int imol, int iat_1, int iat_2, mmdb::PP clipper::Coord_orth pt(0,0,0); if (have_dictionary) { - std::string rn = atoms[iat_1]->residue->GetResName(); - std::string at_n_1 = atoms[iat_1]->name; - std::string at_n_2 = atoms[iat_2]->name; + std::string rn = atoms[iat_1]->GetResidue()->GetResName(); + std::string at_n_1 = atoms[iat_1]->GetAtomName(); + std::string at_n_2 = atoms[iat_2]->GetAtomName(); std::vector neighbours = geom->get_bonded_neighbours(rn, imol, at_n_1, at_n_2, also_2nd_order_neighbs_flag); @@ -1462,14 +1462,14 @@ Bond_lines_container::get_neighb_normal(int imol, int iat_1, int iat_2, mmdb::PP std::cout << " " << neighbours[i] << std::endl; } - std::string alt_conf_bond = atoms[iat_1]->altLoc; // same as iat_2 by the time we get here, I think + std::string alt_conf_bond = atoms[iat_1]->altLoc(); // same as iat_2 by the time we get here, I think if (neighbours.size() > 2) { std::vector neighb_atoms; for (unsigned int i=0; iname; + std::string atom_name = atoms[j]->GetAtomName(); if (neighbours[i] == atom_name) { - std::string alt_conf_atom = atoms[j]->altLoc; + std::string alt_conf_atom = atoms[j]->altLoc(); if (alt_conf_atom == alt_conf_bond) { // only add them if they are not there already (belt and braces test) if (std::find(neighb_atoms.begin(), neighb_atoms.end(), atoms[j]) == @@ -1485,15 +1485,15 @@ Bond_lines_container::get_neighb_normal(int imol, int iat_1, int iat_2, mmdb::PP std::vector neighb_atoms_pos(neighb_atoms.size()); for (unsigned int i=0; ix, - neighb_atoms[i]->y, - neighb_atoms[i]->z); + neighb_atoms_pos[i] = clipper::Coord_orth(neighb_atoms[i]->x(), + neighb_atoms[i]->y(), + neighb_atoms[i]->z()); coot::lsq_plane_info_t lp(neighb_atoms_pos); pt = lp.normal(); } } else { std::string m = "Not enough atoms to determine orientation of "; - m += atoms[iat_1]->residue->GetResName(); + m += atoms[iat_1]->GetResidue()->GetResName(); m += " - dictionary bonding fails"; m += " found "; m += coot::util::int_to_string(neighbours.size()); @@ -1509,7 +1509,7 @@ Bond_lines_container::get_neighb_normal(int imol, int iat_1, int iat_2, mmdb::PP } else { // this should not happend std::string m = "No dictionary for "; - m += atoms[iat_1]->residue->GetResName(); + m += atoms[iat_1]->GetResidue()->GetResName(); m += " - dictionary bonding fails"; throw(std::runtime_error(m)); } @@ -1528,12 +1528,12 @@ Bond_lines_container::invert_deloc_bond_displacement_vector(const clipper::Coord // << residue_atoms[iat_1]->name << ": to :" // << residue_atoms[iat_2]->name << ": =========================" << std::endl; - std::string atom_name_iat = residue_atoms[iat_1]->name; - std::string atom_name_jat = residue_atoms[iat_2]->name; + std::string atom_name_iat = residue_atoms[iat_1]->GetAtomName(); + std::string atom_name_jat = residue_atoms[iat_2]->GetAtomName(); std::map atom_name_map; for (int iat=0; iatname] = iat; + atom_name_map[residue_atoms[iat]->GetAtomName()] = iat; for (unsigned int ib=0; ibx, - residue_atoms[iat_1]->y, - residue_atoms[iat_1]->z); + clipper::Coord_orth pt_1(residue_atoms[iat_1]->x(), + residue_atoms[iat_1]->y(), + residue_atoms[iat_1]->z()); std::map::const_iterator it; it = atom_name_map.find(bond_restraints[ib].atom_id_2_4c()); if (it != atom_name_map.end()) { - clipper::Coord_orth pt_2(residue_atoms[it->second]->x, - residue_atoms[it->second]->y, - residue_atoms[it->second]->z); + clipper::Coord_orth pt_2(residue_atoms[it->second]->x(), + residue_atoms[it->second]->y(), + residue_atoms[it->second]->z()); clipper::Coord_orth diff = pt_2 - pt_1; double d = clipper::Coord_orth::dot(vect, diff); // std::cout << " dot 1 : " << d << std::endl; @@ -1577,15 +1577,15 @@ Bond_lines_container::invert_deloc_bond_displacement_vector(const clipper::Coord // << std::endl; if (bond_restraints[ib].type() == "deloc") { - clipper::Coord_orth pt_1(residue_atoms[iat_1]->x, - residue_atoms[iat_1]->y, - residue_atoms[iat_1]->z); + clipper::Coord_orth pt_1(residue_atoms[iat_1]->x(), + residue_atoms[iat_1]->y(), + residue_atoms[iat_1]->z()); std::map::const_iterator it; it = atom_name_map.find(bond_restraints[ib].atom_id_1_4c()); if (it != atom_name_map.end()) { - clipper::Coord_orth pt_2(residue_atoms[it->second]->x, - residue_atoms[it->second]->y, - residue_atoms[it->second]->z); + clipper::Coord_orth pt_2(residue_atoms[it->second]->x(), + residue_atoms[it->second]->y(), + residue_atoms[it->second]->z()); clipper::Coord_orth diff = pt_2 - pt_1; double d = clipper::Coord_orth::dot(vect, diff); // std::cout << " dot 2 : " << d << std::endl; @@ -1648,20 +1648,20 @@ Bond_lines_container::add_bonds_het_residues(const std::vectorname); + std::string residue_atom_name_1(residue_atoms[iat]->GetAtomName()); if (atom_name_1 == residue_atom_name_1) { for (int jat=0; jatname); + std::string residue_atom_name_2(residue_atoms[jat]->GetAtomName()); if (atom_name_2 == residue_atom_name_2) { - std::string aloc_1 = residue_atoms[iat]->altLoc; - std::string aloc_2 = residue_atoms[jat]->altLoc; + std::string aloc_1 = residue_atoms[iat]->altLoc(); + std::string aloc_2 = residue_atoms[jat]->altLoc(); if (aloc_1 == aloc_2 || aloc_1.empty() || aloc_2.empty()) { - coot::Cartesian p1(residue_atoms[iat]->x, - residue_atoms[iat]->y, - residue_atoms[iat]->z); - coot::Cartesian p2(residue_atoms[jat]->x, - residue_atoms[jat]->y, - residue_atoms[jat]->z); + coot::Cartesian p1(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); + coot::Cartesian p2(residue_atoms[jat]->x(), + residue_atoms[jat]->y(), + residue_atoms[jat]->z()); int iat_1_atom_index = -1; int iat_2_atom_index = -1; @@ -1669,12 +1669,12 @@ Bond_lines_container::add_bonds_het_residues(const std::vectorGetUDData(udd_atom_index_handle, iat_2_atom_index); if (false) - std::cout << "making bond between :" << residue_atoms[iat]->name - << ": and :" << residue_atoms[jat]->name << ": " + std::cout << "making bond between :" << residue_atoms[iat]->GetAtomName() + << ": and :" << residue_atoms[jat]->GetAtomName() << ": " << bt << std::endl; - std::string element_1 = residue_atoms[iat]->element; - std::string element_2 = residue_atoms[jat]->element; + std::string element_1 = residue_atoms[iat]->GetElementName(); + std::string element_2 = residue_atoms[jat]->GetElementName(); if (element_1 != element_2) { @@ -1890,8 +1890,8 @@ Bond_lines_container::add_aromatic_ring_bond_lines(const std::vectorGetAtomTable(residue_atoms, n_residue_atoms); for (unsigned int i=0; iname); - std::string atom_alt_conf(residue_atoms[iat]->altLoc); + std::string atom_name(residue_atoms[iat]->GetAtomName()); + std::string atom_alt_conf(residue_atoms[iat]->altLoc()); if (atom_alt_conf == alt_confs[i_alt_conf]) { if (atom_name == ring_atom_names[i]) { found_atoms.push_back(residue_atoms[iat]); @@ -1906,9 +1906,9 @@ Bond_lines_container::add_aromatic_ring_bond_lines(const std::vector pts(ring_atom_names.size()); for (unsigned int iat=0; iatx, - found_atom->y, - found_atom->z); + pts[iat] = clipper::Coord_orth(found_atom->x(), + found_atom->y(), + found_atom->z()); int idx_mol = -1; found_atom->GetUDData(udd_atom_index_handle, idx_mol); if (! skip_this_ring) @@ -2101,8 +2101,8 @@ Bond_lines_container::add_link_bond_templ(mmdb::Model *model_p, int udd_atom_ind for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - if (std::string(at->name) == std::string(link->atName1)) { - if (std::string(at->altLoc) == std::string(link->aloc1)) { + if (std::string(at->GetAtomName()) == std::string(link->atName1)) { + if (std::string(at->altLoc()) == std::string(link->aloc1)) { atom_1 = at; break; } @@ -2137,9 +2137,9 @@ Bond_lines_container::add_link_bond_templ(mmdb::Model *model_p, int udd_atom_ind for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - if (std::string(at->name) == + if (std::string(at->GetAtomName()) == std::string(link->atName2)) { - if (std::string(at->altLoc) == + if (std::string(at->altLoc()) == std::string(link->aloc2)) { atom_2 = at; break; @@ -2198,11 +2198,11 @@ Bond_lines_container::add_link_bond_templ(mmdb::Model *model_p, int udd_atom_ind // Even if the atom_index_1 or atom_index_2 were not correctly set, we can still draw // the bond - this needs to be fixed however. - coot::Cartesian pos_1(atom_1->x, atom_1->y, atom_1->z); - coot::Cartesian pos_2(atom_2->x, atom_2->y, atom_2->z); + coot::Cartesian pos_1(atom_1->x(), atom_1->y(), atom_1->z()); + coot::Cartesian pos_2(atom_2->x(), atom_2->y(), atom_2->z()); - std::string ele_1 = atom_1->element; - std::string ele_2 = atom_2->element; + std::string ele_1 = atom_1->GetElementName(); + std::string ele_2 = atom_2->GetElementName(); if (ele_1 == ele_2) { int col = atom_colour(atom_1, atom_colour_type, udd_user_defined_atom_colour_index_handle); add_dashed_bond(col, pos_1, pos_2, NOT_HALF_BOND, graphics_line_t::SINGLE, model_number, atom_index_1, atom_index_2); @@ -2508,10 +2508,10 @@ Bond_lines_container::construct_from_asc(const atom_selection_container_t &SelAt if (non_Hydrogen_atoms[i]->GetUDData(udd_found_bond_handle, ic) == mmdb::UDDATA_Ok) { if ((ic == 0) || - ((!strcmp(non_Hydrogen_atoms[i]->element, " S")) && (ic != graphical_bonds_container::BONDED_WITH_HETATM_BOND)) || - ((!strcmp(non_Hydrogen_atoms[i]->element, "SE")) && (ic != graphical_bonds_container::BONDED_WITH_HETATM_BOND)) || - ((!strcmp(non_Hydrogen_atoms[i]->element, "FE")) && (ic != graphical_bonds_container::BONDED_WITH_HETATM_BOND)) || - ((!strcmp(non_Hydrogen_atoms[i]->element, " P")) && (ic != graphical_bonds_container::BONDED_WITH_HETATM_BOND))) { + ((!strcmp(non_Hydrogen_atoms[i]->GetElementName(), " S")) && (ic != graphical_bonds_container::BONDED_WITH_HETATM_BOND)) || + ((!strcmp(non_Hydrogen_atoms[i]->GetElementName(), "SE")) && (ic != graphical_bonds_container::BONDED_WITH_HETATM_BOND)) || + ((!strcmp(non_Hydrogen_atoms[i]->GetElementName(), "FE")) && (ic != graphical_bonds_container::BONDED_WITH_HETATM_BOND)) || + ((!strcmp(non_Hydrogen_atoms[i]->GetElementName(), " P")) && (ic != graphical_bonds_container::BONDED_WITH_HETATM_BOND))) { // std::cout << ":::: No contact for " << non_Hydrogen_atoms[i] // << " with ic " << ic << std::endl; @@ -2520,7 +2520,7 @@ Bond_lines_container::construct_from_asc(const atom_selection_container_t &SelAt // So, was this a seleno-methione? // - mmdb::Residue *atom_residue_p = non_Hydrogen_atoms[i]->residue; + mmdb::Residue *atom_residue_p = non_Hydrogen_atoms[i]->GetResidue(); if (atom_residue_p) { std::string resname = non_Hydrogen_atoms[i]->GetResName(); @@ -2539,7 +2539,7 @@ Bond_lines_container::construct_from_asc(const atom_selection_container_t &SelAt udd_atom_index_handle, udd_user_defined_atom_colour_index_handle); } else { - std::string ele = non_Hydrogen_atoms[i]->element; + std::string ele = non_Hydrogen_atoms[i]->GetElementName(); if (ele == "CL" || ele == "BR" || ele == " S" || ele == " I" || ele == "Cl" || ele == "Br" || ele == "MO" || ele == "Mo" || ele == "AL" || ele == "PT" || ele == "RU" || ele == " W" @@ -2571,7 +2571,7 @@ Bond_lines_container::construct_from_asc(const atom_selection_container_t &SelAt if (non_Hydrogen_atoms[i]->GetUDData(udd_found_bond_handle, ic) == mmdb::UDDATA_Ok) { if (ic == graphical_bonds_container::NO_BOND) { // no contact found - mmdb::Residue *residue_p = non_Hydrogen_atoms[i]->residue; + mmdb::Residue *residue_p = non_Hydrogen_atoms[i]->GetResidue(); std::string res_name(residue_p->GetResName()); if (res_name == "HOH") @@ -2579,9 +2579,9 @@ Bond_lines_container::construct_from_asc(const atom_selection_container_t &SelAt continue; col = atom_colour(non_Hydrogen_atoms[i], atom_colour_type, udd_user_defined_atom_colour_index_handle); - coot::Cartesian atom_pos(non_Hydrogen_atoms[i]->x, - non_Hydrogen_atoms[i]->y, - non_Hydrogen_atoms[i]->z); + coot::Cartesian atom_pos(non_Hydrogen_atoms[i]->x(), + non_Hydrogen_atoms[i]->y(), + non_Hydrogen_atoms[i]->z()); int iat_1 = -1; int udd_status_1 = non_Hydrogen_atoms[i]->GetUDData(udd_atom_index_handle, iat_1); @@ -2600,7 +2600,7 @@ Bond_lines_container::construct_from_asc(const atom_selection_container_t &SelAt if (ic == graphical_bonds_container::NO_BOND) { // no contact found - mmdb::Residue *residue_p = Hydrogen_atoms[i]->residue; + mmdb::Residue *residue_p = Hydrogen_atoms[i]->GetResidue(); if (! residue_p) std::cout << "ERROR:: catched condition for crashetty crash!" << std::endl; @@ -2610,9 +2610,9 @@ Bond_lines_container::construct_from_asc(const atom_selection_container_t &SelAt continue; col = atom_colour(Hydrogen_atoms[i], atom_colour_type, udd_user_defined_atom_colour_index_handle); - coot::Cartesian atom(Hydrogen_atoms[i]->x, - Hydrogen_atoms[i]->y, - Hydrogen_atoms[i]->z); + coot::Cartesian atom(Hydrogen_atoms[i]->x(), + Hydrogen_atoms[i]->y(), + Hydrogen_atoms[i]->z()); // 20171224-PE FIXME by lookup int iat_1 = -1; @@ -2656,7 +2656,7 @@ Bond_lines_container::handle_MET_or_MSE_case(mmdb::PAtom mse_atom, // std::cout << "Handling MET/MSE case for atom " << mse_atom << std::endl; - std::string atom_name(mse_atom->name); + std::string atom_name(mse_atom->GetAtomName()); std::string residue_name(mse_atom->GetResName()); int model_number = mse_atom->GetModelNum(); if (residue_name == "MET" || residue_name == "MSE" || residue_name == "MSO") { @@ -2666,19 +2666,19 @@ Bond_lines_container::handle_MET_or_MSE_case(mmdb::PAtom mse_atom, // We need to add special bonds SE -> CE and SE -> CG. mmdb::PPAtom residue_atoms; int nResidueAtoms; - mse_atom->residue->GetAtomTable(residue_atoms, nResidueAtoms); + mse_atom->GetResidue()->GetAtomTable(residue_atoms, nResidueAtoms); for (int i=0; iname); + std::string table_atom_name(residue_atoms[i]->GetAtomName()); if (table_atom_name == " CG " || table_atom_name == " CE " ) { // mse_atom or met_atom now of course. - coot::Cartesian cart_at1(mse_atom->x, mse_atom->y, mse_atom->z); - coot::Cartesian cart_at2(residue_atoms[i]->x, - residue_atoms[i]->y, - residue_atoms[i]->z); + coot::Cartesian cart_at1(mse_atom->x(), mse_atom->y(), mse_atom->z()); + coot::Cartesian cart_at2(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); - std::string altconf1 = mse_atom->altLoc; - std::string altconf2 = residue_atoms[i]->altLoc; + std::string altconf1 = mse_atom->altLoc(); + std::string altconf2 = residue_atoms[i]->altLoc(); if ( (altconf1=="") || (altconf2=="") || (altconf1==altconf2) ) { coot::Cartesian bond_mid_point = cart_at1.mid_point(cart_at2); int colc = atom_colour(residue_atoms[i], atom_colour_type, udd_user_defined_atom_colour_index_handle, atom_colour_map_p); @@ -2710,17 +2710,17 @@ Bond_lines_container::handle_MET_or_MSE_case(mmdb::PAtom mse_atom, // We need to add special bonds CB -> SG mmdb::PPAtom residue_atoms; int nResidueAtoms; - mse_atom->residue->GetAtomTable(residue_atoms, nResidueAtoms); + mse_atom->GetResidue()->GetAtomTable(residue_atoms, nResidueAtoms); for (int i=0; iname); + std::string table_atom_name(residue_atoms[i]->GetAtomName()); if (table_atom_name == " CB ") { - coot::Cartesian cart_at1(mse_atom->x, mse_atom->y, mse_atom->z); - coot::Cartesian cart_at2(residue_atoms[i]->x, - residue_atoms[i]->y, - residue_atoms[i]->z); + coot::Cartesian cart_at1(mse_atom->x(), mse_atom->y(), mse_atom->z()); + coot::Cartesian cart_at2(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); - std::string altconf1 = mse_atom->altLoc; - std::string altconf2 = residue_atoms[i]->altLoc; + std::string altconf1 = mse_atom->altLoc(); + std::string altconf2 = residue_atoms[i]->altLoc(); if ( (altconf1=="") || (altconf2=="") || (altconf1==altconf2) ) { float len2 = (cart_at1 - cart_at2).amplitude_squared(); if (len2 < 16) { // protection for weirdness @@ -2760,10 +2760,10 @@ Bond_lines_container::handle_long_bonded_atom(mmdb::PAtom atom, // some wiggle room (2.1 was too short for // some dictionary S-S). - std::string atom_name(atom->name); + std::string atom_name(atom->GetAtomName()); std::string residue_name(atom->GetResName()); - std::string element(atom->element); - mmdb::Residue *res = atom->residue; + std::string element(atom->GetElementName()); + mmdb::Residue *res = atom->GetResidue(); int model_number = atom->GetModelNum(); // std::cout << "handling long bonds for " << atom << " ele " << element << std::endl; @@ -2788,26 +2788,26 @@ Bond_lines_container::handle_long_bonded_atom(mmdb::PAtom atom, if (res) { // do the bonding by hand: - coot::Cartesian atom_pos(atom->x, atom->y, atom->z); + coot::Cartesian atom_pos(atom->x(), atom->y(), atom->z()); int col = atom_colour(atom, atom_colour_type, udd_user_defined_atom_colour_index_handle, atom_colour_map_p); mmdb::PPAtom residue_atoms = 0; int nResidueAtoms; res->GetAtomTable(residue_atoms, nResidueAtoms); for (int i=0; ix, - residue_atoms[i]->y, - residue_atoms[i]->z); + coot::Cartesian res_atom_pos(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); // We compared squard bond distances (so that we don't // have to take the square root for everything of course). // - std::string res_atom_ele = residue_atoms[i]->element; + std::string res_atom_ele = residue_atoms[i]->GetElementName(); float len2 = (atom_pos - res_atom_pos).amplitude_squared(); if (((len2 < bl2) && (! is_hydrogen(res_atom_ele))) || ((len2 < h_bl2) && (is_hydrogen(res_atom_ele)))) { - std::string altconf1 = atom->altLoc; - std::string altconf2 = residue_atoms[i]->altLoc; + std::string altconf1 = atom->altLoc(); + std::string altconf2 = residue_atoms[i]->altLoc(); if ( (altconf1=="") || (altconf2=="") || (altconf1==altconf2) ) { coot::Cartesian bond_mid_point = atom_pos.mid_point(res_atom_pos); int colc = atom_colour(residue_atoms[i], atom_colour_type, udd_user_defined_atom_colour_index_handle, atom_colour_map_p); @@ -2844,7 +2844,7 @@ Bond_lines_container::handle_long_bonded_atom(mmdb::PAtom atom, coot::Cartesian small_vec_z(0.0, 0.0, star_size); int col = atom_colour(atom, atom_colour_type, udd_user_defined_atom_colour_index_handle, atom_colour_map_p); - coot::Cartesian atom_pos(atom->x, atom->y, atom->z); + coot::Cartesian atom_pos(atom->x(), atom->y(), atom->z()); graphics_line_t::cylinder_class_t cc = graphics_line_t::SINGLE; // 20171224-PE FIXME lookup iat_1, iat_1 int iat_1 = -1; @@ -2929,16 +2929,16 @@ Bond_lines_container::Bond_lines_container(const atom_selection_container_t &Sel mmdb::Atom *atom_1 = residue_atoms[ contact[i].id1 ]; mmdb::Atom *atom_2 = SelAtom.atom_selection[ contact[i].id2]; - coot::Cartesian atom_1_pos(residue_atoms[ contact[i].id1 ]->x, - residue_atoms[ contact[i].id1 ]->y, - residue_atoms[ contact[i].id1 ]->z); - coot::Cartesian atom_2_pos(SelAtom.atom_selection[ contact[i].id2 ]->x, - SelAtom.atom_selection[ contact[i].id2 ]->y, - SelAtom.atom_selection[ contact[i].id2 ]->z); - std::string ele1 = residue_atoms[ contact[i].id1 ]->element; - std::string ele2 = SelAtom.atom_selection[ contact[i].id2 ]->element; - std::string alt_conf_1 = residue_atoms[ contact[i].id1 ]->altLoc; - std::string alt_conf_2 = SelAtom.atom_selection[ contact[i].id2 ]->altLoc; + coot::Cartesian atom_1_pos(residue_atoms[ contact[i].id1 ]->x(), + residue_atoms[ contact[i].id1 ]->y(), + residue_atoms[ contact[i].id1 ]->z()); + coot::Cartesian atom_2_pos(SelAtom.atom_selection[ contact[i].id2 ]->x(), + SelAtom.atom_selection[ contact[i].id2 ]->y(), + SelAtom.atom_selection[ contact[i].id2 ]->z()); + std::string ele1 = residue_atoms[ contact[i].id1 ]->GetElementName(); + std::string ele2 = SelAtom.atom_selection[ contact[i].id2 ]->GetElementName(); + std::string alt_conf_1 = residue_atoms[ contact[i].id1 ]->altLoc(); + std::string alt_conf_2 = SelAtom.atom_selection[ contact[i].id2 ]->altLoc(); int model_number = residue_atoms[ contact[i].id1 ]->GetModelNum(); // 20110119 environment distances for Hydrogens. We don't @@ -3154,7 +3154,7 @@ Bond_lines_container::Bond_lines_container(const atom_selection_container_t &Sel graphics_line_t::cylinder_class_t cc = graphics_line_t::SINGLE; for (int iresatom=0; iresatom< nResidueAtoms; iresatom++) { mmdb::Atom *res_atom = residue_atoms[iresatom]; - coot::Cartesian res_atom_pos(res_atom->x, res_atom->y, res_atom->z); + coot::Cartesian res_atom_pos(res_atom->x(), res_atom->y(), res_atom->z()); int model_number = residue_atoms[iresatom]->GetModelNum(); molecule_extents_t mol_extents(SelAtom, max_dist); @@ -3170,15 +3170,15 @@ Bond_lines_container::Bond_lines_container(const atom_selection_container_t &Sel int iat_2 = -1; mmdb::Atom *trans_atom = translated[it]; - coot::Cartesian symm_atom_pos(translated[it]->x, - translated[it]->y, - translated[it]->z); + coot::Cartesian symm_atom_pos(translated[it]->x(), + translated[it]->y(), + translated[it]->z()); float d = coot::Cartesian::LineLength(symm_atom_pos, res_atom_pos); // std::cout << translated[it] << " d = " << d << std::endl; if (d < max_dist && d >= min_dist) { - std::string ele1 = residue_atoms[iresatom]->element; - std::string ele2 = translated[it]->element; + std::string ele1 = residue_atoms[iresatom]->GetElementName(); + std::string ele2 = translated[it]->GetElementName(); if (draw_env_distances_to_hydrogens_flag || // ((ele1 != " H") && (ele2 != " H"))) { @@ -3262,8 +3262,8 @@ Bond_lines_container::find_intermolecular_symmetry(const atom_selection_containe mmdb::Atom *at_1 = SelAtom.atom_selection[contact[i].id1]; mmdb::Atom *at_2 = SelAtom.atom_selection[contact[i].id2]; - std::string ele_1 = at_1->element; - std::string ele_2 = at_2->element; + std::string ele_1 = at_1->GetElementName(); + std::string ele_2 = at_2->GetElementName(); if (ele_1 == " H" || ele_1 == "H") max_bond_dist -= 0.8; if (ele_2 == " H" || ele_2 == "H") max_bond_dist -= 0.8; @@ -3277,9 +3277,9 @@ Bond_lines_container::find_intermolecular_symmetry(const atom_selection_containe mmdb::Atom t_atom2; t_atom2.Copy(at_2); t_atom2.Transform(my_matt); - coot::Cartesian atom_1_pt(at_1->x, at_1->y, at_1->z); - coot::Cartesian atom_2_pt(at_2->x, at_2->y, at_2->z); - coot::Cartesian t_atom_2_pt(t_atom2.x, t_atom2.y, t_atom2.z); + coot::Cartesian atom_1_pt(at_1->x(), at_1->y(), at_1->z()); + coot::Cartesian atom_2_pt(at_2->x(), at_2->y(), at_2->z()); + coot::Cartesian t_atom_2_pt(t_atom2.x(), t_atom2.y(), t_atom2.z()); std::cout << "store at_1: " << atom_1_pt << " "; std::cout << "at_2: " << atom_2_pt << " "; std::cout << "t-at_2: " << t_atom_2_pt << " "; @@ -3468,7 +3468,7 @@ Bond_lines_container::addSymmetry_whole_chain(const atom_selection_container_t & for (int i=0; iCopy(SelAtom.atom_selection[i]); - transsel[i]->residue = SelAtom.atom_selection[i]->residue; + transsel[i]->GetResidue() = SelAtom.atom_selection[i]->GetResidue(); transsel[i]->Transform(mol_to_origin_matt); transsel[i]->Transform(my_matt); } @@ -3654,18 +3654,18 @@ Bond_lines_container::intermolecular_symmetry_graphical_bonds(mmdb::Manager *mol for (unsigned int i=0; ix, sabv[i].at_1->y, sabv[i].at_1->z); + coot::Cartesian atom_1_pt(sabv[i].at_1->x(), sabv[i].at_1->y(), sabv[i].at_1->z()); int ierr = sabv[i].GetTMatrix(mol, &my_matt); // check that my_matt gets changed to something sensible int model_number = sabv[i].at_1->GetModelNum(); if (! ierr) { - coot::Cartesian atom_2_pt(sabv[i].at_2->x, sabv[i].at_2->y, sabv[i].at_2->z); + coot::Cartesian atom_2_pt(sabv[i].at_2->x(), sabv[i].at_2->y(), sabv[i].at_2->z()); mmdb::Atom t_atom2; t_atom2.Copy(sabv[i].at_2); t_atom2.Transform(my_matt); - coot::Cartesian t_atom_2_pt(t_atom2.x, t_atom2.y, t_atom2.z); + coot::Cartesian t_atom_2_pt(t_atom2.x(), t_atom2.y(), t_atom2.z()); if (0) std::cout << "gbc int-symm bond: atom_1: " << atom_1_pt << " atom_2: " @@ -3739,8 +3739,8 @@ Bond_lines_container::addSymmetry_calphas(const atom_selection_container_t &SelA res1->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname) == " CA " || - std::string(residue_atoms[iat]->name) == " P ") { + if (std::string(residue_atoms[iat]->GetAtomName()) == " CA " || + std::string(residue_atoms[iat]->GetAtomName()) == " P ") { ca_this.push_back(residue_atoms[iat]); } } @@ -3748,8 +3748,8 @@ Bond_lines_container::addSymmetry_calphas(const atom_selection_container_t &SelA res2->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname) == " CA " || - std::string(residue_atoms[iat]->name) == " P ") { + if (std::string(residue_atoms[iat]->GetAtomName()) == " CA " || + std::string(residue_atoms[iat]->GetAtomName()) == " P ") { ca_next.push_back(residue_atoms[iat]); } } @@ -3760,19 +3760,19 @@ Bond_lines_container::addSymmetry_calphas(const atom_selection_container_t &SelA if (ca_this.size() > 0) { if (ca_next.size() > 0) { for (unsigned int iat=0; iataltLoc; + std::string altconf1 = ca_this[iat]->altLoc(); for (unsigned int jat=0; jataltLoc; + std::string altconf2 = ca_next[jat]->altLoc(); if ((altconf1 == altconf2) || (altconf1 == "") || (altconf2 == "")) { - coot::Cartesian ca_1(ca_this[iat]->x, - ca_this[iat]->y, - ca_this[iat]->z); - coot::Cartesian ca_2(ca_next[jat]->x, - ca_next[jat]->y, - ca_next[jat]->z); + coot::Cartesian ca_1(ca_this[iat]->x(), + ca_this[iat]->y(), + ca_this[iat]->z()); + coot::Cartesian ca_2(ca_next[jat]->x(), + ca_next[jat]->y(), + ca_next[jat]->z()); double len = (ca_1 - ca_2).amplitude(); // CA-CA or P-P @@ -3786,8 +3786,8 @@ Bond_lines_container::addSymmetry_calphas(const atom_selection_container_t &SelA t_atom1.Transform(my_matt); t_atom2.Transform(my_matt); - coot::Cartesian atom1(t_atom1.x, t_atom1.y, t_atom1.z); - coot::Cartesian atom2(t_atom2.x, t_atom2.y, t_atom2.z); + coot::Cartesian atom1(t_atom1.x(), t_atom1.y(), t_atom1.z()); + coot::Cartesian atom2(t_atom2.x(), t_atom2.y(), t_atom2.z()); int iat_1 = -1; // 20171224-PE FIXME maybe lookup int iat_2 = -1; @@ -3918,7 +3918,7 @@ Bond_lines_container::add_NCS_molecule_whole_chain(const atom_selection_containe for (int i=0; iCopy(SelAtom.atom_selection[i]); - transsel[i]->residue = SelAtom.atom_selection[i]->residue; + transsel[i]->GetResidue() = SelAtom.atom_selection[i]->GetResidue(); transsel[i]->Transform(my_matt); } // So now we have transsel. We need to calculate bonds from @@ -4065,7 +4065,7 @@ Bond_lines_container::trans_sel(atom_selection_container_t AtomSel, // trans_selection[ii]->SetChain( AtomSel.atom_selection[ii]->GetChain()); trans_selection[ii]->Copy(AtomSel.atom_selection[ii]); - trans_selection[ii]->residue = AtomSel.atom_selection[ii]->residue; + trans_selection[ii]->GetResidue() = AtomSel.atom_selection[ii]->GetResidue(); trans_selection[ii]->Transform(mol_to_origin_matt); trans_selection[ii]->Transform(my_matt); } @@ -4198,17 +4198,17 @@ Bond_lines_container::do_disulphide_bonds_by_distance(atom_selection_container_t Sulfur_selection[contact[i].id1]->GetUDData(udd_atom_index_handle, iat_1); Sulfur_selection[contact[i].id2]->GetUDData(udd_atom_index_handle, iat_2); - std::string aloc_1(Sulfur_selection[ contact[i].id1 ]->altLoc); - std::string aloc_2(Sulfur_selection[ contact[i].id2 ]->altLoc); + std::string aloc_1(Sulfur_selection[ contact[i].id1 ]->altLoc()); + std::string aloc_2(Sulfur_selection[ contact[i].id2 ]->altLoc()); if ( (aloc_1=="") || (aloc_2=="") || (aloc_1==aloc_2) ) { - coot::Cartesian atom_1(Sulfur_selection[ contact[i].id1 ]->x, - Sulfur_selection[ contact[i].id1 ]->y, - Sulfur_selection[ contact[i].id1 ]->z); + coot::Cartesian atom_1(Sulfur_selection[ contact[i].id1 ]->x(), + Sulfur_selection[ contact[i].id1 ]->y(), + Sulfur_selection[ contact[i].id1 ]->z()); - coot::Cartesian atom_2(Sulfur_selection[ contact[i].id2 ]->x, - Sulfur_selection[ contact[i].id2 ]->y, - Sulfur_selection[ contact[i].id2 ]->z); + coot::Cartesian atom_2(Sulfur_selection[ contact[i].id2 ]->x(), + Sulfur_selection[ contact[i].id2 ]->y(), + Sulfur_selection[ contact[i].id2 ]->z()); col = atom_colour(Sulfur_selection[ contact[i].id1 ], coot::DISULFIDE_COLOUR, udd_user_defined_atom_colour_index_handle); @@ -4905,9 +4905,9 @@ Bond_lines_container::do_Ca_loop(int imod, int ires, int nres, mmdb::Atom *N_this = residue_this->GetAtom(" N "); if (N_this) { float dist_sqrd = - (C_prev->x - N_this->x) * (C_prev->x - N_this->x) + - (C_prev->y - N_this->y) * (C_prev->y - N_this->y) + - (C_prev->z - N_this->z) * (C_prev->z - N_this->z); + (C_prev->x() - N_this->x()) * (C_prev->x() - N_this->x()) + + (C_prev->y() - N_this->y()) * (C_prev->y() - N_this->y()) + + (C_prev->z() - N_this->z()) * (C_prev->z() - N_this->z()); if (dist_sqrd < 2.5 * 2.5) C_and_N_are_close = true; } @@ -4925,9 +4925,9 @@ Bond_lines_container::do_Ca_loop(int imod, int ires, int nres, mmdb::Atom *P_this = residue_this->GetAtom(" P "); if (P_this) { float dist_sqrd = - (O3prime_prev->x - P_this->x) * (O3prime_prev->x - P_this->x) + - (O3prime_prev->y - P_this->y) * (O3prime_prev->y - P_this->y) + - (O3prime_prev->z - P_this->z) * (O3prime_prev->z - P_this->z); + (O3prime_prev->x() - P_this->x()) * (O3prime_prev->x() - P_this->x()) + + (O3prime_prev->y() - P_this->y()) * (O3prime_prev->y() - P_this->y()) + + (O3prime_prev->z() - P_this->z()) * (O3prime_prev->z() - P_this->z()); if (dist_sqrd < 2.5 * 2.5) // c.f 1.6 * 1.6 P_and_O3prime_are_close = true; } @@ -4939,8 +4939,8 @@ Bond_lines_container::do_Ca_loop(int imod, int ires, int nres, if (loop_is_possible) { if (at_pp_1 && at_pp_2 && at_pp_3 && at_pp_4) { - coot::Cartesian pp_2(at_pp_2->x, at_pp_2->y, at_pp_2->z); - coot::Cartesian pp_3(at_pp_3->x, at_pp_3->y, at_pp_3->z); + coot::Cartesian pp_2(at_pp_2->x(), at_pp_2->y(), at_pp_2->z()); + coot::Cartesian pp_3(at_pp_3->x(), at_pp_3->y(), at_pp_3->z()); float a = (pp_3-pp_2).amplitude(); int n_line_segments = static_cast(a*1.2); std::pair > lp = @@ -5078,11 +5078,11 @@ Bond_lines_container::do_Ca_or_P_bonds_internal(atom_selection_container_t SelAt mmdb::Atom *at_2 = residue_this->GetAtom(jat); std::string atom_name_2(at_2->GetAtomName()); if (atom_name_2 == " P ") { - std::string alt_conf_1 = at_1->altLoc; - std::string alt_conf_2 = at_2->altLoc; + std::string alt_conf_1 = at_1->altLoc(); + std::string alt_conf_2 = at_2->altLoc(); if (alt_conf_1.empty() || alt_conf_2.empty() || alt_conf_2 == alt_conf_1) { - coot::Cartesian pt_1(at_1->x, at_1->y, at_1->z); - coot::Cartesian pt_2(at_2->x, at_2->y, at_2->z); + coot::Cartesian pt_1(at_1->x(), at_1->y(), at_1->z()); + coot::Cartesian pt_2(at_2->x(), at_2->y(), at_2->z()); coot::Cartesian bond_mid_point = pt_1.mid_point(pt_2); int iat_1 = -1; int iat_2 = -1; @@ -5115,11 +5115,11 @@ Bond_lines_container::do_Ca_or_P_bonds_internal(atom_selection_container_t SelAt } } if (do_base_stick_bond) { // at least potentially... - std::string alt_conf_1 = at_1->altLoc; - std::string alt_conf_2 = at_2->altLoc; + std::string alt_conf_1 = at_1->altLoc(); + std::string alt_conf_2 = at_2->altLoc(); if (alt_conf_1.empty() || alt_conf_2.empty() || alt_conf_2 == alt_conf_1) { - coot::Cartesian pt_1(at_1->x, at_1->y, at_1->z); - coot::Cartesian pt_2(at_2->x, at_2->y, at_2->z); + coot::Cartesian pt_1(at_1->x(), at_1->y(), at_1->z()); + coot::Cartesian pt_2(at_2->x(), at_2->y(), at_2->z()); int iat_1 = -1; int iat_2 = -1; at_1->GetUDData(udd_atom_index_handle, iat_1); @@ -5144,11 +5144,11 @@ Bond_lines_container::do_Ca_or_P_bonds_internal(atom_selection_container_t SelAt mmdb::Atom *at_2 = residue_this->GetAtom(jat); std::string atom_name_2(at_2->GetAtomName()); if (atom_name_2 == " P ") { // PDBv3 FIXME - std::string alt_conf_prev = at_1->altLoc; - std::string alt_conf_this = at_2->altLoc; + std::string alt_conf_prev = at_1->altLoc(); + std::string alt_conf_this = at_2->altLoc(); if (alt_conf_prev.empty() || alt_conf_this.empty() || alt_conf_prev == alt_conf_this) { - coot::Cartesian pt_1(at_1->x, at_1->y, at_1->z); - coot::Cartesian pt_2(at_2->x, at_2->y, at_2->z); + coot::Cartesian pt_1(at_1->x(), at_1->y(), at_1->z()); + coot::Cartesian pt_2(at_2->x(), at_2->y(), at_2->z()); int iat_1 = -1; int iat_2 = -1; at_1->GetUDData(udd_atom_index_handle, iat_1); @@ -5190,8 +5190,8 @@ Bond_lines_container::do_Ca_or_P_bonds_internal(atom_selection_container_t SelAt for (int jat=0; jatGetAtom(jat); std::string atom_name_2(at_2->GetAtomName()); - std::string alt_conf_prev = at_1->altLoc; - std::string alt_conf_this = at_2->altLoc; + std::string alt_conf_prev = at_1->altLoc(); + std::string alt_conf_this = at_2->altLoc(); // Allow MSE hetgroups in CA mode if ((!at_1->Het || res_name_1 == "MSE") && (!at_2->Het || res_name_2 == "MSE")) { if (!at_1->isTer() && !at_2->isTer()) { @@ -5209,8 +5209,8 @@ Bond_lines_container::do_Ca_or_P_bonds_internal(atom_selection_container_t SelAt if (Calpha_pair || phosphate_pair) { if (alt_conf_prev == alt_conf_this || alt_conf_this == "" || alt_conf_prev == "") { int col = 0; // overridden. - coot::Cartesian ca_1(at_1->x, at_1->y, at_1->z); - coot::Cartesian ca_2(at_2->x, at_2->y, at_2->z); + coot::Cartesian ca_1(at_1->x(), at_1->y(), at_1->z()); + coot::Cartesian ca_2(at_2->x(), at_2->y(), at_2->z()); int iat_1 = -1; int iat_2 = -1; at_1->GetUDData(udd_atom_index_handle, iat_1); @@ -5419,7 +5419,7 @@ Bond_lines_container::do_Ca_or_P_bonds_internal(atom_selection_container_t SelAt int iat_1 = -1; // 20171224-PE FIXME int udd_status_1 = at->GetUDData(udd_atom_index_handle, iat_1); - coot::Cartesian pos(at->x, at->y, at->z); + coot::Cartesian pos(at->x(), at->y(), at->z()); addBond(col, pos+small_vec_x, pos-small_vec_x, cc, imod, iat_1, iat_1, true, true); addBond(col, pos+small_vec_y, pos-small_vec_y, cc, imod, iat_1, iat_1, true, true); addBond(col, pos+small_vec_z, pos-small_vec_z, cc, imod, iat_1, iat_1, true, true); @@ -5521,7 +5521,7 @@ Bond_lines_container::set_b_factor_colours(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); if (! atom_p->Het) { - float b_factor = atom_p->tempFactor; + float b_factor = atom_p->tempFactor(); float bs = b_factor * b_factor_scale; float f = bs/max_b_factor; if (f < 0.0) f = 0.0; @@ -5591,7 +5591,7 @@ Bond_lines_container::atom_colour(mmdb::Atom *at, int bond_colour_type, std::string ch_id(std::string(at->GetChainID())); int col_idx = atom_colour_map_p->index_for_chain(ch_id); col = 2 * col_idx; - std::string ele = at->element; + std::string ele = at->GetElementName(); if (ele != " C") col += 1; // std::cout << "here in atom_colour(): with goodsell colours with chain-id " << ch_id @@ -5601,7 +5601,7 @@ Bond_lines_container::atom_colour(mmdb::Atom *at, int bond_colour_type, } else { if (bond_colour_type == coot::COLOUR_BY_HYDROPHOBIC_SIDE_CHAIN) { - mmdb::Residue *r = at->residue; + mmdb::Residue *r = at->GetResidue(); if (r) { std::string res_name(r->GetResName()); if (coot::util::is_standard_amino_acid_name(res_name)) { @@ -5619,7 +5619,7 @@ Bond_lines_container::atom_colour(mmdb::Atom *at, int bond_colour_type, } if (bond_colour_type == coot::COLOUR_BY_SEC_STRUCT) { - int sse = at->residue->SSE; + int sse = at->GetResidue()->SSE; switch (sse) { case mmdb::SSE_None: col = 0; @@ -5647,7 +5647,7 @@ Bond_lines_container::atom_colour(mmdb::Atom *at, int bond_colour_type, } } else { if (bond_colour_type == coot::COLOUR_BY_ATOM_TYPE) { - std::string element(at->element); + std::string element(at->GetElementName()); if (element == " C") { return CARBON_BOND; @@ -5711,7 +5711,7 @@ Bond_lines_container::atom_colour(mmdb::Atom *at, int bond_colour_type, } else { if (bond_colour_type == coot::COLOUR_BY_CHAIN_C_ONLY) { - std::string element(at->element); + std::string element(at->GetElementName()); if (element == " C") { // PDBv3 FIXME (and below) if (atom_colour_map_p) { @@ -5787,19 +5787,19 @@ Bond_lines_container::atom_colour(mmdb::Atom *at, int bond_colour_type, return YELLOW_BOND; } else { if (bond_colour_type == coot::COLOUR_BY_OCCUPANCY) { - if (at->occupancy > 0.95) { + if (at->occupancy() > 0.95) { return BLUE_BOND; } else { - if (at->occupancy < 0.05) { + if (at->occupancy() < 0.05) { return RED_BOND; } else { - if (at->occupancy > 0.7) { + if (at->occupancy() > 0.7) { return CYAN_BOND; } else { - if (at->occupancy > 0.45) { + if (at->occupancy() > 0.45) { return GREEN_BOND; } else { - if (at->occupancy > 0.25) { + if (at->occupancy() > 0.25) { return YELLOW_BOND; } else { return ORANGE_BOND; @@ -5811,7 +5811,7 @@ Bond_lines_container::atom_colour(mmdb::Atom *at, int bond_colour_type, } else { if (bond_colour_type == coot::COLOUR_BY_B_FACTOR) { // B-factors by atom are done this way. - float scaled_b = at->tempFactor * b_factor_scale; + float scaled_b = at->tempFactor() * b_factor_scale; float max_b = 100.0; // std::cout << "here we go! scaled_b " << scaled_b << std::endl; float f = scaled_b/max_b; @@ -6001,7 +6001,7 @@ Bond_lines_container::do_Ca_plus_ligands_bonds(atom_selection_container_t SelAto if (residue_p->GetUDData(udd_has_ca_handle, ic) == mmdb::UDDATA_Ok) { if (ic == 0) { // Residue was not rendered as CA, needs normal bonds - std::string resname(residue_p->name); + std::string resname(residue_p->GetResName()); if (resname != "WAT" && resname != "HOH") { // can we do this residue by dictionary? @@ -6269,13 +6269,13 @@ Bond_lines_container::do_symmetry_Ca_bonds(atom_selection_container_t SelAtom, for (int i=0; i< ncontacts; i++) { if ( contact[i].id2 > contact[i].id1 ) { - coot::Cartesian ca_1(trans_ca_selection[ contact[i].id1 ]->x, - trans_ca_selection[ contact[i].id1 ]->y, - trans_ca_selection[ contact[i].id1 ]->z); + coot::Cartesian ca_1(trans_ca_selection[ contact[i].id1 ]->x(), + trans_ca_selection[ contact[i].id1 ]->y(), + trans_ca_selection[ contact[i].id1 ]->z()); - coot::Cartesian ca_2(trans_ca_selection[ contact[i].id2 ]->x, - trans_ca_selection[ contact[i].id2 ]->y, - trans_ca_selection[ contact[i].id2 ]->z); + coot::Cartesian ca_2(trans_ca_selection[ contact[i].id2 ]->x(), + trans_ca_selection[ contact[i].id2 ]->y(), + trans_ca_selection[ contact[i].id2 ]->z()); // 20171224-PE FIXME int iat_1 = -1; @@ -6306,7 +6306,7 @@ Bond_lines_container::draw_GA_rings_outer(mmdb::Residue *residue_p, int model_nu for (int iat=0; iatisTer()) { - std::string a(at->altLoc); + std::string a(at->altLoc()); residue_alt_confs.insert(a); } } @@ -6325,9 +6325,9 @@ Bond_lines_container::draw_GA_rings_outer(mmdb::Residue *residue_p, int model_nu for (int iat=0; iatisTer()) { - std::string atom_name(at->name); + std::string atom_name(at->GetAtomName()); if (atom_name == G_rings_atom_name) { - std::string a(at->altLoc); + std::string a(at->altLoc()); if (a == alt_loc || a == "") { G_rings_atoms[i] = at; n_found++; @@ -6365,7 +6365,7 @@ Bond_lines_container::draw_trp_ring_outer(mmdb::Residue *residue_p, int model_nu for (int iat=0; iatisTer()) { - std::string a(at->altLoc); + std::string a(at->altLoc()); residue_alt_confs.insert(a); } } @@ -6384,9 +6384,9 @@ Bond_lines_container::draw_trp_ring_outer(mmdb::Residue *residue_p, int model_nu for (int iat=0; iatisTer()) { - std::string atom_name(at->name); + std::string atom_name(at->GetAtomName()); if (atom_name == trp_rings_atom_name) { - std::string a(at->altLoc); + std::string a(at->altLoc()); if (a == alt_loc || a == "") { trp_rings_atoms[i] = at; n_found++; @@ -6423,7 +6423,7 @@ Bond_lines_container::draw_CUT_ring(mmdb::Residue *residue_p, int model_number, for (int iat=0; iatisTer()) { - std::string a(at->altLoc); + std::string a(at->altLoc()); residue_alt_confs.insert(a); } } @@ -6442,9 +6442,9 @@ Bond_lines_container::draw_CUT_ring(mmdb::Residue *residue_p, int model_number, for (int iat=0; iatisTer()) { - std::string atom_name(at->name); + std::string atom_name(at->GetAtomName()); if (atom_name == ring_atom_name) { - std::string a(at->altLoc); + std::string a(at->altLoc()); if (a == alt_loc || a == "") { ring_atoms[i] = at; n_found++; @@ -6483,9 +6483,9 @@ Bond_lines_container::draw_phenyl_ring_outer(mmdb::Residue *residue_p, int model for (int iat=0; iatisTer()) { - std::string atom_name(at->name); + std::string atom_name(at->GetAtomName()); if (atom_name == ring_atom_name) { - std::string a(at->altLoc); + std::string a(at->altLoc()); if (a == alt_loc || a == "") { ring_atoms[i] = at; n_found++; @@ -6525,7 +6525,7 @@ Bond_lines_container::draw_het_group_rings(mmdb::Residue *residue_p, for (int iat=0; iatisTer()) { - std::string atom_name(at->name); + std::string atom_name(at->GetAtomName()); if (names.atom_name(0) == atom_name) bq.atom_1 = at; if (names.atom_name(1) == atom_name) bq.atom_2 = at; if (names.atom_name(2) == atom_name) bq.atom_3 = at; @@ -6585,9 +6585,9 @@ Bond_lines_container::add_residue_monomer_bonds(const std::mapisTer()) { - std::string atom_name(at->name); - std::string ele(at->element); - std::string alt_loc(at->altLoc); + std::string atom_name(at->GetAtomName()); + std::string ele(at->GetElementName()); + std::string alt_loc(at->altLoc()); atom_string_bits_t asb(atom_name, ele, alt_loc, at); atom_name_ele_map[monomer_name][i].push_back(asb); if (at->Het) @@ -6725,7 +6725,7 @@ Bond_lines_container::add_residue_monomer_bonds(const std::mapisTer()) { - std::string a(at->altLoc); + std::string a(at->altLoc()); residue_alt_confs.insert(a); } } @@ -6785,10 +6785,10 @@ Bond_lines_container::add_residue_monomer_bonds(const std::mapelement); - std::string element_2(atom_p_2->element); - coot::Cartesian p1(atom_p_1->x, atom_p_1->y, atom_p_1->z); - coot::Cartesian p2(atom_p_2->x, atom_p_2->y, atom_p_2->z); + std::string element_1(atom_p_1->GetElementName()); + std::string element_2(atom_p_2->GetElementName()); + coot::Cartesian p1(atom_p_1->x(), atom_p_1->y(), atom_p_1->z()); + coot::Cartesian p2(atom_p_2->x(), atom_p_2->y(), atom_p_2->z()); int iat_1_atom_index = -1; int iat_2_atom_index = -1; @@ -7102,7 +7102,7 @@ Bond_lines_container::do_colour_by_dictionary_and_by_chain_bonds_carbons_only(co mmdb::Atom *at = asc.atom_selection[iat]; if (at->GetUDData(udd_found_bond_handle, ic) == mmdb::UDDATA_Ok) { if (ic == graphical_bonds_container::NO_BOND) { - mmdb::Residue *residue_p = at->residue; + mmdb::Residue *residue_p = at->GetResidue(); std::string res_name(residue_p->GetResName()); if (res_name == "HOH") if (! do_sticks_for_waters) @@ -7118,7 +7118,7 @@ Bond_lines_container::do_colour_by_dictionary_and_by_chain_bonds_carbons_only(co coot::Cartesian small_vec_y(0.0, star_size, 0.0); coot::Cartesian small_vec_z(0.0, 0.0, star_size); int col = atom_colour(at, atom_colour_type, udd_user_defined_atom_colour_index_handle, &atom_colour_map); - coot::Cartesian atom_pos(at->x, at->y, at->z); + coot::Cartesian atom_pos(at->x(), at->y(), at->z()); int iat_1 = -1; int udd_status_1 = at->GetUDData(udd_atom_index_handle, iat_1); @@ -7206,19 +7206,19 @@ Bond_lines_container::add_polymer_bonds_generic(const atom_selection_container_t for (int iat=0; iatGetAtom(iat); if (! at_1->isTer()) { - std::string at_1_name(at_1->name); + std::string at_1_name(at_1->GetAtomName()); if (at_1_name == res_1_atom_name) { for (int jat=0; jatGetAtom(jat); if (! at_2->isTer()) { - std::string at_2_name(at_2->name); + std::string at_2_name(at_2->GetAtomName()); if (at_2_name == res_2_atom_name) { - std::string alt_conf_1(at_1->altLoc); - std::string alt_conf_2(at_2->altLoc); + std::string alt_conf_1(at_1->altLoc()); + std::string alt_conf_2(at_2->altLoc()); if (alt_conf_1 == alt_conf_2 || alt_conf_1 == "" || alt_conf_2 == "") { - coot::Cartesian atom_1_pos(at_1->x, at_1->y, at_1->z); - coot::Cartesian atom_2_pos(at_2->x, at_2->y, at_2->z); + coot::Cartesian atom_1_pos(at_1->x(), at_1->y(), at_1->z()); + coot::Cartesian atom_2_pos(at_2->x(), at_2->y(), at_2->z()); int res_no_delta = residue_next_p->GetSeqNum() - residue_this_p->GetSeqNum(); bool do_it = true; @@ -7545,20 +7545,20 @@ Bond_lines_container::do_colour_by_chain_bonds(const atom_selection_container_t if (chain_id_1 == chain_id_2) { - element1 = at1->element; - element2 = at2->element; + element1 = at1->GetElementName(); + element2 = at2->GetElementName(); if ( (draw_hydrogens_flag == 1) || // (element1 != " H" && element1 != " D" && // element2 != " H" && element2 != " D") ) { (! is_hydrogen(element1) && ! is_hydrogen(element2))) { - coot::Cartesian atom_1(at1->x, at1->y, at1->z); - coot::Cartesian atom_2(at2->x, at2->y, at2->z); + coot::Cartesian atom_1(at1->x(), at1->y(), at1->z()); + coot::Cartesian atom_2(at2->x(), at2->y(), at2->z()); // alternate location test // - std::string aloc_1(at1->altLoc); - std::string aloc_2(at2->altLoc); + std::string aloc_1(at1->altLoc()); + std::string aloc_2(at2->altLoc()); // if (aloc_1 == "" || aloc_2 == "" || aloc_1 == aloc_2) { bonds_size_colour_check(col); @@ -7606,9 +7606,9 @@ Bond_lines_container::do_colour_by_chain_bonds(const atom_selection_container_t << std::endl; } else { if ((ic == graphical_bonds_container::NO_BOND) || - (!strcmp(atom_selection[i]->element, " S")) || - (!strcmp(atom_selection[i]->element, "SE")) || - (!strcmp(atom_selection[i]->element, " P"))) { + (!strcmp(atom_selection[i]->GetElementName(), " S")) || + (!strcmp(atom_selection[i]->GetElementName(), "SE")) || + (!strcmp(atom_selection[i]->GetElementName(), " P"))) { std::string segid(atom_selection[i]->GetChainID()); col = atom_colour_map.index_for_chain(segid); @@ -7617,14 +7617,14 @@ Bond_lines_container::do_colour_by_chain_bonds(const atom_selection_container_t // So, was this a seleno-methione? // - mmdb::Residue *atom_residue_p = atom_selection[i]->residue; + mmdb::Residue *atom_residue_p = atom_selection[i]->GetResidue(); if (atom_residue_p) { std::string resname = atom_selection[i]->GetResName(); if (resname == "MSE" || resname == "MET" || resname == "MSO" || resname == "CYS") { // handle_MET_or_MSE_case(atom_selection[i], uddHnd, udd_atom_index_handle, col); } else { - std::string ele = atom_selection[i]->element; + std::string ele = atom_selection[i]->GetElementName(); if (ele == "CL" || ele == "BR" || ele == " S" || ele == " I" || ele == "Cl" || ele == "Br" || ele == "MO" || ele == "PT" || ele == "RU" @@ -7649,16 +7649,16 @@ Bond_lines_container::do_colour_by_chain_bonds(const atom_selection_container_t if (atom_selection[i]->GetUDData(uddHnd, ic) == mmdb::UDDATA_Ok) { if (ic == graphical_bonds_container::NO_BOND) { // no contact found - std::string res_name(atom_selection[i]->residue->GetResName()); + std::string res_name(atom_selection[i]->GetResidue()->GetResName()); if (res_name == "HOH") if (! do_sticks_for_waters) continue; col = atom_colour(atom_selection[i], atom_colour_type, udd_user_defined_atom_colour_index_handle); - std::string ele = atom_selection[i]->element; + std::string ele = atom_selection[i]->GetElementName(); if (!is_hydrogen(ele) || draw_hydrogens_flag) { - coot::Cartesian atom(atom_selection[i]->x, - atom_selection[i]->y, - atom_selection[i]->z); + coot::Cartesian atom(atom_selection[i]->x(), + atom_selection[i]->y(), + atom_selection[i]->z()); int iat_1 = 1; // 20171224-PE FIXME real addBond(col, atom+small_vec_x, atom-small_vec_x, cc, imodel, iat_1, iat_1, true, true); @@ -7808,8 +7808,8 @@ Bond_lines_container::do_colour_by_chain_bonds_carbons_only(const atom_selection if (segid1 == segid2) { - element1 = at1->element; - element2 = at2->element; + element1 = at1->GetElementName(); + element2 = at2->GetElementName(); if ( (draw_hydrogens_flag == 1) || // (element1 != " H" && element1 != " D" && @@ -7817,13 +7817,13 @@ Bond_lines_container::do_colour_by_chain_bonds_carbons_only(const atom_selection (! is_hydrogen(element1) && ! is_hydrogen(element2))) { - coot::Cartesian atom_1(at1->x, at1->y, at1->z); - coot::Cartesian atom_2(at2->x, at2->y, at2->z); + coot::Cartesian atom_1(at1->x(), at1->y(), at1->z()); + coot::Cartesian atom_2(at2->x(), at2->y(), at2->z()); // alternate location test // - std::string aloc_1(at1->altLoc); - std::string aloc_2(at2->altLoc); + std::string aloc_1(at1->altLoc()); + std::string aloc_2(at2->altLoc()); // if (aloc_1 == "" || aloc_2 == "" || aloc_1 == aloc_2) { @@ -7849,8 +7849,8 @@ Bond_lines_container::do_colour_by_chain_bonds_carbons_only(const atom_selection // unbonded (stared) hydrogen atoms. // check the distance. - coot::Cartesian pt_1(at1->x, at1->y, at1->z); - coot::Cartesian pt_2(at2->x, at2->y, at2->z); + coot::Cartesian pt_1(at1->x(), at1->y(), at1->z()); + coot::Cartesian pt_2(at2->x(), at2->y(), at2->z()); double d = (pt_1-pt_2).amplitude(); if (d < 1.5) { @@ -7889,8 +7889,8 @@ Bond_lines_container::do_colour_by_chain_bonds_carbons_only(const atom_selection // 20190921-PE no longer consider P for additional bonds. Stops bond flashing in Goodsell // mode. if ((ic == graphical_bonds_container::NO_BOND) || - (!strcmp(atom_selection[i]->element, " S")) || - (!strcmp(atom_selection[i]->element, "SE")) + (!strcmp(atom_selection[i]->GetElementName(), " S")) || + (!strcmp(atom_selection[i]->GetElementName(), "SE")) // (!strcmp(atom_selection[i]->element, " P") ) { @@ -7904,7 +7904,7 @@ Bond_lines_container::do_colour_by_chain_bonds_carbons_only(const atom_selection // So, was this a seleno-methione? // - mmdb::Residue *atom_residue_p = atom_selection[i]->residue; + mmdb::Residue *atom_residue_p = atom_selection[i]->GetResidue(); if (atom_residue_p) { std::string resname = atom_selection[i]->GetResName(); if (resname == "MSE" || resname == "MET" || resname == "MSO" || resname == "CYS") { @@ -7912,7 +7912,7 @@ Bond_lines_container::do_colour_by_chain_bonds_carbons_only(const atom_selection udd_user_defined_atom_colour_index_handle, atom_colour_type, &atom_colour_map); } else { - std::string ele = atom_selection[i]->element; + std::string ele = atom_selection[i]->GetElementName(); if (ele == "CL" || ele == "BR" || ele == " S" || ele == " I" || ele == "Cl" || ele == "Br" || ele == "MO" || ele == "PT" || ele == "RU" @@ -7939,18 +7939,18 @@ Bond_lines_container::do_colour_by_chain_bonds_carbons_only(const atom_selection if (atom_selection[i]->GetUDData(uddHnd, ic) == mmdb::UDDATA_Ok) { if (ic == graphical_bonds_container::NO_BOND) { // no contact found - mmdb::Residue *residue_p = atom_selection[i]->residue; + mmdb::Residue *residue_p = atom_selection[i]->GetResidue(); std::string res_name(residue_p->GetResName()); if (res_name == "HOH") if (! do_sticks_for_waters) continue; col = atom_colour(atom_selection[i], atom_colour_type, udd_user_defined_atom_colour_index_handle); - std::string ele = atom_selection[i]->element; + std::string ele = atom_selection[i]->GetElementName(); // if (ele != " H" || draw_hydrogens_flag) { if (! is_hydrogen(ele) || draw_hydrogens_flag) { - coot::Cartesian atom(atom_selection[i]->x, - atom_selection[i]->y, - atom_selection[i]->z); + coot::Cartesian atom(atom_selection[i]->x(), + atom_selection[i]->y(), + atom_selection[i]->z()); addBond(col, atom+small_vec_x, atom-small_vec_x, cc, imodel, i, i, true, true); addBond(col, atom+small_vec_y, atom-small_vec_y, cc, imodel, i, i, true, true); @@ -8275,15 +8275,15 @@ Bond_lines_container::do_colour_by_ncs_related_chains_atoms_only(const atom_sele icol = icol_base * 2 + 100; // this is the way for Goodsell colours bool is_C = false; // only care about this if goodsell mode if (goodsell_mode) - is_C = strncmp(at->element, " C", 2); - bool is_H_flag = (is_hydrogen(std::string(at->element))); - coot::Cartesian pos(at->x, at->y, at->z); + is_C = strncmp(at->GetElementName(), " C", 2); + bool is_H_flag = (is_hydrogen(std::string(at->GetElementName()))); + coot::Cartesian pos(at->x(), at->y(), at->z()); graphical_bonds_atom_info_t gbai(pos, iat, is_H_flag); gbai.atom_p = at; bool make_fat_atom = false; // because atoms are rendered as BALLS_NOT_BONDS, they don't // need fattening here. gbai.set_radius_scale_for_atom(at, make_fat_atom); - if (std::string(at->residue->GetResName()) == "HOH") gbai.is_water = true; + if (std::string(at->GetResidue()->GetResName()) == "HOH") gbai.is_water = true; if (goodsell_mode) { if (is_C) icol += 1; // pastel versions } @@ -8411,11 +8411,11 @@ Bond_lines_container::do_colour_by_molecule_bonds(const atom_selection_container res2 = at2->GetSeqNum(); if (abs(res1 - res2) < 2) { - coot::Cartesian atom_1(at1->x, at1->y, at1->z); - coot::Cartesian atom_2(at2->x, at2->y, at2->z); + coot::Cartesian atom_1(at1->x(), at1->y(), at1->z()); + coot::Cartesian atom_2(at2->x(), at2->y(), at2->z()); - element1 = at1->element; - element2 = at2->element; + element1 = at1->GetElementName(); + element2 = at2->GetElementName(); if ( (draw_hydrogens_flag == 1) || // (element1 != " H" && element1 != " D" && // element2 != " H" && element2 != " D") ) { @@ -8423,8 +8423,8 @@ Bond_lines_container::do_colour_by_molecule_bonds(const atom_selection_container // alternate location test // - std::string aloc_1(at1->altLoc); - std::string aloc_2(at2->altLoc); + std::string aloc_1(at1->altLoc()); + std::string aloc_2(at2->altLoc()); // if (aloc_1 == "" || aloc_2 == "" || aloc_1 == aloc_2) { @@ -8470,7 +8470,7 @@ Bond_lines_container::do_colour_by_molecule_bonds(const atom_selection_container if ( atom_selection[i]->GetUDData(uddHnd,ic) == mmdb::UDDATA_Ok ) { // uddHnd for bond state if (ic == 0) { - std::string res_name(atom_selection[i]->residue->GetResName()); + std::string res_name(atom_selection[i]->GetResidue()->GetResName()); if (res_name == "HOH") if (! do_sticks_for_waters) continue; @@ -8478,9 +8478,9 @@ Bond_lines_container::do_colour_by_molecule_bonds(const atom_selection_container std::string segid(atom_selection[i]->GetChainID()); int col_inner = atom_colour_map.index_for_chain(segid); bonds_size_colour_check(col_inner); - coot::Cartesian atom(atom_selection[i]->x, - atom_selection[i]->y, - atom_selection[i]->z); + coot::Cartesian atom(atom_selection[i]->x(), + atom_selection[i]->y(), + atom_selection[i]->z()); addBond(col_inner, atom+small_vec_x, atom-small_vec_x, cc, imodel, i, i, true, true); addBond(col_inner, atom+small_vec_y, atom-small_vec_y, cc, imodel, i, i, true, true); @@ -8508,17 +8508,17 @@ Bond_lines_container::add_zero_occ_spots(const atom_selection_container_t &SelAt zero_occ_spots.clear(); for (int i=0; ioccupancy < 0.01 && - SelAtom.atom_selection[i]->occupancy > -1) { // shelx occ test + if (SelAtom.atom_selection[i]->occupancy() < 0.01 && + SelAtom.atom_selection[i]->occupancy() > -1) { // shelx occ test // we don't want to see atoms with occupancy -61 from a shelx ins // file with zero occupancy spots. - std::string ele(SelAtom.atom_selection[i]->element); + std::string ele(SelAtom.atom_selection[i]->GetElementName()); if (do_bonds_to_hydrogens || ((do_bonds_to_hydrogens == 0) && (! is_hydrogen(ele)))) { if (no_bonds_to_these_atoms.find(i) == no_bonds_to_these_atoms.end()) - zero_occ_spots.push_back(coot::Cartesian(SelAtom.atom_selection[i]->x, - SelAtom.atom_selection[i]->y, - SelAtom.atom_selection[i]->z)); + zero_occ_spots.push_back(coot::Cartesian(SelAtom.atom_selection[i]->x(), + SelAtom.atom_selection[i]->y(), + SelAtom.atom_selection[i]->z())); } } } @@ -8530,11 +8530,11 @@ Bond_lines_container::add_deuterium_spots(const atom_selection_container_t &SelA deuterium_spots.clear(); for (int i=0; ielement); + std::string ele(SelAtom.atom_selection[i]->GetElementName()); if (do_bonds_to_hydrogens && ele == " D") - deuterium_spots.push_back(coot::Cartesian(SelAtom.atom_selection[i]->x, - SelAtom.atom_selection[i]->y, - SelAtom.atom_selection[i]->z)); + deuterium_spots.push_back(coot::Cartesian(SelAtom.atom_selection[i]->x(), + SelAtom.atom_selection[i]->y(), + SelAtom.atom_selection[i]->z())); } } @@ -8558,10 +8558,10 @@ Bond_lines_container::add_ramachandran_goodness_spots(const atom_selection_conta mmdb::Atom *CB = r->GetAtom(" CB "); if (CA && C && N && CB) { - coot::Cartesian ca_pos(CA->x, CA->y, CA->z); - coot::Cartesian c_pos( C->x, C->y, C->z); - coot::Cartesian n_pos( N->x, N->y, N->z); - coot::Cartesian cb_pos(CB->x, CB->y, CB->z); + coot::Cartesian ca_pos(CA->x(), CA->y(), CA->z()); + coot::Cartesian c_pos( C->x(), C->y(), C->z()); + coot::Cartesian n_pos( N->x(), N->y(), N->z()); + coot::Cartesian cb_pos(CB->x(), CB->y(), CB->z()); coot::Cartesian dir_1 = ca_pos - c_pos; coot::Cartesian dir_2 = ca_pos - n_pos; coot::Cartesian dir_3 = ca_pos - cb_pos; @@ -8570,9 +8570,9 @@ Bond_lines_container::add_ramachandran_goodness_spots(const atom_selection_conta status = true; } else { if (CA && C && N) { - coot::Cartesian ca_pos(CA->x, CA->y, CA->z); - coot::Cartesian c_pos( C->x, C->y, C->z); - coot::Cartesian n_pos( N->x, N->y, N->z); + coot::Cartesian ca_pos(CA->x(), CA->y(), CA->z()); + coot::Cartesian c_pos( C->x(), C->y(), C->z()); + coot::Cartesian n_pos( N->x(), N->y(), N->z()); coot::Cartesian dir_1 = ca_pos - c_pos; coot::Cartesian dir_2 = ca_pos - n_pos; coot::Cartesian r = dir_1 + dir_2; @@ -8587,7 +8587,7 @@ Bond_lines_container::add_ramachandran_goodness_spots(const atom_selection_conta std::set sorted_residues_set(residue_sort_function); for (int i=0; iresidue; + mmdb::Residue *this_res = SelAtom.atom_selection[i]->GetResidue(); if (this_res) { sorted_residues_set.insert(this_res); } @@ -8623,7 +8623,7 @@ Bond_lines_container::add_ramachandran_goodness_spots(const atom_selection_conta mmdb::Atom *at = this_res->GetAtom(" CA "); // PDBv3 FIXME if (at) { - coot::Cartesian pos(at->x, at->y, at->z); + coot::Cartesian pos(at->x(), at->y(), at->z()); coot::Cartesian offset_in_HA_dir_uv(0,0,1); auto r = get_HA_unit_vector(this_res); if (r.first) @@ -8722,11 +8722,11 @@ Bond_lines_container::add_atom_centres(int imol, std::cout << " geom: " << geom << " " << coot::atom_spec_t(at) << " have_dict_for_this_type: " << have_dict_for_this_type << std::endl; - if (is_hydrogen(std::string(at->element))) + if (is_hydrogen(std::string(at->GetElementName()))) is_H_flag = true; if (do_bonds_to_hydrogens || (do_bonds_to_hydrogens == 0 && (!is_H_flag))) { - coot::Cartesian pos(at->x, at->y, at->z); + coot::Cartesian pos(at->x(), at->y(), at->z()); graphical_bonds_atom_info_t gbai(pos, idx, is_H_flag); // Fat atoms are for atom in residues with no dictionary - except @@ -8756,7 +8756,7 @@ Bond_lines_container::add_atom_centres(int imol, // because the add_bond function doesn't take a "thin" flag // (thinning is only currently done by bond colour) // - mmdb::Residue *r = at->residue; + mmdb::Residue *r = at->GetResidue(); if (r) { const char *rn = r->GetResName(); if (rn) { @@ -9003,10 +9003,10 @@ graphical_bonds_container::add_cis_peptide_markup(const std::vectorx, q.atom_1->y, q.atom_1->z); - coot::Cartesian c_2(q.atom_2->x, q.atom_2->y, q.atom_2->z); - coot::Cartesian c_3(q.atom_3->x, q.atom_3->y, q.atom_3->z); - coot::Cartesian c_4(q.atom_4->x, q.atom_4->y, q.atom_4->z); + coot::Cartesian c_1(q.atom_1->x(), q.atom_1->y(), q.atom_1->z()); + coot::Cartesian c_2(q.atom_2->x(), q.atom_2->y(), q.atom_2->z()); + coot::Cartesian c_3(q.atom_3->x(), q.atom_3->y(), q.atom_3->z()); + coot::Cartesian c_4(q.atom_4->x(), q.atom_4->y(), q.atom_4->z()); bool pre_pro_flag = false; bool twisted_trans_flag = false; if (cis_peptide_quads[i].type == coot::util::cis_peptide_quad_info_t::PRE_PRO_CIS) diff --git a/coords/Bond_lines.hh b/coords/Bond_lines.hh index ce1a414916..c496f2361b 100644 --- a/coords/Bond_lines.hh +++ b/coords/Bond_lines.hh @@ -112,7 +112,7 @@ namespace coot { int n_H() const { return hydrogen_atoms_.size(); } int n_non_H() const { return non_hydrogen_atoms_.size(); } void add_atom(mmdb::Atom *atom) { - std::string element = atom->element; + std::string element = atom->GetElementName(); if (element == " H" || element == " D") { hydrogen_atoms_.push_back(atom); } else { diff --git a/coords/Bond_lines_ext.cc b/coords/Bond_lines_ext.cc index 0488d3306a..07c99e11fb 100644 --- a/coords/Bond_lines_ext.cc +++ b/coords/Bond_lines_ext.cc @@ -94,13 +94,13 @@ Bond_lines_ext::find_skel_atom_bonds(atom_selection_container_t SelAtom) { int iat_1 = contact[i].id1; int iat_2 = contact[i].id2; - coot::Cartesian atom_1(atom_sel[ contact[i].id1 ]->x, - atom_sel[ contact[i].id1 ]->y, - atom_sel[ contact[i].id1 ]->z); + coot::Cartesian atom_1(atom_sel[ contact[i].id1 ]->x(), + atom_sel[ contact[i].id1 ]->y(), + atom_sel[ contact[i].id1 ]->z()); - coot::Cartesian atom_2(atom_sel[ contact[i].id2 ]->x, - atom_sel[ contact[i].id2 ]->y, - atom_sel[ contact[i].id2 ]->z); + coot::Cartesian atom_2(atom_sel[ contact[i].id2 ]->x(), + atom_sel[ contact[i].id2 ]->y(), + atom_sel[ contact[i].id2 ]->z()); addBond(col, atom_1, atom_2, cc, model_number, iat_1, iat_2, true, true); @@ -186,9 +186,9 @@ Bond_lines_ext::find_molecule_middle(atom_selection_container_t SelAtom, if (max_neighbour_atom_index != -1) { // - centre.set_them(atom_sel[max_neighbour_atom_index]->x, - atom_sel[max_neighbour_atom_index]->y, - atom_sel[max_neighbour_atom_index]->z); + centre.set_them(atom_sel[max_neighbour_atom_index]->x(), + atom_sel[max_neighbour_atom_index]->y(), + atom_sel[max_neighbour_atom_index]->z()); } else { // diff --git a/coords/graphical-bonds-container.hh b/coords/graphical-bonds-container.hh index fbea4fbf23..7dc6d59ff3 100644 --- a/coords/graphical-bonds-container.hh +++ b/coords/graphical-bonds-container.hh @@ -112,7 +112,7 @@ public: float scale = 1.0f; mmdb::Residue *r = atom_p->GetResidue(); if (r) { - std::string ele(atom_p->element); + std::string ele(atom_p->GetElementName()); if (ele == " H") return 0.5f; std::string res_name = r->GetResName(); if (res_name == "HOH") @@ -146,7 +146,7 @@ public: if (atom_index < n_atoms) { if (atom_index >= 0) { mmdb::Atom *at = atom_selection[atom_index]; - position = coot::Cartesian(at->x, at->y, at->z); + position = coot::Cartesian(at->x(), at->y(), at->z()); } } } diff --git a/coords/graphics-line.cc b/coords/graphics-line.cc index 58542e0b59..df141051a1 100644 --- a/coords/graphics-line.cc +++ b/coords/graphics-line.cc @@ -10,8 +10,8 @@ graphics_line_t::update(mmdb::Atom **atom_selection, int n_atoms) { if (atom_index_2 >= 0) { mmdb::Atom *at_1 = atom_selection[atom_index_1]; mmdb::Atom *at_2 = atom_selection[atom_index_2]; - coot::Cartesian p1(at_1->x, at_1->y, at_1->z); - coot::Cartesian p2(at_2->x, at_2->y, at_2->z); + coot::Cartesian p1(at_1->x(), at_1->y(), at_1->z()); + coot::Cartesian p2(at_2->x(), at_2->y(), at_2->z()); positions = coot::CartesianPair(p1, p2); } } diff --git a/coords/loop-path.cc b/coords/loop-path.cc index 231ee0ec25..be877740d7 100644 --- a/coords/loop-path.cc +++ b/coords/loop-path.cc @@ -60,8 +60,8 @@ coot::loop_path(mmdb::Atom *start_back_2, // between them should be flagged with something big and red. // Also, they will be drawn as a straight line, not a spline. - int res_no_start = start->residue->GetSeqNum(); - int res_no_end = end->residue->GetSeqNum(); + int res_no_start = start->GetResidue()->GetSeqNum(); + int res_no_end = end->GetResidue()->GetSeqNum(); int res_no_delta = res_no_end - res_no_start; n_line_segments = 2 * res_no_delta; // don't listen to call parameter! if (n_line_segments < 8) n_line_segments = 8; // sanitize diff --git a/coords/mmdb-crystal.cc b/coords/mmdb-crystal.cc index d59dcdff97..4d1c159678 100644 --- a/coords/mmdb-crystal.cc +++ b/coords/mmdb-crystal.cc @@ -85,9 +85,9 @@ molecule_extents_t::molecule_extents_t(atom_selection_container_t selection, for (int i=0; i< selection.n_selected_atoms; i++) { - atom_x = selection.atom_selection[i]->x; - atom_y = selection.atom_selection[i]->y; - atom_z = selection.atom_selection[i]->z; + atom_x = selection.atom_selection[i]->x(); + atom_y = selection.atom_selection[i]->y(); + atom_z = selection.atom_selection[i]->z(); // if there is only one atom, it will be all the limits, // so we don't use the else. @@ -182,9 +182,9 @@ molecule_extents_t::molecule_extents_t(atom_selection_container_t selection, coot::minimol::residue res(1, "EXT"); for (int i=0; i<6; i++) { coot::minimol::atom at(" CA ", " C", - extents_selection[i]->x, - extents_selection[i]->y, - extents_selection[i]->z, "", 10.0, 1.0); + extents_selection[i]->x(), + extents_selection[i]->y(), + extents_selection[i]->z(), "", 10.0, 1.0); res.addatom(at); } @@ -491,9 +491,9 @@ molecule_extents_t::which_strict_ncs(const coot::Cartesian ¢re_pt, // OK, so what now is the fractional difference between atom and trans_atom? // - diff_x = centre_pt.x() - trans_atom.x; - diff_y = centre_pt.y() - trans_atom.y; - diff_z = centre_pt.z() - trans_atom.z; + diff_x = centre_pt.x() - trans_atom.x(); + diff_y = centre_pt.y() - trans_atom.y(); + diff_z = centre_pt.z() - trans_atom.z(); AtomSel.mol->Orth2Frac(diff_x, diff_y, diff_z, u, v, w); // fill u, v, w. @@ -513,11 +513,11 @@ molecule_extents_t::which_strict_ncs(const coot::Cartesian ¢re_pt, shift_matrix(AtomSel.mol, m[ii], x_shift, y_shift, z_shift, shifted_mat); tmp_atom.Transform(shifted_mat); b = 0.0; - dist = tmp_atom.x - centre_pt.x(); + dist = tmp_atom.x() - centre_pt.x(); b += dist*dist; - dist = tmp_atom.y - centre_pt.y(); + dist = tmp_atom.y() - centre_pt.y(); b += dist*dist; - dist = tmp_atom.z - centre_pt.z(); + dist = tmp_atom.z() - centre_pt.z(); b += dist*dist; if (b < min_dist) { min_dist = b; @@ -672,9 +672,9 @@ molecule_extents_t::trans_sel(mmdb::Cryst *my_cryst, for (int ii=0; ii<6; ii++) { trans_selection[ii] = new mmdb::Atom; - trans_selection[ii]->SetCoordinates(extents_selection[ii]->x, - extents_selection[ii]->y, - extents_selection[ii]->z, + trans_selection[ii]->SetCoordinates(extents_selection[ii]->x(), + extents_selection[ii]->y(), + extents_selection[ii]->z(), 1.0, 99.9); trans_selection[ii]->Transform(my_matt); } @@ -698,9 +698,9 @@ molecule_extents_t::trans_sel(mmdb::Manager *mol, for (int ii=0; ii<6; ii++) { trans_selection[ii] = new mmdb::Atom; - trans_selection[ii]->SetCoordinates(extents_selection[ii]->x, - extents_selection[ii]->y, - extents_selection[ii]->z, + trans_selection[ii]->SetCoordinates(extents_selection[ii]->x(), + extents_selection[ii]->y(), + extents_selection[ii]->z(), 1.0, 99.9); trans_selection[ii]->Transform(my_matt); } @@ -750,9 +750,9 @@ molecule_extents_t::trans_sel(mmdb::Manager *mol, mmdb::mat44 my_mat, for (int ii=0; ii<6; ii++) { trans_selection[ii] = new mmdb::Atom; - trans_selection[ii]->SetCoordinates(extents_selection[ii]->x, - extents_selection[ii]->y, - extents_selection[ii]->z, + trans_selection[ii]->SetCoordinates(extents_selection[ii]->x(), + extents_selection[ii]->y(), + extents_selection[ii]->z(), 1.0, 99.9); trans_selection[ii]->Transform(amat); } @@ -784,32 +784,32 @@ molecule_extents_t::trans_sel_o(mmdb::Manager *mol, const symm_trans_t &symm_tra atom.Copy(extents_selection[0]); atom.Transform(to_origin_matt); atom.Transform(my_matt); - t.front = coot::Cartesian(atom.x, atom.y, atom.z); + t.front = coot::Cartesian(atom.x(), atom.y(), atom.z()); atom.Copy(extents_selection[1]); atom.Transform(to_origin_matt); atom.Transform(my_matt); - t.back = coot::Cartesian(atom.x, atom.y, atom.z); + t.back = coot::Cartesian(atom.x(), atom.y(), atom.z()); atom.Copy(extents_selection[2]); atom.Transform(to_origin_matt); atom.Transform(my_matt); - t.left = coot::Cartesian(atom.x, atom.y, atom.z); + t.left = coot::Cartesian(atom.x(), atom.y(), atom.z()); atom.Copy(extents_selection[3]); atom.Transform(to_origin_matt); atom.Transform(my_matt); - t.right = coot::Cartesian(atom.x, atom.y, atom.z); + t.right = coot::Cartesian(atom.x(), atom.y(), atom.z()); atom.Copy(extents_selection[4]); atom.Transform(to_origin_matt); atom.Transform(my_matt); - t.bottom = coot::Cartesian(atom.x, atom.y, atom.z); + t.bottom = coot::Cartesian(atom.x(), atom.y(), atom.z()); atom.Copy(extents_selection[5]); atom.Transform(to_origin_matt); atom.Transform(my_matt); - t.top = coot::Cartesian(atom.x, atom.y, atom.z); + t.top = coot::Cartesian(atom.x(), atom.y(), atom.z()); return t; } @@ -823,12 +823,12 @@ molecule_extents_t::point_is_in_box(const coot::Cartesian &point, mmdb::PPAtom T // front back left right bottom top // z x y // - coot::Cartesian front(TransSel[0]->x, TransSel[0]->y, TransSel[0]->z); - coot::Cartesian back(TransSel[1]->x, TransSel[1]->y, TransSel[1]->z); - coot::Cartesian left(TransSel[2]->x, TransSel[2]->y, TransSel[2]->z); - coot::Cartesian right(TransSel[3]->x, TransSel[3]->y, TransSel[3]->z); - coot::Cartesian bottom(TransSel[4]->x, TransSel[4]->y, TransSel[4]->z); - coot::Cartesian top(TransSel[5]->x, TransSel[5]->y, TransSel[5]->z); + coot::Cartesian front(TransSel[0]->x(), TransSel[0]->y(), TransSel[0]->z()); + coot::Cartesian back(TransSel[1]->x(), TransSel[1]->y(), TransSel[1]->z()); + coot::Cartesian left(TransSel[2]->x(), TransSel[2]->y(), TransSel[2]->z()); + coot::Cartesian right(TransSel[3]->x(), TransSel[3]->y(), TransSel[3]->z()); + coot::Cartesian bottom(TransSel[4]->x(), TransSel[4]->y(), TransSel[4]->z()); + coot::Cartesian top(TransSel[5]->x(), TransSel[5]->y(), TransSel[5]->z()); coot::Cartesian back_to_front = front - back; coot::Cartesian left_to_right = right - left; @@ -1072,7 +1072,7 @@ coot::Cartesian translate_atom(atom_selection_container_t AtomSel, int ii, trans_atom->Copy(AtomSel.atom_selection[ii]); trans_atom->Transform(my_matt); - coot::Cartesian c(trans_atom->x, trans_atom->y, trans_atom->z); + coot::Cartesian c(trans_atom->x(), trans_atom->y(), trans_atom->z()); delete trans_atom; return c; @@ -1108,7 +1108,7 @@ translate_atom_with_pre_shift(atom_selection_container_t AtomSel, int ii, trans_atom.Transform(pre_shift_matt); trans_atom.Transform(my_matt); - coot::Cartesian c(trans_atom.x, trans_atom.y, trans_atom.z); + coot::Cartesian c(trans_atom.x(), trans_atom.y(), trans_atom.z()); return c; } diff --git a/coords/mmdb-extras.cc b/coords/mmdb-extras.cc index 116476ba2c..03cf055f0c 100644 --- a/coords/mmdb-extras.cc +++ b/coords/mmdb-extras.cc @@ -144,7 +144,7 @@ coot::deep_copy_this_residue_old_style(mmdb::Residue *residue, mmdb::Atom *at = residue_atoms[iat]; if (at) { // can have been deleted if (! at->isTer()) { - std::string this_atom_alt_loc(residue_atoms[iat]->altLoc); + std::string this_atom_alt_loc(residue_atoms[iat]->altLoc()); if (whole_residue_flag || this_atom_alt_loc == altconf || this_atom_alt_loc == "") { atom_p = new mmdb::Atom; @@ -210,10 +210,10 @@ coot::deep_copy_this_residue_and_make_asc(mmdb::Manager *orig_mol, mmdb::Chain *chain_p = new mmdb::Chain; std::string chain_id1 = ((mmdb::Residue *)residue)->GetChainID(); chain_p->SetChainID(chain_id1.c_str()); - rres->seqNum = ((mmdb::Residue *)residue)->GetSeqNum(); + rres->GetSeqNum() = ((mmdb::Residue *)residue)->GetSeqNum(); /* Copy insertion code - a char[10] */ memcpy(rres->insCode, residue->insCode, sizeof(mmdb::InsCode)); - memcpy(rres->name, residue->name, sizeof(mmdb::ResName)); + rres->SetResName(residue->name); mmdb::PPAtom residue_atoms; int nResidueAtoms; @@ -225,7 +225,7 @@ coot::deep_copy_this_residue_and_make_asc(mmdb::Manager *orig_mol, for(int iat=0; iatisTer()) { - std::string this_atom_alt_loc(residue_atoms[iat]->altLoc); + std::string this_atom_alt_loc(residue_atoms[iat]->altLoc()); if (whole_residue_flag || this_atom_alt_loc == altconf || this_atom_alt_loc == "") { atom_p = new mmdb::Atom; @@ -311,7 +311,7 @@ coot::get_first_atom_with_atom_name(const std::string &atomname, mmdb::Atom *atom = NULL; for (int i=0; iname); + std::string name(asc.atom_selection[i]->GetAtomName()); if (name == atomname) { atom = asc.atom_selection[i]; break; diff --git a/coords/mmdb.cc b/coords/mmdb.cc index 9f067067a2..fdaff931b1 100644 --- a/coords/mmdb.cc +++ b/coords/mmdb.cc @@ -65,7 +65,7 @@ centre_of_molecule(atom_selection_container_t SelAtom) { for (int i=0; i< SelAtom.n_selected_atoms; i++) { atom = SelAtom.atom_selection[i]; - coot::Cartesian atom_pos (atom->x, atom->y, atom->z); + coot::Cartesian atom_pos (atom->x(), atom->y(), atom->z()); rs += atom_pos; } @@ -86,9 +86,9 @@ std::ostream& operator<<(std::ostream& s, mmdb::Atom &atom) { // s << atom.GetModelNum() << "/" << atom.GetChainID() << "/" << atom.GetSeqNum() << atom.GetInsCode() << "/" << atom.GetResName() - << "/" << atom.name << " altLoc :" << atom.altLoc << ": pos: (" - << atom.x << "," << atom.y << "," << atom.z - << ") B-factor: " << atom.tempFactor; + << "/" << atom.GetAtomName() << " altLoc :" << atom.altLoc() << ": pos: (" + << atom.x() << "," << atom.y() << "," << atom.z() + << ") B-factor: " << atom.tempFactor(); return s; @@ -103,10 +103,10 @@ std::ostream& operator<<(std::ostream& s, mmdb::PAtom atom) { s << atom->GetModelNum() << "/" << atom->GetChainID() << "/" << atom->GetSeqNum() << atom->GetInsCode() << " {" << atom->GetResName() << "}/" - << atom->name << " altLoc :" << atom->altLoc << ": segid :" + << atom->GetAtomName() << " altLoc :" << atom->altLoc() << ": segid :" << atom->segID << ":" << " pos: (" - << atom->x << "," << atom->y << "," << atom->z - << ") B-factor: " << atom->tempFactor; + << atom->x() << "," << atom->y() << "," << atom->z() + << ") B-factor: " << atom->tempFactor(); } else { s << "NULL"; } @@ -233,7 +233,7 @@ coot::delete_hydrogens_from_mol(mmdb::Manager *mol) { bool deleted = 0; for (int iat=0; iatGetAtom(iat); - std::string ele(at->element); + std::string ele(at->GetElementName()); if (is_hydrogen(ele)) { // delete this atom deleted = 1; diff --git a/coords/phenix-geo-bonds.cc b/coords/phenix-geo-bonds.cc index 5961f829d3..3a48118100 100644 --- a/coords/phenix-geo-bonds.cc +++ b/coords/phenix-geo-bonds.cc @@ -65,13 +65,13 @@ Bond_lines_container::Bond_lines_container(mmdb::Manager *mol, if (previous_atom_1) { atom_1 = previous_atom_1; - atom_1_res = atom_1->residue; + atom_1_res = atom_1->GetResidue(); } coot::residue_spec_t res_2_spec(gb.atom_2); if (atom_1) { - mmdb::Atom *atom_2 = coot::util::get_atom(atom_2_spec, atom_1->residue); + mmdb::Atom *atom_2 = coot::util::get_atom(atom_2_spec, atom_1->GetResidue()); if (res_2_spec == res_1_spec) { @@ -148,7 +148,7 @@ Bond_lines_container::Bond_lines_container(mmdb::Manager *mol, if (atom_1) { coot::residue_spec_t res_2_spec(gb.atom_2); if (res_2_spec == res_1_spec) { - mmdb::Atom *atom_2 = coot::util::get_atom(atom_2_spec, atom_1->residue); + mmdb::Atom *atom_2 = coot::util::get_atom(atom_2_spec, atom_1->GetResidue()); if (atom_2) { bonded_atom_pairs.push_back(bonded_atom_pair_t(atom_1, atom_2, gb.residual)); } else { @@ -176,11 +176,11 @@ Bond_lines_container::Bond_lines_container(mmdb::Manager *mol, if (atom_1) { res_1_spec = coot::residue_spec_t(atom_1->GetResidue()); - atom_1_res=atom_1->residue; + atom_1_res=atom_1->GetResidue(); coot::residue_spec_t res_2_spec(gb.atom_2); if (res_2_spec == res_1_spec) { - mmdb::Atom *atom_2 = coot::util::get_atom(atom_2_spec, atom_1->residue); + mmdb::Atom *atom_2 = coot::util::get_atom(atom_2_spec, atom_1->GetResidue()); if (atom_2) { bonded_atom_pairs.push_back(bonded_atom_pair_t(atom_1, atom_2, gb.residual)); } else { @@ -238,8 +238,8 @@ Bond_lines_container::Bond_lines_container(mmdb::Manager *mol, a1->GetUDData(udd_atom_index_handle, atom_index_1); a2->GetUDData(udd_atom_index_handle, atom_index_2); int col = atom_colour(bap.residual); - addBond(col, coot::Cartesian(a1->x, a1->y, a1->z), - coot::Cartesian(a2->x, a2->y, a2->z), + addBond(col, coot::Cartesian(a1->x(), a1->y(), a1->z()), + coot::Cartesian(a2->x(), a2->y(), a2->z()), cc, model_number, atom_index_1, atom_index_2); } @@ -325,7 +325,7 @@ Bond_lines_container::stars_for_unbonded_atoms(mmdb::Manager *mol, int uddHnd) { if (at) { if (at->GetUDData(uddHnd, ic) == mmdb::UDDATA_Ok) { if (ic == graphical_bonds_container::NO_BOND) { - coot::Cartesian atom_pos(at->x, at->y, at->z); + coot::Cartesian atom_pos(at->x(), at->y(), at->z()); addBond(col, atom_pos+small_vec_x, atom_pos-small_vec_x, cc, -1, -1, -1, true, true); addBond(col, atom_pos+small_vec_y, atom_pos-small_vec_y, cc, -1, -1, -1, true, true); addBond(col, atom_pos+small_vec_z, atom_pos-small_vec_z, cc, -1, -1, -1, true, true); diff --git a/coot-utils/atom-overlaps.cc b/coot-utils/atom-overlaps.cc index d17513195b..28ce1d414f 100644 --- a/coot-utils/atom-overlaps.cc +++ b/coot-utils/atom-overlaps.cc @@ -272,8 +272,8 @@ coot::atom_overlaps_container_t::mark_donors_and_acceptors_central_residue(int u res_central->GetAtomTable(central_residue_atoms, n_central_residue_atoms); for (int iat=0; iatname); - std::string ele = at->element; + std::string atom_name(at->GetAtomName()); + std::string ele = at->GetElementName(); if (ele == " H") { molecule_has_hydrogens = true; // Hydrogens have energy type "H" from Refmac and acedrg, that doesn't @@ -372,8 +372,8 @@ coot::atom_overlaps_container_t::mark_donors_and_acceptors_for_neighbours(int ud neighbours[i]->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); - std::string ele = n_at->element; + std::string atom_name(n_at->GetAtomName()); + std::string ele = n_at->GetElementName(); if (ele == " H") { molecule_has_hydrogens = true; // as above @@ -649,14 +649,14 @@ coot::atom_overlaps_container_t::kludge_filter(mmdb::Atom *at_1, mmdb::Atom *at_ // generate full restraints - which we don't do. bool reject = false; - if (at_1->residue->chain == at_2->residue->chain) { - std::string res_name_1(at_1->residue->GetResName()); + if (at_1->GetResidue()->chain == at_2->GetResidue()->chain) { + std::string res_name_1(at_1->GetResidue()->GetResName()); if (res_name_1 == "ASN") { - std::string res_name_2(at_2->residue->GetResName()); + std::string res_name_2(at_2->GetResidue()->GetResName()); if (res_name_2 == "NAG") { - std::string atom_name_1(at_1->name); + std::string atom_name_1(at_1->GetAtomName()); if (atom_name_1 == " NE2") { - std::string atom_name_2(at_2->name); + std::string atom_name_2(at_2->GetAtomName()); if (atom_name_2 == " C2 ") { reject = true; } @@ -664,11 +664,11 @@ coot::atom_overlaps_container_t::kludge_filter(mmdb::Atom *at_1, mmdb::Atom *at_ } } if (res_name_1 == "NAG") { - std::string res_name_2(at_2->residue->GetResName()); + std::string res_name_2(at_2->GetResidue()->GetResName()); if (res_name_2 == "ASN") { - std::string atom_name_1(at_1->name); + std::string atom_name_1(at_1->GetAtomName()); if (atom_name_1 == " C2 ") { - std::string atom_name_2(at_2->name); + std::string atom_name_2(at_2->GetAtomName()); if (atom_name_2 == " NE2") { reject = true; } @@ -1098,7 +1098,7 @@ coot::hb_t coot::atom_overlaps_container_t::get_h_bond_type(mmdb::Atom *at) { hb_t type = HB_UNASSIGNED; - std::string atom_name = at->name; + std::string atom_name = at->GetAtomName(); std::string res_name = at->GetResName(); type = geom_p->get_h_bond_type(atom_name, res_name, protein_geometry::IMOL_ENC_ANY); // heavyweight @@ -1123,12 +1123,12 @@ coot::atom_overlaps_container_t::contact_dots_for_overlaps() const { // std::cout << "considering overlap idx: " << i << std::endl; - clipper::Coord_orth pt_at_1(overlaps[i].atom_1->x, - overlaps[i].atom_1->y, - overlaps[i].atom_1->z); - clipper::Coord_orth pt_at_2(overlaps[i].atom_2->x, - overlaps[i].atom_2->y, - overlaps[i].atom_2->z); + clipper::Coord_orth pt_at_1(overlaps[i].atom_1->x(), + overlaps[i].atom_1->y(), + overlaps[i].atom_1->z()); + clipper::Coord_orth pt_at_2(overlaps[i].atom_2->x(), + overlaps[i].atom_2->y(), + overlaps[i].atom_2->z()); const double &r_1 = overlaps[i].r_1; const double &r_2 = overlaps[i].r_2; const int &idx = overlaps[i].ligand_atom_index; @@ -1152,7 +1152,7 @@ coot::atom_overlaps_container_t::contact_dots_for_overlaps() const { bool draw_it = ! is_inside_another_ligand_atom(idx, pt_at_surface); if (false) // debugging - if (std::string(overlaps[i].atom_1->name) != " HO3") + if (std::string(overlaps[i].atom_1->GetAtomName()) != " HO3") draw_it = false; if (draw_it) { @@ -1365,7 +1365,7 @@ coot::atom_overlaps_container_t::contact_dots_for_ligand(double dot_density_in) double r_1 = get_vdw_radius_ligand_atom(cr_at); std::vector &sphere_points_for_atom = sphere_points; - if (std::string(cr_at->element) == " H") + if (std::string(cr_at->GetElementName()) == " H") sphere_points_for_atom = H_sphere_points; for (unsigned int j=0; j &sphere_points_for_atom = sphere_points; - if (std::string(at->element) == " H") + if (std::string(at->GetElementName()) == " H") sphere_points_for_atom = H_sphere_points; // if (std::string(at->element) == " H") // dot_density *=0.66; // so that surface dots on H atoms don't appear (weirdly) more fine - if (std::string(at->element) == " H") + if (std::string(at->GetElementName()) == " H") sphere_points_for_atom = H_sphere_points; for (unsigned int j=0; jresidue != atom_with_biggest_overlap->residue) { + if (at->GetResidue() != atom_with_biggest_overlap->GetResidue()) { atom_overlaps_dots_container_t::dot_t dot(overlap_delta, col, pt_at_surface); ao.dots[c_type].push_back(dot); } @@ -2033,7 +2033,7 @@ coot::atom_overlaps_container_t::contacts_for_atom(int iat, std::vector H_sphere_points = fibonacci_sphere(n_sphere_points_for_H); // less than above std::vector sphere_points_for_atom; - if (std::string(at->element) == " H") + if (std::string(at->GetElementName()) == " H") sphere_points_for_atom = H_sphere_points; else sphere_points_for_atom = sphere_points; @@ -2072,7 +2072,7 @@ coot::atom_overlaps_container_t::contacts_for_atom(int iat, for (unsigned int jj=0; jjresidue == at->residue) continue; + if (neighb_atom->GetResidue() == at->GetResidue()) continue; double r_2 = neighb_atom_radius[v[jj]]; double r_2_sqrd = r_2 * r_2; double r_2_plus_prb_squard = r_2_sqrd + 2 * r_2 * probe_radius + @@ -2136,7 +2136,7 @@ coot::atom_overlaps_container_t::contacts_for_atom(int iat, // draw dot if these are atoms from different residues or this is not // a wide contact - if (at->residue != atom_with_biggest_overlap->residue) { + if (at->GetResidue() != atom_with_biggest_overlap->GetResidue()) { atom_overlaps_dots_container_t::dot_t dot(overlap_delta, col, pt_at_surface); ao.dots[c_type].push_back(dot); } else { @@ -2181,8 +2181,8 @@ coot::atom_overlaps_container_t::clashable_alt_confs(mmdb::Atom *at_1, mmdb::Ato bool r = true; - std::string alt_conf_1 = at_1->altLoc; - std::string alt_conf_2 = at_2->altLoc; + std::string alt_conf_1 = at_1->altLoc(); + std::string alt_conf_2 = at_2->altLoc(); if (alt_conf_1.empty()) { return true; @@ -2244,7 +2244,7 @@ coot::atom_overlaps_container_t::is_inside_an_env_atom_to_which_its_bonded(int i // std::cout << "testing env_atom: " << atom_spec_t(env_atom) << std::endl; clipper::Coord_orth pt_env_atom = co(env_atom); double r_2 = 1.6; - std::string ele(env_atom->element); + std::string ele(env_atom->GetElementName()); if (ele == " H") r_2 = 0.97; double r_2_sqrd = r_2 * r_2; @@ -2521,7 +2521,7 @@ coot::atom_overlaps_container_t::setup_env_residue_atoms_radii(int i_sel_hnd_env std::cout << ":::::::::::::::::: in setup_env_residue_atoms_radii() the dictionary_map is of size " << dictionary_map.size() << " and residue_index is " << residue_index << std::endl; - mmdb::Residue *res = at->residue; + mmdb::Residue *res = at->GetResidue(); const dictionary_residue_restraints_t &rest = get_dictionary(res, residue_index); // is rest sane? // std::cout << "debug:: rest has " << rest.atom_info.size() << " atoms "<< std::endl; @@ -2675,8 +2675,8 @@ coot::atom_overlaps_container_t::bonded_angle_or_ring_related(mmdb::Manager *mol // std::string res_name = res_1->GetResName(); std::vector > bps; - std::string atom_name_1 = at_1->name; - std::string atom_name_2 = at_2->name; + std::string atom_name_1 = at_1->GetAtomName(); + std::string atom_name_2 = at_2->GetAtomName(); std::map > >::const_iterator it; it = bonded_neighbours->find(res_name); if (it == bonded_neighbours->end()) { @@ -2912,9 +2912,9 @@ coot::atom_overlaps_container_t::is_ss_bonded_or_CYS_CYS_SGs(mmdb::Atom *at_1, // There is no mmdb class for SSBOND! - must fix. bool status = false; - std::string res_name_1 = at_1->residue->GetResName(); + std::string res_name_1 = at_1->GetResidue()->GetResName(); if (res_name_1 == "CYS") { - std::string res_name_2 = at_2->residue->GetResName(); + std::string res_name_2 = at_2->GetResidue()->GetResName(); if (res_name_2 == "CYS") { std::string atom_name_1 = at_1->GetAtomName(); if (atom_name_1 == " SG ") { @@ -3119,8 +3119,8 @@ coot::atom_overlaps_container_t::are_bonded_residues(mmdb::Residue *res_1, mmdb: if (! r) { // perhaps they are next to each other by serial number but not sequence number - int ser_1 = res_1->index; - int ser_2 = res_2->index; + int ser_1 = res_1->GetIndex(); + int ser_2 = res_2->GetIndex(); if (ser_2 > ser_1) { if ((ser_2 - ser_1) == 1) { if (! res_1->isCTerminus()) { diff --git a/coot-utils/atom-selection-container.cc b/coot-utils/atom-selection-container.cc index cd39f6eccb..603293d883 100644 --- a/coot-utils/atom-selection-container.cc +++ b/coot-utils/atom-selection-container.cc @@ -526,7 +526,7 @@ get_atom_selection(std::string pdb_name, std::cout << i << " " << asc.atom_selection[i]->GetChainID() << " " << asc.atom_selection[i]->GetSeqNum() << " :" - << asc.atom_selection[i]->name << ":" <GetAtomName() << ":" <GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - std::string ele(at->element); + std::string ele(at->GetElementName()); if (ele.length() == 1) { ele = " " + ele; at->SetElementName(ele.c_str()); @@ -677,7 +677,7 @@ fix_nucleic_acid_residue_names(atom_selection_container_t asc) { mmdb::PResidue residue_p; for (int ires=0; iresGetResidue(ires); - std::string residue_name(residue_p->name); + std::string residue_name(residue_p->GetResName()); if (residue_name == "T" || residue_name == "U" || @@ -711,7 +711,7 @@ int fix_nucleic_acid_residue_name(mmdb::Residue *r) { r->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iname); + std::string atom_name(residue_atoms[i]->GetAtomName()); if (atom_name == " O2*") { found_o2_star = 1; break; @@ -727,7 +727,7 @@ int fix_nucleic_acid_residue_name(mmdb::Residue *r) { convert_to_old_nucleotide_atom_names(r); - std::string res_name = r->name; + std::string res_name = r->GetResName(); std::string new_name_stub = res_name.substr(0,1); if (res_name == "DA" || res_name == "DT" || res_name == "DC" || res_name == "DG") @@ -757,9 +757,9 @@ convert_to_old_nucleotide_atom_names(mmdb::Residue *r) { int n_residue_atoms; r->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iname); + std::string atom_name(residue_atoms[i]->GetAtomName()); std::string name_orig = atom_name; - std::string ele(residue_atoms[i]->element); + std::string ele(residue_atoms[i]->GetElementName()); char c3 = atom_name[2]; // 3rd char char c4 = atom_name[3]; // 4th char if (coot::is_hydrogen(ele)) { @@ -777,21 +777,21 @@ convert_to_old_nucleotide_atom_names(mmdb::Residue *r) { atom_name[3] = '*'; } } - strncpy(residue_atoms[i]->name, atom_name.c_str(),5); + residue_atoms[i]->SetAtomName(atom_name.c_str()); } else { // if it is not a hydrogen, simply change the prime to a star if (c4 == '\'') { atom_name[3] = '*'; - strncpy(residue_atoms[i]->name, atom_name.c_str(),5); + residue_atoms[i]->SetAtomName(atom_name.c_str()); } if (atom_name == " OP1") { atom_name = " O1P"; - strncpy(residue_atoms[i]->name, atom_name.c_str(),5); + residue_atoms[i]->SetAtomName(atom_name.c_str()); } if (atom_name == " OP2") { atom_name = " O2P"; - strncpy(residue_atoms[i]->name, atom_name.c_str(),5); + residue_atoms[i]->SetAtomName(atom_name.c_str()); } } // debug @@ -806,12 +806,12 @@ fix_away_atoms(atom_selection_container_t asc) { int nat = 0; for (int i=0; ix > 9998.0) && - (asc.atom_selection[i]->y > 9998.0) && - (asc.atom_selection[i]->z > 9998.0)) { - asc.atom_selection[i]->x = 0.0; - asc.atom_selection[i]->y = 0.0; - asc.atom_selection[i]->z = 0.0; + if ((asc.atom_selection[i]->x() > 9998.0) && + (asc.atom_selection[i]->y() > 9998.0) && + (asc.atom_selection[i]->z() > 9998.0)) { + asc.atom_selection[i]->x() = 0.0; + asc.atom_selection[i]->y() = 0.0; + asc.atom_selection[i]->z() = 0.0; nat++; } } @@ -837,7 +837,7 @@ fix_wrapped_names(atom_selection_container_t asc) { // std::string ele(asc.atom_selection[i]->element); if (1) { - std::string atom_name(asc.atom_selection[i]->name); + std::string atom_name(asc.atom_selection[i]->GetAtomName()); if (atom_name[0] == '1' || atom_name[0] == '2' || atom_name[0] == '3' || @@ -864,7 +864,7 @@ fix_wrapped_names(atom_selection_container_t asc) { // << new_atom_name << ":\n"; if (uddHnd_old >= 0) asc.atom_selection[i]->PutUDData(uddHnd_old, - asc.atom_selection[i]->name); + asc.atom_selection[i]->GetAtomName()); if (uddHnd_new >= 0) asc.atom_selection[i]->PutUDData(uddHnd_new, new_atom_name.c_str()); @@ -876,7 +876,7 @@ fix_wrapped_names(atom_selection_container_t asc) { std::string new_atom_name = " H "; if (uddHnd_old >= 0) asc.atom_selection[i]->PutUDData(uddHnd_old, - asc.atom_selection[i]->name); + asc.atom_selection[i]->GetAtomName()); if (uddHnd_new >= 0) asc.atom_selection[i]->PutUDData(uddHnd_new, (char *) new_atom_name.c_str()); @@ -1100,9 +1100,9 @@ coot::get_molecule_diameter(const atom_selection_container_t &asc) { if (idx_1 != idx_2) { mmdb:: Atom *at_1 = asc.atom_selection[idx_1]; mmdb:: Atom *at_2 = asc.atom_selection[idx_2]; - float dx = at_2->x - at_1->x; - float dy = at_2->y - at_1->y; - float dz = at_2->z - at_1->z; + float dx = at_2->x() - at_1->x(); + float dy = at_2->y() - at_1->y(); + float dz = at_2->z() - at_1->z(); float dd = dx*dx + dy*dy + dz*dz; float d = std::sqrt(dd); s.add(d); diff --git a/coot-utils/atom-selection-container.hh b/coot-utils/atom-selection-container.hh index 4ed88d5187..ed03cb95be 100644 --- a/coot-utils/atom-selection-container.hh +++ b/coot-utils/atom-selection-container.hh @@ -142,7 +142,7 @@ public: for (int i=0; ix, at->y, at->z); + sum += clipper::Coord_orth(at->x(), at->y(), at->z()); count++; } } @@ -158,18 +158,18 @@ public: //! apply shift void apply_shift(float x_shift, float y_shift, float z_shift) { for (int i=0; ix += x_shift; - atom_selection[i]->y += y_shift; - atom_selection[i]->z += z_shift; + atom_selection[i]->x() += x_shift; + atom_selection[i]->y() += y_shift; + atom_selection[i]->z() += z_shift; } } //! apply shift void apply_shift(const clipper::Coord_orth &shift) { for (int i=0; ix += shift.x(); - atom_selection[i]->y += shift.y(); - atom_selection[i]->z += shift.z(); + atom_selection[i]->x() += shift.x(); + atom_selection[i]->y() += shift.y(); + atom_selection[i]->z() += shift.z(); } } diff --git a/coot-utils/bonded-pairs.cc b/coot-utils/bonded-pairs.cc index 883c9d0773..6945f6666d 100644 --- a/coot-utils/bonded-pairs.cc +++ b/coot-utils/bonded-pairs.cc @@ -180,7 +180,7 @@ coot::bonded_pair_t::delete_atom(mmdb::Residue *res, const std::string &atom_nam for (int iat=0; iatname); + std::string at_name(at->GetAtomName()); if (at_name == atom_name) { delete at; at = NULL; diff --git a/coot-utils/c-beta-deviations.cc b/coot-utils/c-beta-deviations.cc index 27b474c452..2c839804b7 100644 --- a/coot-utils/c-beta-deviations.cc +++ b/coot-utils/c-beta-deviations.cc @@ -80,7 +80,7 @@ coot::get_c_beta_deviations(mmdb::Residue *residue_p) { for (int iat=0; iatGetAtom(iat); std::string atom_name(at->GetAtomName()); - std::string alt_conf(at->altLoc); + std::string alt_conf(at->altLoc()); if (atom_name == " N ") alt_conf_map[alt_conf].atom_1 = at; if (atom_name == " CA ") alt_conf_map[alt_conf].atom_2 = at; if (atom_name == " C ") alt_conf_map[alt_conf].atom_3 = at; @@ -95,7 +95,7 @@ coot::get_c_beta_deviations(mmdb::Residue *residue_p) { for(it=alt_conf_map.begin(); it!=alt_conf_map.end(); it++) { const atom_quad &q = it->second; if (q.filled_p()) { - clipper::Coord_orth CB_real_pos(q.atom_4->x, q.atom_4->y, q.atom_4->z); // no coot-utils.h included + clipper::Coord_orth CB_real_pos(q.atom_4->x(), q.atom_4->y(), q.atom_4->z()); // no coot-utils.h included clipper::Coord_orth CB_ideal_pos = make_CB_ideal_pos(q, res_name); double dsqrd = (CB_ideal_pos-CB_real_pos).lengthsq(); double d = sqrt(dsqrd); @@ -124,9 +124,9 @@ coot::make_CB_ideal_pos(const coot::atom_quad &q, const std::string &res_name) { if (res_name == std::string("PRO")) is_PRO = true; - clipper::Coord_orth pt_1(q.atom_1->x, q.atom_1->y, q.atom_1->z); - clipper::Coord_orth pt_2(q.atom_2->x, q.atom_2->y, q.atom_2->z); - clipper::Coord_orth pt_3(q.atom_3->x, q.atom_3->y, q.atom_3->z); + clipper::Coord_orth pt_1(q.atom_1->x(), q.atom_1->y(), q.atom_1->z()); + clipper::Coord_orth pt_2(q.atom_2->x(), q.atom_2->y(), q.atom_2->z()); + clipper::Coord_orth pt_3(q.atom_3->x(), q.atom_3->y(), q.atom_3->z()); double l = 1.53; double a1 = clipper::Util::d2rad(111.0); diff --git a/coot-utils/cablam-markup.cc b/coot-utils/cablam-markup.cc index 07a0f7f82d..1b35008435 100644 --- a/coot-utils/cablam-markup.cc +++ b/coot-utils/cablam-markup.cc @@ -49,7 +49,7 @@ coot::cablam_markup_t::cablam_markup_t(mmdb::Atom *O_prev_at, if (! CA_this_at) return; if (! CA_next_at) return; score = -1; - residue = O_this_at->residue; + residue = O_this_at->GetResidue(); O_prev_pos = co(O_prev_at); O_this_pos = co(O_this_at); O_next_pos = co(O_next_at); @@ -127,7 +127,7 @@ coot::calc_cablam(mmdb::Chain *chain_p, mmdb::Residue *residue_this_p, int n_atoms_next_next = residue_next_next_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - std::string alt_loc(at->altLoc); + std::string alt_loc(at->altLoc()); if (alt_loc.empty()) { // no cablams for altconfed atoms std::string atom_name(at->GetAtomName()); if (atom_name == " O ") { @@ -142,7 +142,7 @@ coot::calc_cablam(mmdb::Chain *chain_p, mmdb::Residue *residue_this_p, } for (int iat=0; iatGetAtom(iat); - std::string alt_loc(at->altLoc); + std::string alt_loc(at->altLoc()); if (alt_loc.empty()) { // no cablams for altconfed atoms std::string atom_name(at->GetAtomName()); if (atom_name == " O ") { @@ -157,7 +157,7 @@ coot::calc_cablam(mmdb::Chain *chain_p, mmdb::Residue *residue_this_p, } for (int iat=0; iatGetAtom(iat); - std::string alt_loc(at->altLoc); + std::string alt_loc(at->altLoc()); if (alt_loc.empty()) { // no cablams for altconfed atoms std::string atom_name(at->GetAtomName()); if (atom_name == " O ") { @@ -172,7 +172,7 @@ coot::calc_cablam(mmdb::Chain *chain_p, mmdb::Residue *residue_this_p, } for (int iat=0; iatGetAtom(iat); - std::string alt_loc(at->altLoc); + std::string alt_loc(at->altLoc()); if (alt_loc.empty()) { // no cablams for altconfed atoms std::string atom_name(at->GetAtomName()); if (atom_name == " CA ") { diff --git a/coot-utils/cfc.cc b/coot-utils/cfc.cc index 46886b4eda..853584f18a 100644 --- a/coot-utils/cfc.cc +++ b/coot-utils/cfc.cc @@ -112,10 +112,10 @@ cfc::chemical_feature_clustering(const std::vector &mol_infos for (int iat=0; iatisTer()) { - clipper::Coord_orth posc(at->x, at->y, at->z); + clipper::Coord_orth posc(at->x(), at->y(), at->z()); double dd = (posc - pt_ref).lengthsq(); if (dd < dist_crit_sq) { - RDGeom::Point3D pos(at->x, at->y, at->z); + RDGeom::Point3D pos(at->x(), at->y(), at->z()); coot::residue_spec_t res_spec(residue_p); water_info_t wi(imol, res_spec, pos); waters.push_back(wi); @@ -615,9 +615,9 @@ cfc::chemical_feature_clustering(const std::vector &mol_infos for (int iat=0; iatisTer()) { - float delta_x = at->x - fi.pos.x; - float delta_y = at->y - fi.pos.y; - float delta_z = at->z - fi.pos.z; + float delta_x = at->x() - fi.pos.x; + float delta_y = at->y() - fi.pos.y; + float delta_z = at->z() - fi.pos.z; float dd = delta_x * delta_x + delta_y * delta_y + delta_z * delta_z; if (dd < dist_crit * dist_crit) return true; diff --git a/coot-utils/contact-info.cc b/coot-utils/contact-info.cc index d2a546c807..0aaf3164b1 100644 --- a/coot-utils/contact-info.cc +++ b/coot-utils/contact-info.cc @@ -44,11 +44,11 @@ coot::contact_info::contact_info(mmdb::PPAtom atom_selection, mmdb::Contact *con for (int i=0; ielement; - std::string ele_2 = at_2->element; - mmdb::realtype dx = at_1->x - at_2->x; - mmdb::realtype dy = at_1->y - at_2->y; - mmdb::realtype dz = at_1->z - at_2->z; + std::string ele_1 = at_1->GetElementName(); + std::string ele_2 = at_2->GetElementName(); + mmdb::realtype dx = at_1->x() - at_2->x(); + mmdb::realtype dy = at_1->y() - at_2->y(); + mmdb::realtype dz = at_1->z() - at_2->z(); mmdb::realtype dist_2 = dx*dx + dy*dy + dz*dz; mmdb::realtype dist = sqrt(dist_2); mmdb::realtype r1 = get_radius(ele_1); @@ -77,7 +77,7 @@ coot::contact_info::contact_info(const atom_selection_container_t &asc, if (r.first) { std::map name_map; for (int i=0; iname); + std::string atom_name(asc.atom_selection[i]->GetAtomName()); name_map[atom_name] = map_index_t(i); } @@ -112,8 +112,8 @@ coot::contact_info::contact_info(const atom_selection_container_t &asc, if (r.first) { std::map name_map; for (int i=0; iname); - std::string atom_alt_conf(asc.atom_selection[i]->altLoc); + std::string atom_name(asc.atom_selection[i]->GetAtomName()); + std::string atom_alt_conf(asc.atom_selection[i]->altLoc()); if (atom_alt_conf.empty() || atom_alt_conf == alt_conf) { name_map[atom_name] = map_index_t(i); } @@ -148,7 +148,7 @@ coot::contact_info::contact_info(const atom_selection_container_t &asc, int imol // fill residues and atoms_in_residue for (int i=0; iresidue; + mmdb::Residue *r = asc.atom_selection[i]->GetResidue(); if (std::find(residues.begin(), residues.end(), r) == residues.end()) residues.push_back(r); atoms_in_residue[r].push_back(i); @@ -198,10 +198,10 @@ coot::contact_info::contact_info(const atom_selection_container_t &asc, int imol if (order_switch == false) { for (unsigned int iat_1=0; iat_1name; + std::string atom_name_1 = asc.atom_selection[iat_1]->GetAtomName(); if (link_bond_atom_name_1 == atom_name_1) { for (unsigned int iat_2=0; iat_2name; + std::string atom_name_2 = asc.atom_selection[iat_2]->GetAtomName(); if (link_bond_atom_name_2 == atom_name_2) { contacts_pair p(iat_1, iat_2); contacts.push_back(p); @@ -213,10 +213,10 @@ coot::contact_info::contact_info(const atom_selection_container_t &asc, int imol // order switch for (unsigned int iat_1=0; iat_1name; + std::string atom_name_1 = asc.atom_selection[iat_1]->GetAtomName(); if (link_bond_atom_name_2 == atom_name_1) { for (unsigned int iat_2=0; iat_2name; + std::string atom_name_2 = asc.atom_selection[iat_2]->GetAtomName(); if (link_bond_atom_name_1 == atom_name_2) { contacts_pair p(iat_1, iat_2); contacts.push_back(p); @@ -242,15 +242,15 @@ coot::contact_info::contacts_from_monomer_restraints(const atom_selection_contai // for (int iat=0; iatname; + std::string atom_name_1 = at_1->GetAtomName(); for (int jat=0; jatresidue == at_2->residue) { - std::string atom_name_2 = at_2->name; + if (at_1->GetResidue() == at_2->GetResidue()) { + std::string atom_name_2 = at_2->GetAtomName(); // was there a bond between them? const std::vector &bond_restraints = - res_restraints[at_1->residue].bond_restraint; + res_restraints[at_1->GetResidue()].bond_restraint; for (unsigned int ibond=0; ibondresidue; + mmdb::Residue *r = asc.atom_selection[i]->GetResidue(); if (std::find(residues.begin(), residues.end(), r) == residues.end()) residues.push_back(r); atoms_in_residue[r].push_back(i); @@ -344,8 +344,8 @@ coot::contact_info::contact_info(mmdb::Manager *mol, int imol, // now the bond between monomers (middle atoms must be in different residues). for (unsigned int itor=0; itorresidue; - mmdb::Residue *r2 = link_torsions[itor].atom_3->residue; + mmdb::Residue *r1 = link_torsions[itor].atom_2->GetResidue(); + mmdb::Residue *r2 = link_torsions[itor].atom_3->GetResidue(); if (r1 != r2) { for (int i=0; iname; + std::string atom_name = asc.atom_selection[i]->GetAtomName(); if (atom_name == "SE ") SE_index = i; if (atom_name == " CE ") CE_index = i; if (atom_name == " CG ") CG_index = i; diff --git a/coot-utils/contacts-by-bricks.cc b/coot-utils/contacts-by-bricks.cc index 50e2a68818..cd18de7e85 100644 --- a/coot-utils/contacts-by-bricks.cc +++ b/coot-utils/contacts-by-bricks.cc @@ -75,9 +75,9 @@ coot::contacts_by_bricks::fill_the_bricks() { mmdb::Atom *at = atoms[i]; int idx_3d[3]; // beware when copying this later - when atoms move? - idx_3d[0] = static_cast ((at->x - lower_left[0]) * inv_brick_size); - idx_3d[1] = static_cast ((at->y - lower_left[1]) * inv_brick_size); - idx_3d[2] = static_cast ((at->z - lower_left[2]) * inv_brick_size); + idx_3d[0] = static_cast ((at->x() - lower_left[0]) * inv_brick_size); + idx_3d[1] = static_cast ((at->y() - lower_left[1]) * inv_brick_size); + idx_3d[2] = static_cast ((at->z() - lower_left[2]) * inv_brick_size); unsigned int idx_1d = idx_3d_to_idx_1d(idx_3d); // atoms that fly over the edge don't have NBCs :-) unsigned int n_bricks = atoms_in_bricks.size(); @@ -135,7 +135,7 @@ coot::contacts_by_bricks::set_lower_left_and_range(mmdb::PAtom *atoms_in, int n_ for(unsigned int i=0; ix; pos[1] = atom->y; pos[2] = atom->z; + pos[0] = atom->x(); pos[1] = atom->y(); pos[2] = atom->z(); for (int j=0; j<3; j++) if (pos[j] < lower_left[j]) lower_left[j] = pos[j]; @@ -148,7 +148,7 @@ coot::contacts_by_bricks::set_lower_left_and_range(mmdb::PAtom *atoms_in, int n_ for(unsigned int i=0; ix; pos[1] = atom->y; pos[2] = atom->z; + pos[0] = atom->x(); pos[1] = atom->y(); pos[2] = atom->z(); for (int j=0; j<3; j++) { if (false) std::cout @@ -208,11 +208,11 @@ coot::contacts_by_bricks::find_the_contacts_in_bricks(std::vectorresidue == at_1->residue) + if (at_2->GetResidue() == at_1->GetResidue()) continue; - float d_x(at_1->x - at_2->x); - float d_y(at_1->y - at_2->y); - float d_z(at_1->z - at_2->z); + float d_x(at_1->x() - at_2->x()); + float d_y(at_1->y() - at_2->y()); + float d_z(at_1->z() - at_2->z()); float dd = d_x * d_x + d_y * d_y + d_z * d_z; if (dd < dist_max_sqrd) { vec->at(*it_base).insert(*it_neighb); @@ -324,11 +324,11 @@ coot::contacts_by_bricks::find_the_contacts_between_bricks_multi_thread_workpack for (it_neighb=brick_neighb.begin(); it_neighb!=brick_neighb.end(); it_neighb++) { mmdb::Atom *at_2 = atoms[*it_neighb]; if (only_between_different_residues_flag) - if (at_2->residue == at_1->residue) + if (at_2->GetResidue() == at_1->GetResidue()) continue; - float d_x(at_1->x - at_2->x); - float d_y(at_1->y - at_2->y); - float d_z(at_1->z - at_2->z); + float d_x(at_1->x() - at_2->x()); + float d_y(at_1->y() - at_2->y()); + float d_z(at_1->z() - at_2->z()); float dd(d_x * d_x + d_y * d_y + d_z * d_z); // std::cout << "MP " << *it_base << " " << *it_neighb << " sqrt(dd) " << sqrt(dd) << std::endl; if (dd < dist_max_sqrd) { @@ -390,11 +390,11 @@ coot::contacts_by_bricks::find_the_contacts_between_bricks_simple(std::vectorresidue == at_1->residue) + if (at_2->GetResidue() == at_1->GetResidue()) continue; - float d_x(at_1->x - at_2->x); - float d_y(at_1->y - at_2->y); - float d_z(at_1->z - at_2->z); + float d_x(at_1->x() - at_2->x()); + float d_y(at_1->y() - at_2->y()); + float d_z(at_1->z() - at_2->z()); float dd(d_x * d_x + d_y * d_y + d_z * d_z); if (dd < dist_max_sqrd) { vec->at(*it_base).insert(*it_neighb); diff --git a/coot-utils/coot-coord-extras.cc b/coot-utils/coot-coord-extras.cc index b521b56241..9e933f2e76 100644 --- a/coot-utils/coot-coord-extras.cc +++ b/coot-utils/coot-coord-extras.cc @@ -60,7 +60,7 @@ coot::util::check_dictionary_for_residues(mmdb::PResidue *SelResidues, int nSelR int fail = 0; // not fail initially. for (int ires=0; iresname); + std::string resname(SelResidues[ires]->GetResName()); status = geom_p->have_dictionary_for_residue_type(resname, imol_enc, read_number); // This bit is redundant now that try_dynamic_add has been added // to have_dictionary_for_residue_type(): @@ -104,7 +104,7 @@ coot::GetResidue(const minimol::residue &res_in) { // reset new_alt_loc for (unsigned int ic=0; icaltLoc, mat.altLoc.c_str(), new_length); + strncpy(at->altLoc(), mat.altLoc.c_str(), new_length); res->AddAtom(at); } @@ -132,7 +132,7 @@ coot::util::get_contact_indices_from_restraints(mmdb::Residue *residue, int nResidueAtoms = residue->GetNumberOfAtoms(); std::vector > contact_indices(nResidueAtoms); - std::string restype(residue->name); + std::string restype(residue->GetResName()); int n_monomers = geom_p->size(); @@ -142,7 +142,7 @@ coot::util::get_contact_indices_from_restraints(mmdb::Residue *residue, for (int iat=0; iatGetAtom(iat); if (! atom_p->isTer()) { - std::string atom_ele(atom_p->element); + std::string atom_ele(atom_p->GetElementName()); if (atom_ele == " D") { has_deuterium_atoms = true; break; @@ -600,7 +600,7 @@ coot::match_torsions::get_torsion(mmdb::Residue *res, const coot::atom_name_quad if (atoms[0] && atoms[1] && atoms[2] && atoms[3]) { clipper::Coord_orth pts[4]; for (unsigned int i=0; i<4; i++) - pts[i] = clipper::Coord_orth(atoms[i]->x, atoms[i]->y, atoms[i]->z); + pts[i] = clipper::Coord_orth(atoms[i]->x(), atoms[i]->y(), atoms[i]->z()); tors = clipper::Coord_orth::torsion(pts[0], pts[1], pts[2], pts[3]); // radians status = 1; } @@ -674,11 +674,11 @@ coot::match_torsions::apply_torsion_by_contacts(const coot::atom_name_quad &movi if (at) { if (0) std::cout << "transfering coords was " - << at->z << " " << at->y << " " << at->z << " to " + << at->z() << " " << at->y() << " " << at->z() << " to " << ligand_residue.atoms[iat] << std::endl; - at->x = wiggled_ligand_residue.atoms[iat].pos.x(); - at->y = wiggled_ligand_residue.atoms[iat].pos.y(); - at->z = wiggled_ligand_residue.atoms[iat].pos.z(); + at->x() = wiggled_ligand_residue.atoms[iat].pos.x(); + at->y() = wiggled_ligand_residue.atoms[iat].pos.y(); + at->z() = wiggled_ligand_residue.atoms[iat].pos.z(); n_transfered++; } } @@ -728,13 +728,13 @@ coot::torsionable_bonds_monomer_internal(mmdb::Residue *residue_p, std::string tr_atom_name_3 = tors_restraints[itor].atom_id_3_4c(); for (int iat1=0; iat1residue; - std::string atom_name_1 = atom_selection[iat1]->name; + mmdb::Residue *res_1 = atom_selection[iat1]->GetResidue(); + std::string atom_name_1 = atom_selection[iat1]->GetAtomName(); for (int iat2=0; iat2residue; + mmdb::Residue *res_2 = atom_selection[iat2]->GetResidue(); if (res_1 == res_2) { - std::string atom_name_2 = atom_selection[iat2]->name; + std::string atom_name_2 = atom_selection[iat2]->GetAtomName(); if (atom_name_1 == tr_atom_name_2) { if (atom_name_2 == tr_atom_name_3) { @@ -792,8 +792,8 @@ coot::torsionable_bonds_monomer_internal_quads(mmdb::Residue *residue_p, (! is_pyranose)) { for (unsigned int ialt=0; ialtname; - std::string alt_conf = atom_selection[iat]->altLoc; + std::string atom_name = atom_selection[iat]->GetAtomName(); + std::string alt_conf = atom_selection[iat]->altLoc(); if (alt_conf == residue_alt_confs[ialt]) { for (unsigned int jtor=1; jtor<5; jtor++) { if (atom_name == tor_atom_name[jtor]) @@ -829,7 +829,7 @@ coot::linkrs_in_atom_selection(mmdb::Manager *mol, mmdb::PPAtom atom_selection, // normal case std::vector residues; for (int i=0; iresidue; + mmdb::Residue *r = atom_selection[i]->GetResidue(); if (std::find(residues.begin(), residues.end(), r) == residues.end()) residues.push_back(r); } @@ -949,7 +949,7 @@ coot::util::CO_orientations(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); std::string atom_name(at->GetAtomName()); - std::string alt_conf(at->altLoc); + std::string alt_conf(at->altLoc()); if (alt_conf == "") { if (atom_name == " C ") prev_C = at; if (atom_name == " O ") prev_O = at; @@ -960,7 +960,7 @@ coot::util::CO_orientations(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); std::string atom_name(at->GetAtomName()); - std::string alt_conf(at->altLoc); + std::string alt_conf(at->altLoc()); if (alt_conf == "") { if (atom_name == " C ") this_C = at; if (atom_name == " O ") this_O = at; @@ -971,7 +971,7 @@ coot::util::CO_orientations(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); std::string atom_name(at->GetAtomName()); - std::string alt_conf(at->altLoc); + std::string alt_conf(at->altLoc()); if (alt_conf == "") { if (atom_name == " C ") next_C = at; if (atom_name == " O ") next_O = at; @@ -1261,7 +1261,7 @@ coot::util::missing_atoms(mmdb::Manager *mol, int n_atoms = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - std::string atom_name(at->name); + std::string atom_name(at->GetAtomName()); // check against each atom in the dictionary: for (unsigned int idictat=0; idictat alt_confs; std::string ac[4]; - ac[0] = ca_first->altLoc; - ac[1] = c_first->altLoc; - ac[2] = n_next->altLoc; - ac[3] = ca_next->altLoc; + ac[0] = ca_first->altLoc(); + ac[1] = c_first->altLoc(); + ac[2] = n_next->altLoc(); + ac[3] = ca_next->altLoc(); for (int i=0; i<4; i++) if (!ac[i].empty()) alt_confs.insert(ac[i]); @@ -1403,10 +1403,10 @@ coot::cis_peptide_quads_from_coords(mmdb::Manager *mol, } } if (! is_ter) { - clipper::Coord_orth caf(ca_first->x, ca_first->y, ca_first->z); - clipper::Coord_orth cf( c_first->x, c_first->y, c_first->z); - clipper::Coord_orth can( ca_next->x, ca_next->y, ca_next->z); - clipper::Coord_orth nn( n_next->x, n_next->y, n_next->z); + clipper::Coord_orth caf(ca_first->x(), ca_first->y(), ca_first->z()); + clipper::Coord_orth cf( c_first->x(), c_first->y(), c_first->z()); + clipper::Coord_orth can( ca_next->x(), ca_next->y(), ca_next->z()); + clipper::Coord_orth nn( n_next->x(), n_next->y(), n_next->z()); double tors = clipper::Coord_orth::torsion(caf, cf, nn, can); double torsion = clipper::Util::rad2d(tors); @@ -1727,18 +1727,18 @@ coot::util::get_dictionary_conformers(const dictionary_residue_restraints_t &res residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatelement); + std::string ele_1(at_1->GetElementName()); if (ele_1 == " H") continue; if (! at_1->isTer()) { for (int jat=0; jatelement); + std::string ele_2(at_2->GetElementName()); if (ele_2 == " H") continue; if (! at_2->isTer()) { - float dx = at_2->x - at_1->x; - float dy = at_2->y - at_1->y; - float dz = at_2->z - at_1->z; + float dx = at_2->x() - at_1->x(); + float dy = at_2->y() - at_1->y(); + float dz = at_2->z() - at_1->z(); if (fabsf(dx) < dist_crit) { if (fabsf(dy) < dist_crit) { if (fabsf(dz) < dist_crit) { @@ -1847,7 +1847,7 @@ coot::util::get_dictionary_conformers(const dictionary_residue_restraints_t &res if (! at_from->isTer()) { std::string atom_name_from = at_from->GetAtomName(); - std::string alt_conf_from = at_from->altLoc; + std::string alt_conf_from = at_from->altLoc(); mmdb::Atom **to_residue_atoms = 0; int n_to_residue_atoms = 0; @@ -1857,26 +1857,26 @@ coot::util::get_dictionary_conformers(const dictionary_residue_restraints_t &res if (! at_to->isTer()) { std::string atom_name_to = at_to->GetAtomName(); - std::string alt_conf_to = at_to->altLoc; + std::string alt_conf_to = at_to->altLoc(); if (atom_name_from == atom_name_to) { if (alt_conf_from == alt_conf_to) { if (debug) { - std::vector was = {at_to->x, at_to->y, at_to->z}; + std::vector was = {at_to->x(), at_to->y(), at_to->z()}; std::cout << "transfered " << coot::atom_spec_t(at_to) << " " << std::setw(8) << was[0] << " " << std::setw(8) << was[1] << " " << std::setw(8) << was[2] << " now " - << std::setw(8) << at_from->x << " " - << std::setw(8) << at_from->y << " " - << std::setw(8) << at_from->z << " " + << std::setw(8) << at_from->x() << " " + << std::setw(8) << at_from->y() << " " + << std::setw(8) << at_from->z() << " " << std::endl; } - at_to->x = at_from->x; - at_to->y = at_from->y; - at_to->z = at_from->z; + at_to->x() = at_from->x(); + at_to->y() = at_from->y(); + at_to->z() = at_from->z(); break; } @@ -1987,7 +1987,7 @@ coot::util::get_dictionary_conformers(const dictionary_residue_restraints_t &res mmdb::Atom *at = residue_atoms[iat]; if (! at->isTer()) { std::cout << " " << lab << " " << iat << " " << coot::atom_spec_t(at) << " " - << at->x << " " << at->y << " " << at->z << std::endl; + << at->x() << " " << at->y() << " " << at->z() << std::endl; } } }; @@ -2135,12 +2135,12 @@ coot::util::mutate_by_overlap(mmdb::Residue *residue_p, mmdb::Manager *mol, if (atom_name != " O " || move_O_atom) { - at_mutable->x = at->x; - at_mutable->y = at->y; - at_mutable->z = at->z; + at_mutable->x() = at->x(); + at_mutable->y() = at->y(); + at_mutable->z() = at->z(); if (false) std::cout << "moved atom " << coot::atom_spec_t(at_mutable) - << " to " << at->x << " " << at->y << " " << at->z << std::endl; + << " to " << at->x() << " " << at->y() << " " << at->z() << std::endl; } } } @@ -2158,7 +2158,7 @@ coot::util::mutate_by_overlap(mmdb::Residue *residue_p, mmdb::Manager *mol, std::string at_name = at->GetAtomName(); if (atom_name != " OXT") { // extra atom in an amino acid if (! (atom_name != " OP3" && is_nucleotide)) { // extra atom in a nucleic acid - std::string ele = at->element; + std::string ele = at->GetElementName(); if (ele == " H") continue; at_copy->Copy(at); res_mutable->AddAtom(at_copy); diff --git a/coot-utils/coot-coord-lsq.cc b/coot-utils/coot-coord-lsq.cc index adbdaf86d7..ce8a1c40d7 100644 --- a/coot-utils/coot-coord-lsq.cc +++ b/coot-utils/coot-coord-lsq.cc @@ -308,8 +308,8 @@ coot::util::get_matching_indices(mmdb::Manager *mol1, << std::endl; } if (at1 && at2) { - v1.push_back(clipper::Coord_orth(at1->x, at1->y, at1->z)); - v2.push_back(clipper::Coord_orth(at2->x, at2->y, at2->z)); + v1.push_back(clipper::Coord_orth(at1->x(), at1->y(), at1->z())); + v2.push_back(clipper::Coord_orth(at2->x(), at2->y(), at2->z())); } } @@ -340,8 +340,8 @@ coot::util::get_matching_indices(mmdb::Manager *mol1, std::cout << "Found match " << atom_spec_t(at1) << " to " << atom_spec_t(at2) << std::endl; - v1.push_back(clipper::Coord_orth(at1->x, at1->y, at1->z)); - v2.push_back(clipper::Coord_orth(at2->x, at2->y, at2->z)); + v1.push_back(clipper::Coord_orth(at1->x(), at1->y(), at1->z())); + v2.push_back(clipper::Coord_orth(at2->x(), at2->y(), at2->z())); } } } @@ -360,8 +360,8 @@ coot::util::get_matching_indices(mmdb::Manager *mol1, if (at2) { if (! at1->isTer()) { if (! at2->isTer()) { - v1.push_back(clipper::Coord_orth(at1->x, at1->y, at1->z)); - v2.push_back(clipper::Coord_orth(at2->x, at2->y, at2->z)); + v1.push_back(clipper::Coord_orth(at1->x(), at1->y(), at1->z())); + v2.push_back(clipper::Coord_orth(at2->x(), at2->y(), at2->z())); } } } @@ -383,17 +383,17 @@ coot::util::get_matching_indices(mmdb::Manager *mol1, SelResidue_2[0]->GetAtomTable(residue_atoms2, n_residue_atoms2); for (int iat=0; iatname); - std::string at1_altconf(at1->altLoc); + std::string at1_name(at1->GetAtomName()); + std::string at1_altconf(at1->altLoc()); for (int jat=0; jatname); - std::string at2_altconf(at2->altLoc); + std::string at2_name(at2->GetAtomName()); + std::string at2_altconf(at2->altLoc()); if (at1_name == at2_name) { if (at1_altconf == at2_altconf) { - v1.push_back(clipper::Coord_orth(at1->x, at1->y, at1->z)); - v2.push_back(clipper::Coord_orth(at2->x, at2->y, at2->z)); + v1.push_back(clipper::Coord_orth(at1->x(), at1->y(), at1->z())); + v2.push_back(clipper::Coord_orth(at2->x(), at2->y(), at2->z())); break; } } @@ -415,18 +415,18 @@ coot::util::get_matching_indices(mmdb::Manager *mol1, // << std::endl; for (int iat=0; iatname); - std::string at1_altconf(at1->altLoc); + std::string at1_name(at1->GetAtomName()); + std::string at1_altconf(at1->altLoc()); if (at1_name == match.reference_atom_name) { if (at1_altconf == match.reference_alt_conf) { for (int jat=0; jatname); - std::string at2_altconf(at2->altLoc); + std::string at2_name(at2->GetAtomName()); + std::string at2_altconf(at2->altLoc()); if (at2_name == match.matcher_atom_name) { if (at2_altconf == match.matcher_alt_conf) { - v1.push_back(clipper::Coord_orth(at1->x, at1->y, at1->z)); - v2.push_back(clipper::Coord_orth(at2->x, at2->y, at2->z)); + v1.push_back(clipper::Coord_orth(at1->x(), at1->y(), at1->z())); + v2.push_back(clipper::Coord_orth(at2->x(), at2->y(), at2->z())); } } } diff --git a/coot-utils/coot-coord-utils-glyco.cc b/coot-utils/coot-coord-utils-glyco.cc index 553f61b13b..ee65d1ab19 100644 --- a/coot-utils/coot-coord-utils-glyco.cc +++ b/coot-utils/coot-coord-utils-glyco.cc @@ -302,16 +302,16 @@ coot::beam_in_linked_residue::get_residue() const { current_torsion = quad.torsion(); double diff = clipper::Util::d2rad(template_torsion - current_torsion); clipper::Coord_orth base; - base = clipper::Coord_orth(at_C5->x, at_C5->y, at_C5->z); - origin_shift = clipper::Coord_orth(at_C6->x, at_C6->y, at_C6->z); - position = clipper::Coord_orth(at_O6->x, at_O6->y, at_O6->z); + base = clipper::Coord_orth(at_C5->x(), at_C5->y(), at_C5->z()); + origin_shift = clipper::Coord_orth(at_C6->x(), at_C6->y(), at_C6->z()); + position = clipper::Coord_orth(at_O6->x(), at_O6->y(), at_O6->z()); direction = origin_shift - base; clipper::Coord_orth new_pos = coot::util::rotate_around_vector(direction, position, origin_shift, diff); - at_O6->x = new_pos.x(); - at_O6->y = new_pos.y(); - at_O6->z = new_pos.z(); + at_O6->x() = new_pos.x(); + at_O6->y() = new_pos.y(); + at_O6->z() = new_pos.z(); } } catch (const std::runtime_error &rte) { @@ -325,26 +325,26 @@ coot::beam_in_linked_residue::get_residue() const { if (r) { // now rotate r and O6 back to current_torsion if (at_O6) { - position = clipper::Coord_orth(at_O6->x, at_O6->y, at_O6->z); + position = clipper::Coord_orth(at_O6->x(), at_O6->y(), at_O6->z()); double diff = clipper::Util::d2rad(template_torsion - current_torsion); clipper::Coord_orth new_pos = coot::util::rotate_around_vector(direction, position, origin_shift, -diff); - at_O6->x = new_pos.x(); - at_O6->y = new_pos.y(); - at_O6->z = new_pos.z(); + at_O6->x() = new_pos.x(); + at_O6->y() = new_pos.y(); + at_O6->z() = new_pos.z(); mmdb::PPAtom residue_atoms = 0; int n_residue_atoms; r->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; ix, at->y, at->z); + clipper::Coord_orth p(at->x(), at->y(), at->z()); clipper::Coord_orth n = coot::util::rotate_around_vector(direction, p, origin_shift, -diff); - at->x = n.x(); - at->y = n.y(); - at->z = n.z(); + at->x() = n.x(); + at->y() = n.y(); + at->z() = n.z(); } } } @@ -502,8 +502,8 @@ coot::beam_in_linked_residue::lsq_fit(mmdb::Residue *ref_res, std::vector co_1(n); std::vector co_2(n); for (unsigned int iat=0; iatx, va_1[iat]->y, va_1[iat]->z); - co_2[iat] = clipper::Coord_orth(va_2[iat]->x, va_2[iat]->y, va_2[iat]->z); + co_1[iat] = clipper::Coord_orth(va_1[iat]->x(), va_1[iat]->y(), va_1[iat]->z()); + co_2[iat] = clipper::Coord_orth(va_2[iat]->x(), va_2[iat]->y(), va_2[iat]->z()); } clipper::RTop_orth rtop(co_1, co_2); coot::util::transform_atoms(mov_res, rtop); @@ -525,7 +525,7 @@ coot::beam_in_linked_residue::delete_atom(mmdb::Residue *res, const std::string for (int iat=0; iatname); + std::string at_name(at->GetAtomName()); if (at_name == atom_name) { // std::cout << "..... delete_atom() deleting atom with index " << iat // << " and name \"" << at_name << "\"" << std::endl; @@ -672,7 +672,7 @@ coot::glyco_tree_t::glyco_tree_t(mmdb::Residue *residue_p, mmdb::Manager *mol, std::vector considered; // std::vector linked_residues; - if (is_pyranose(residue_p) || std::string(residue_p->name) == "ASN") + if (is_pyranose(residue_p) || std::string(residue_p->GetResName()) == "ASN") q.push(residue_p); while (q.size()) { @@ -680,7 +680,7 @@ coot::glyco_tree_t::glyco_tree_t(mmdb::Residue *residue_p, mmdb::Manager *mol, q.pop(); std::vector residues = residues_near_residue(test_residue, mol, dist_crit); for (unsigned int ires=0; iresname) == "ASN") { + if (is_pyranose(residues[ires]) || std::string(residues[ires]->GetResName()) == "ASN") { if (std::find(considered.begin(), considered.end(), residues[ires]) == considered.end()) { q.push(residues[ires]); linked_residues.push_back(residues[ires]); @@ -698,7 +698,7 @@ coot::glyco_tree_t::glyco_tree_t(mmdb::Residue *residue_p, mmdb::Manager *mol, std::cout << "INFO:: " << linked_residues.size() << " glycan/ASN residues" << std::endl; for (unsigned int ires=0; iresname); + std::string residue_name(linked_residues[ires]->GetResName()); // std::cout << " " << ires << " " << residue_name << std::endl; if (residue_name == "ASN") { if (false) @@ -1041,7 +1041,7 @@ coot::glyco_tree_t::residues(const coot::residue_spec_t &containing_res_spec) co std::vector v; for (unsigned int ires=0; iresname); + std::string residue_name(this_res->GetResName()); if (false) std::cout << "residues(): considering residue " << coot::residue_spec_t(this_res) << " " << residue_name << std::endl; @@ -1066,7 +1066,7 @@ void coot::glyco_tree_t::internal_distances(double dist_lim, const std::string &file_name) const { for (unsigned int ires=0; iresname); + std::string residue_name(linked_residues[ires]->GetResName()); if (residue_name == "ASN") { tree tr = find_ASN_rooted_tree(linked_residues[ires], linked_residues); if (tr.size() < 2) { @@ -1152,14 +1152,14 @@ coot::glyco_tree_t::output_internal_distances(mmdb::Residue *residue_p, for (int iat=0; iatisTer()) { - std::string ele_i(at_i->element); + std::string ele_i(at_i->GetElementName()); if (include_hydrogen_atoms || (ele_i != " H")) { // PDBv3 FIXME and below clipper::Coord_orth pos_atom_i = co(at_i); // don't do forwards and backwards distances for (int jat=iat; jatelement); + std::string ele_j(at_j->GetElementName()); if (include_hydrogen_atoms || (ele_j != " H")) { if (! at_j->isTer()) { clipper::Coord_orth pos_atom_j = co(at_j); @@ -1182,7 +1182,7 @@ coot::glyco_tree_t::output_internal_distances(mmdb::Residue *residue_p, for (int iat=0; iatisTer()) { - std::string ele_i(at_i->element); + std::string ele_i(at_i->GetElementName()); if (include_hydrogen_atoms || (ele_i != " H")) { // PDBv3 FIXME clipper::Coord_orth pos_atom_i = co(at_i); mmdb::Atom **parent_residue_atoms = 0; @@ -1192,7 +1192,7 @@ coot::glyco_tree_t::output_internal_distances(mmdb::Residue *residue_p, mmdb::Atom *at_j = parent_residue_atoms[jat]; clipper::Coord_orth pos_atom_j = co(at_j); if (! at_j->isTer()) { - std::string ele_j(at_j->element); + std::string ele_j(at_j->GetElementName()); if (include_hydrogen_atoms || (ele_j != " H")) { // PDBv3 FIXME double d = clipper::Coord_orth::length(pos_atom_i, pos_atom_j); if (! at_j->isTer()) { diff --git a/coot-utils/coot-coord-utils-nucleotides.cc b/coot-utils/coot-coord-utils-nucleotides.cc index 55ada4f262..d51d98a946 100644 --- a/coot-utils/coot-coord-utils-nucleotides.cc +++ b/coot-utils/coot-coord-utils-nucleotides.cc @@ -73,11 +73,11 @@ coot::pucker_analysis_info_t::pucker_analysis_info_t(mmdb::Residue *res_p, for (int i=0; iisTer()) { - std::string atm_name(atm->name); - std::string alt_name(atm->altLoc); + std::string atm_name(atm->GetAtomName()); + std::string alt_name(atm->altLoc()); if (altconf == alt_name) { if (atm_name == " P ") { // PDBv3 FIXME - clipper::Coord_orth p(atm->x, atm->y, atm->z); + clipper::Coord_orth p(atm->x(), atm->y(), atm->z()); markup_info.phosphorus_position = p; markup_info.projected_point = lsq_plane.value().projected_point(p); } @@ -87,8 +87,8 @@ coot::pucker_analysis_info_t::pucker_analysis_info_t(mmdb::Residue *res_p, // find the ribose atoms res_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iname); - std::string alt_name(residue_atoms[i]->altLoc); + std::string atm_name(residue_atoms[i]->GetAtomName()); + std::string alt_name(residue_atoms[i]->altLoc()); if (altconf == alt_name) { if (atm_name == " C1*") ribose_atoms[0] = residue_atoms[i]; if (atm_name == " C1'") ribose_atoms[0] = residue_atoms[i]; @@ -107,9 +107,9 @@ coot::pucker_analysis_info_t::pucker_analysis_info_t(mmdb::Residue *res_p, throw std::runtime_error(mess); } else { for (int i_oop_atom=0; i_oop_atom<5; i_oop_atom++) { - clipper::Coord_orth c(ribose_atoms[i_oop_atom]->x, - ribose_atoms[i_oop_atom]->y, - ribose_atoms[i_oop_atom]->z); + clipper::Coord_orth c(ribose_atoms[i_oop_atom]->x(), + ribose_atoms[i_oop_atom]->y(), + ribose_atoms[i_oop_atom]->z()); ribose_atoms_coords.push_back(c); } @@ -123,16 +123,16 @@ coot::pucker_analysis_info_t::pucker_analysis_info_t(mmdb::Residue *res_p, std::vector plane_atom_coords; for (int i=0; i<5; i++) { if (i != i_oop_atom) { - clipper::Coord_orth c(ribose_atoms[i]->x, ribose_atoms[i]->y, ribose_atoms[i]->z); + clipper::Coord_orth c(ribose_atoms[i]->x(), ribose_atoms[i]->y(), ribose_atoms[i]->z()); plane_atom.push_back(ribose_atoms[i]); plane_atom_coords.push_back(c); } } // plane atom is now filled with 4 atoms from which the plane // should be calculated. - clipper::Coord_orth pt(ribose_atoms[i_oop_atom]->x, - ribose_atoms[i_oop_atom]->y, - ribose_atoms[i_oop_atom]->z); + clipper::Coord_orth pt(ribose_atoms[i_oop_atom]->x(), + ribose_atoms[i_oop_atom]->y(), + ribose_atoms[i_oop_atom]->z()); // lsq_plane_deviation returns pair(out-of-plane-dist, rms_deviation_plane); std::pair dev = coot::lsq_plane_deviation(plane_atom_coords, pt); @@ -254,8 +254,8 @@ coot::pucker_analysis_info_t::assign_base_atom_coords(mmdb::Residue *residue_p) // Assign N1_or_9 and C1_prime for (int i=0; iname); - std::string alt_name(residue_atoms[i]->altLoc); + std::string atom_name(residue_atoms[i]->GetAtomName()); + std::string alt_name(residue_atoms[i]->altLoc()); if (alt_name == altconf) { if (atom_name == " N1 ") N1_or_9 = residue_atoms[i]; @@ -294,13 +294,13 @@ coot::pucker_analysis_info_t::assign_base_atom_coords(mmdb::Residue *residue_p) if (base_names.size() > 0) { for (int i=0; iname); - std::string alt_name(residue_atoms[i]->altLoc); + std::string atm_name(residue_atoms[i]->GetAtomName()); + std::string alt_name(residue_atoms[i]->altLoc()); for (unsigned int j=0; jx, - residue_atoms[i]->y, - residue_atoms[i]->z)); + base_atoms_coords.push_back(clipper::Coord_orth(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z())); } } } @@ -377,13 +377,13 @@ coot::pucker_analysis_info_t::phosphate_distance_to_base_plane(mmdb::Residue *fo following_res->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iname); - std::string alt_name(residue_atoms[i]->altLoc); + std::string atm_name(residue_atoms[i]->GetAtomName()); + std::string alt_name(residue_atoms[i]->altLoc()); if (atm_name == " P ") { if (altconf == alt_name) { - clipper::Coord_orth pt(residue_atoms[i]->x, - residue_atoms[i]->y, - residue_atoms[i]->z); + clipper::Coord_orth pt(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); // lsq_plane_deviation returns pair(out-of-plane-dist, rms_deviation_plane); if (base_atoms_coords.size() < 4) { @@ -453,15 +453,15 @@ coot::pucker_analysis_info_t::phosphate_distance(mmdb::Residue *following_res) { bool found = 0; following_res->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iname); - std::string alt_name(residue_atoms[i]->altLoc); + std::string atm_name(residue_atoms[i]->GetAtomName()); + std::string alt_name(residue_atoms[i]->altLoc()); if (atm_name == " P ") { if (altconf == alt_name) { - clipper::Coord_orth P_pt(residue_atoms[i]->x, - residue_atoms[i]->y, - residue_atoms[i]->z); - clipper::Coord_orth N_pt( N1_or_9->x, N1_or_9->y, N1_or_9->z); - clipper::Coord_orth C_pt(C1_prime->x, C1_prime->y, C1_prime->z); + clipper::Coord_orth P_pt(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); + clipper::Coord_orth N_pt( N1_or_9->x(), N1_or_9->y(), N1_or_9->z()); + clipper::Coord_orth C_pt(C1_prime->x(), C1_prime->y(), C1_prime->z()); clipper::Coord_orth CN = N_pt - C_pt; clipper::Coord_orth CP = P_pt - C_pt; diff --git a/coot-utils/coot-coord-utils.cc b/coot-utils/coot-coord-utils.cc index ab3f7131a3..3199a0fd7a 100644 --- a/coot-utils/coot-coord-utils.cc +++ b/coot-utils/coot-coord-utils.cc @@ -86,7 +86,7 @@ coot::util::residue_types_in_molecule(mmdb::Manager *mol) { // mmdb::Atom *atom_p = residue_p->GetAtom(iat); // } - std::string resname = residue_p->name; + std::string resname = residue_p->GetResName(); if (! is_member_p(v, resname)) { v.push_back(resname); @@ -133,11 +133,11 @@ coot::util::pair_residue_atoms(mmdb::Residue *a_residue_p, b_residue_p->GetAtomTable(residue_atoms_2, n_residue_atoms_2); for (int i=0; iname); - std::string alt1(residue_atoms_1[i]->altLoc); + std::string atn1(residue_atoms_1[i]->GetAtomName()); + std::string alt1(residue_atoms_1[i]->altLoc()); for (int j=0; jname); - std::string alt2(residue_atoms_2[j]->altLoc); + std::string atn2(residue_atoms_2[j]->GetAtomName()); + std::string alt2(residue_atoms_2[j]->altLoc()); if (atn1 == atn2) { if (alt1 == alt2) { std::pair p(i,j); @@ -180,9 +180,9 @@ coot::util::translate_close_to_origin(mmdb::Manager *mol) { int n_atoms = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - at->x += co.x(); - at->y += co.y(); - at->z += co.z(); + at->x() += co.x(); + at->y() += co.y(); + at->z() += co.z(); } } } @@ -211,9 +211,9 @@ coot::util::shift(mmdb::Manager *mol, clipper::Coord_orth pt) { int n_atoms = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - at->x += pt.x(); - at->y += pt.y(); - at->z += pt.z(); + at->x() += pt.x(); + at->y() += pt.y(); + at->z() += pt.z(); } } } @@ -374,15 +374,15 @@ coot::residues_near_residue(mmdb::Residue *res_ref, // std::cout << " comparing " << atom_selection[pscontact[i].id2] // << " " << coot::atom_spec_t(atom_selection[pscontact[i].id2]) // << " " << " to " << rs << " " << res_p << std::endl; - if (atom_selection[pscontact[i].id2]->residue != res_ref) { + if (atom_selection[pscontact[i].id2]->GetResidue() != res_ref) { n_cont_diff++; std::vector::iterator result = std::find(close_residues.begin(), close_residues.end(), - atom_selection[pscontact[i].id2]->residue); + atom_selection[pscontact[i].id2]->GetResidue()); if (result == close_residues.end()) { - close_residues.push_back(atom_selection[pscontact[i].id2]->residue); + close_residues.push_back(atom_selection[pscontact[i].id2]->GetResidue()); } } else { n_cont_same++; @@ -498,8 +498,8 @@ coot::residues_near_residues(const std::vector > for (int i=0; iresidue; - mmdb::Residue *data = atom_2->residue; + mmdb::Residue *key = atom_1->GetResidue(); + mmdb::Residue *data = atom_2->GetResidue(); if (data != key) { if (m.find(key) != m.end()) { m[key].insert(data); @@ -583,8 +583,8 @@ coot::residues_near_residues(mmdb::Manager *mol, float dist_crit) { for (int i=0; iresidue; - mmdb::Residue *data = atom_2->residue; + mmdb::Residue *key = atom_1->GetResidue(); + mmdb::Residue *data = atom_2->GetResidue(); if (data != key) { m[key].insert(data); } @@ -634,7 +634,7 @@ coot::residues_near_position(const clipper::Coord_orth &pt, int n_atoms = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - clipper::Coord_orth at_pt(at->x, at->y, at->z); + clipper::Coord_orth at_pt(at->x(), at->y(), at->z()); double d = clipper::Coord_orth::length(pt, at_pt); if (d < radius) { v.push_back(residue_p); @@ -670,15 +670,15 @@ coot::filter_residues_by_solvent_contact(mmdb::Residue *res_ref, residues[i]->GetAtomTable(residue_atoms, n_residue_atoms); bool i_added = 0; for (int jat=0; jatx, - lig_residue_atoms[jat]->y, - lig_residue_atoms[jat]->z); - std::string ligand_atom_ele = lig_residue_atoms[jat]->element; + clipper::Coord_orth lig_pt(lig_residue_atoms[jat]->x(), + lig_residue_atoms[jat]->y(), + lig_residue_atoms[jat]->z()); + std::string ligand_atom_ele = lig_residue_atoms[jat]->GetElementName(); for (int iat=0; iatx, - residue_atoms[iat]->y, - residue_atoms[iat]->z); + clipper::Coord_orth pt(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); if ((lig_pt-pt).lengthsq() < (water_dist_max*water_dist_max)) { if (0) std::cout << "pushing back " << coot::residue_spec_t(residues[i]) @@ -714,13 +714,13 @@ coot::closest_approach(mmdb::Manager *mol, r1->GetAtomTable( residue_atoms_1, n_res_1_atoms); r2->GetAtomTable( residue_atoms_2, n_res_2_atoms); for (int i=0; ix, - residue_atoms_1[i]->y, - residue_atoms_1[i]->z); + clipper::Coord_orth pt1(residue_atoms_1[i]->x(), + residue_atoms_1[i]->y(), + residue_atoms_1[i]->z()); for (int j=0; jx, - residue_atoms_2[j]->y, - residue_atoms_2[j]->z); + clipper::Coord_orth pt2(residue_atoms_2[j]->x(), + residue_atoms_2[j]->y(), + residue_atoms_2[j]->z()); double d_sqrd = (pt2 - pt1).lengthsq(); if (d_sqrd < dist_sqrd_best) { @@ -840,8 +840,8 @@ coot::distance(mmdb::Atom *at_1, mmdb::Atom *at_2) { double d = -1; if (at_1 && at_2) { - clipper::Coord_orth pt_1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth pt_2(at_2->x, at_2->y, at_2->z); + clipper::Coord_orth pt_1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth pt_2(at_2->x(), at_2->y(), at_2->z()); d = clipper::Coord_orth::length(pt_1, pt_2); } @@ -858,9 +858,9 @@ coot::angle(mmdb::Atom *at_1, mmdb::Atom *at_2, mmdb::Atom *at_3) { if (at_1 && at_2 && at_3) { - clipper::Coord_orth pt_1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth pt_2(at_2->x, at_2->y, at_2->z); - clipper::Coord_orth pt_3(at_3->x, at_3->y, at_3->z); + clipper::Coord_orth pt_1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth pt_2(at_2->x(), at_2->y(), at_2->z()); + clipper::Coord_orth pt_3(at_3->x(), at_3->y(), at_3->z()); ang = clipper::Util::rad2d(clipper::Coord_orth::angle(pt_1, pt_2, pt_3)); @@ -980,7 +980,7 @@ coot::util::get_reorientation_matrix(mmdb::Residue *residue_current, bool coot::is_hydrogen_atom(mmdb::Atom *at_p) { - std::string ele = at_p->element; + std::string ele = at_p->GetElementName(); if ((ele == "H") || (ele == " H")) return true; else @@ -1149,7 +1149,7 @@ coot::util::residue_types_in_chain(mmdb::Chain *chain_p) { for (int ires=0; iresGetResidue(ires); if (residue_p) { - std::string n(residue_p->name); + std::string n(residue_p->GetResName()); if (! is_member_p(v, n)) v.push_back(n); } @@ -1163,7 +1163,7 @@ coot::util::residue_types_in_residue_vec(const std::vector &res std::vector v; for (unsigned int ires=0; iresname); + std::string n(residues[ires]->GetResName()); if (! is_member_p(v, n)) v.push_back(n); } @@ -1353,9 +1353,9 @@ coot::util::get_residue_centre(mmdb::Residue *residue_p) { if (n_residue_atoms>0) { status = 1; for (int i=0; ix, - residue_atoms[i]->y, - residue_atoms[i]->z); + clipper::Coord_orth pt(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); centre += pt; } double scale = 1.0/double(n_residue_atoms); @@ -1376,9 +1376,9 @@ coot::util::get_CA_position_in_residue(mmdb::Residue *residue_p) { for (int i=0; iGetAtomName()); if (atom_name == " CA ") { // PDBv3 FIXME - clipper::Coord_orth pt(residue_atoms[i]->x, - residue_atoms[i]->y, - residue_atoms[i]->z); + clipper::Coord_orth pt(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); pos = pt; status = true; break; @@ -1398,9 +1398,9 @@ coot::util::get_CB_position_in_residue(mmdb::Residue *residue_p) { for (int i=0; iGetAtomName()); if (atom_name == " CB ") { // PDBv3 FIXME - clipper::Coord_orth pt(residue_atoms[i]->x, - residue_atoms[i]->y, - residue_atoms[i]->z); + clipper::Coord_orth pt(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); pos = pt; status = true; break; @@ -1569,9 +1569,9 @@ coot::util::get_fragment_from_atom_spec(const coot::atom_spec_t &atom_spec, for (int iat=0; iatGetAtom(iat); - std::string mol_atom_name = at->name; + std::string mol_atom_name = at->GetAtomName(); if (mol_atom_name == atom_spec.atom_name) { - std::string alt_conf = at->altLoc; + std::string alt_conf = at->altLoc(); if (alt_conf == atom_spec.alt_conf) { search_atom = at; } @@ -1798,7 +1798,7 @@ coot::util::min_resno_in_chain(mmdb::Chain *chain_p) { int resno; for (int ires=0; iresGetResidue(ires); - resno = residue_p->seqNum; + resno = residue_p->GetSeqNum(); if (resno < min_resno) { min_resno = resno; found_residues = 1; @@ -1828,7 +1828,7 @@ coot::util::max_resno_in_chain(mmdb::Chain *chain_p) { if (nres > 0) { for (int ires=0; iresGetResidue(ires); - resno = residue_p->seqNum; + resno = residue_p->GetSeqNum(); if (resno > max_resno) { max_resno = resno; found_residues = 1; @@ -1867,7 +1867,7 @@ coot::util::min_max_residues_in_polymer_chain(mmdb::Chain *chain_p) { if (nres > 0) { for (int ires=0; iresGetResidue(ires); - int resno = residue_p->seqNum; + int resno = residue_p->GetSeqNum(); if (resno > max_resno) { if (! residue_has_hetatms(residue_p)) { max_resno = resno; @@ -2142,10 +2142,10 @@ coot::graph_match(mmdb::Residue *res_moving, // ipair, V1->GetName(), V2->GetName()); mmdb::Atom *at1 = cleaned_res_moving->atom[V1->GetUserID()]; mmdb::Atom *at2 = cleaned_res_reference->atom[V2->GetUserID()]; - coords_1_local.push_back(clipper::Coord_orth(at1->x, at1->y, at1->z)); - coords_2_local.push_back(clipper::Coord_orth(at2->x, at2->y, at2->z)); - std::pair atom_info_1(at1->name, at1->altLoc); - std::pair atom_info_2(at2->name, at2->altLoc); + coords_1_local.push_back(clipper::Coord_orth(at1->x(), at1->y(), at1->z())); + coords_2_local.push_back(clipper::Coord_orth(at2->x(), at2->y(), at2->z())); + std::pair atom_info_1(at1->GetAtomName(), at1->altLoc()); + std::pair atom_info_2(at2->GetAtomName(), at2->altLoc()); std::pair, std::pair > atom_pair(atom_info_1, atom_info_2); matching_atoms.push_back(atom_pair); } @@ -2224,7 +2224,7 @@ coot::graph_match_info_t::match_names(mmdb::Residue *res_with_moving_names) { int n_residue_atoms; res_with_moving_names->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); + std::string atom_name(residue_atoms[iat]->GetAtomName()); // add the name if is not already there. if (std::find(residue_atom_names.begin(), residue_atom_names.end(), atom_name) == residue_atom_names.end()) @@ -2287,7 +2287,7 @@ coot::graph_match_info_t::match_names(mmdb::Residue *res_with_moving_names) { // check for a collision. Is the reference name in existing // atom names that are not due to be replaced? - std::string this_atom_name(residue_atoms[iat]->name); + std::string this_atom_name(residue_atoms[iat]->GetAtomName()); bool replace_name = 0; std::string new_atom_name = ""; @@ -2298,7 +2298,7 @@ coot::graph_match_info_t::match_names(mmdb::Residue *res_with_moving_names) { this_atom_name) != orig_moving_atom_names_non_mapped_non_same.end()) { // OK, this atom name is in the list of atoms non-mapped needing a name change - std::string ele = residue_atoms[iat]->element; + std::string ele = residue_atoms[iat]->GetElementName(); new_atom_name = invent_new_name(this_atom_name, ele, residue_atom_names); residue_atom_names.push_back(new_atom_name); replace_name = 1; @@ -2368,7 +2368,7 @@ coot::util::median_temperature_factor(mmdb::PPAtom atom_selection, float median = 0; std::vector b; for (int i=0; itempFactor; + this_b = atom_selection[i]->tempFactor(); if ((apply_low_cutoff && (this_b > low_cutoff)) || !apply_low_cutoff) { if ((apply_high_cutoff && (this_b > high_cutoff)) || @@ -2399,7 +2399,7 @@ coot::util::average_temperature_factor(mmdb::PPAtom atom_selection, int n_sum = 0; for (int i=0; itempFactor; + this_b = atom_selection[i]->tempFactor(); if ((apply_low_cutoff && (this_b > low_cutoff)) || !apply_low_cutoff) { if ((apply_high_cutoff && (this_b > high_cutoff)) || @@ -2430,7 +2430,7 @@ coot::util::standard_deviation_temperature_factor(mmdb::PPAtom atom_selection, int n_sum = 0; for (int i=0; itempFactor; + this_b = atom_selection[i]->tempFactor(); if ((apply_low_cutoff && (this_b > low_cutoff)) || !apply_low_cutoff) { if ((apply_high_cutoff && (this_b > high_cutoff)) || @@ -2469,7 +2469,7 @@ coot::util::delete_alt_confs_except(mmdb::Residue *residue_p, const std::string int n_residue_atoms; residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; ialtLoc); + std::string atom_alt_conf(residue_atoms[i]->altLoc()); if (atom_alt_conf != alt_conf) { atoms_to_be_deleted.push_back(residue_atoms[i]); } @@ -2540,9 +2540,9 @@ coot::util::get_residue_mid_point(mmdb::Manager *mol, const coot::residue_spec_t for (int iat=0; iatisTer()) { - sum_x += at->x; - sum_y += at->y; - sum_z += at->z; + sum_x += at->x(); + sum_y += at->y(); + sum_z += at->z(); n += 1; } } @@ -2997,8 +2997,8 @@ coot::util::get_atom(const atom_spec_t &spec, mmdb::Manager *mol) { res->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname; - std::string at_alt_conf = test_at->altLoc; + std::string at_name = test_at->GetAtomName(); + std::string at_alt_conf = test_at->altLoc(); if (spec.atom_name == at_name) { if (spec.alt_conf == at_alt_conf) { if (! test_at->isTer()) { @@ -3039,7 +3039,7 @@ coot::util::get_atom_using_fuzzy_search(const atom_spec_t &spec, mmdb::Manager * for (int iat=0; iatisTer()) { - std::string atom_name(at->name); + std::string atom_name(at->GetAtomName()); if (atom_name == spec.atom_name) { rat = at; break; @@ -3058,7 +3058,7 @@ coot::util::get_atom_using_fuzzy_search(const atom_spec_t &spec, mmdb::Manager * for (int iat=0; iatisTer()) { - std::string atom_name(at->name); + std::string atom_name(at->GetAtomName()); if (atom_name == t) { rat = at; break; @@ -3091,8 +3091,8 @@ coot::util::get_atom(const atom_spec_t &spec, mmdb::Residue *res) { res->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname; - std::string at_alt_conf = test_at->altLoc; + std::string at_name = test_at->GetAtomName(); + std::string at_alt_conf = test_at->altLoc(); if (spec.atom_name == at_name) { if (spec.alt_conf == at_alt_conf) { if (! test_at->isTer()) { @@ -3112,7 +3112,7 @@ coot::util::get_atom(const atom_spec_t &spec, mmdb::Residue *res) { clipper::Coord_orth coot::util::get_coords(mmdb::Atom *at) { - clipper::Coord_orth pt(at->x, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); return pt; } @@ -3144,8 +3144,8 @@ coot::util::add_atom(mmdb::Residue *res, if (res) { res->GetAtomTable(residue_atoms, nResidueAtoms); for (int i=0; iname); - std::string atom_alt_conf(residue_atoms[i]->altLoc); + std::string atom_name(residue_atoms[i]->GetAtomName()); + std::string atom_alt_conf(residue_atoms[i]->altLoc()); if (atom_alt_conf == alt_conf) { if (atom_name == atom_name_1) { a = residue_atoms[i]; @@ -3160,9 +3160,9 @@ coot::util::add_atom(mmdb::Residue *res, } if (a && b && c) { - clipper::Coord_orth ac(a->x, a->y, a->z); - clipper::Coord_orth bc(b->x, b->y, b->z); - clipper::Coord_orth cc(c->x, c->y, c->z); + clipper::Coord_orth ac(a->x(), a->y(), a->z()); + clipper::Coord_orth bc(b->x(), b->y(), b->z()); + clipper::Coord_orth cc(c->x(), c->y(), c->z()); double ang = clipper::Util::d2rad(angle); double tors = clipper::Util::d2rad(torsion); clipper::Coord_orth pos(ac, bc, cc, length, ang, tors); @@ -3539,7 +3539,7 @@ coot::util::create_mmdbmanager_from_residue_vector(const std::vectorPutUDData(index_from_reference_residue_handle, residue_old_p->index); + residue_new_p->PutUDData(index_from_reference_residue_handle, residue_old_p->GetIndex()); mmdb::Atom **new_residue_atoms = 0; mmdb::Atom **old_residue_atoms = 0; int n_old_residue_atoms; @@ -3563,8 +3563,8 @@ coot::util::create_mmdbmanager_from_residue_vector(const std::vectorGetAtomName(); std::string at_name_new = at_new->GetAtomName(); if (at_name_old == at_name_new) { - std::string alt_conf_old = at_old->altLoc; - std::string alt_conf_new = at_new->altLoc; + std::string alt_conf_old = at_old->altLoc(); + std::string alt_conf_new = at_new->altLoc(); if (alt_conf_new == alt_conf_old) { int idx = -1; if (at_old->GetUDData(udd_atom_index_handle, idx) == mmdb::UDDATA_Ok) { @@ -3592,12 +3592,12 @@ coot::util::create_mmdbmanager_from_residue_vector(const std::vectorGetAtomName(); - std::string alt_conf_new = at_new->altLoc; + std::string alt_conf_new = at_new->altLoc(); for (int jat=0; jatGetAtomName(); if (at_name_old == at_name_new) { - std::string alt_conf_old = at_old->altLoc; + std::string alt_conf_old = at_old->altLoc(); if (alt_conf_new == alt_conf_old) { int idx = -1; if (at_old->GetUDData(udd_atom_index_handle, idx) == mmdb::UDDATA_Ok) { @@ -3724,7 +3724,7 @@ mmdb::Manager *coot::util::create_mmdbmanager_from_points(const std::vectorSetElementName(" C"); mmdb::Residue *residue_p = new mmdb::Residue; residue_p->SetResName("ALA"); - residue_p->seqNum = i; + residue_p->GetSeqNum() = i; residue_p->AddAtom(at); chain_p->AddResidue(residue_p); } @@ -3746,7 +3746,7 @@ coot::util::pdbcleanup_serial_residue_numbers(mmdb::Manager *mol) { int nres = chain_p->GetNumberOfResidues(); for (int ires=0; iresGetResidue(ires); - residue_p->index = ires; + residue_p->GetIndex() = ires; } } } @@ -4517,14 +4517,14 @@ coot::util::transfer_links(mmdb::Manager *mol_orig, mmdb::Manager *mol_new) { mmdb::Link *link = new mmdb::Link; // sym ids default to 1555 1555 strncpy(link->atName1, at_1->GetAtomName(), 20); - strncpy(link->aloc1, at_1->altLoc, 20); + strncpy(link->aloc1, at_1->altLoc(), 20); strcpy(link->resName1, at_1->GetResName()); strcpy(link->chainID1, at_1->GetChainID()); strcpy(link->insCode1, at_1->GetInsCode()); link->seqNum1 = at_1->GetSeqNum(); strncpy(link->atName2, at_2->GetAtomName(), 20); - strncpy(link->aloc2, at_2->altLoc, 20); + strncpy(link->aloc2, at_2->altLoc(), 20); strcpy(link->resName2, at_2->GetResName()); strcpy(link->chainID2, at_2->GetChainID()); strcpy(link->insCode2, at_2->GetInsCode()); @@ -4620,8 +4620,8 @@ coot::util::deep_copy_this_residue_add_chain(mmdb::Residue *residue, chain_p = new mmdb::Chain; chain_p->SetChainID(residue->GetChainID()); } - rres->seqNum = residue->GetSeqNum(); - strcpy(rres->name, residue->name); + rres->GetSeqNum() = residue->GetSeqNum(); + rres->SetResName(residue->name); // BL says:: should copy insCode too, maybe more things... strncpy(rres->insCode, residue->GetInsCode(), 3); @@ -4631,7 +4631,7 @@ coot::util::deep_copy_this_residue_add_chain(mmdb::Residue *residue, mmdb::Atom *atom_p; for(int iat=0; iatisTer()) { - std::string this_atom_alt_loc(residue_atoms[iat]->altLoc); + std::string this_atom_alt_loc(residue_atoms[iat]->altLoc()); if (whole_residue_flag || this_atom_alt_loc == altconf || this_atom_alt_loc == "") { atom_p = new mmdb::Atom; @@ -4653,8 +4653,8 @@ coot::util::deep_copy_this_residue(mmdb::Residue *residue) { if (residue) { rres = new mmdb::Residue; - rres->seqNum = residue->GetSeqNum(); - strcpy(rres->name, residue->name); + rres->GetSeqNum() = residue->GetSeqNum(); + rres->SetResName(residue->name); strncpy(rres->insCode, residue->GetInsCode(), 3); mmdb::PPAtom residue_atoms = 0; @@ -4687,8 +4687,8 @@ coot::util::deep_copy_this_residue(mmdb::Residue *residue, if (residue) { rres = new mmdb::Residue; - rres->seqNum = residue->GetSeqNum(); - strcpy(rres->name, residue->name); + rres->GetSeqNum() = residue->GetSeqNum(); + rres->SetResName(residue->name); // BL says:: should copy insCode too, maybe more things... strncpy(rres->insCode, residue->GetInsCode(), 3); @@ -4702,7 +4702,7 @@ coot::util::deep_copy_this_residue(mmdb::Residue *residue, if (! at->isTer()) { if (use_alt_conf.first) { - std::string alt_conf(at->altLoc); + std::string alt_conf(at->altLoc()); if (! alt_conf.empty()) if (alt_conf != use_alt_conf.second) continue; @@ -4747,8 +4747,8 @@ coot::util::deep_copy_this_residue_with_atom_index_and_afix_transfer(mmdb::Manag mmdb::Residue *rres = new mmdb::Residue; mmdb::Chain *chain_p = new mmdb::Chain; chain_p->SetChainID(((mmdb::Residue *)residue)->GetChainID()); - rres->seqNum = ((mmdb::Residue *)residue)->GetSeqNum(); - strcpy(rres->name, residue->name); + rres->GetSeqNum() = ((mmdb::Residue *)residue)->GetSeqNum(); + rres->SetResName(residue->name); // BL says:: should copy insCode too, maybe more things... strncpy(rres->insCode, ((mmdb::Residue *)residue)->GetInsCode(), 3); @@ -4766,7 +4766,7 @@ coot::util::deep_copy_this_residue_with_atom_index_and_afix_transfer(mmdb::Manag } for(int iat=0; iataltLoc); + std::string this_atom_alt_loc(residue_atoms[iat]->altLoc()); if (whole_residue_flag || this_atom_alt_loc == altconf || this_atom_alt_loc == "") { atom_p = new mmdb::Atom; @@ -4802,7 +4802,7 @@ mmdb::Residue *coot::util::copy_and_delete_hydrogens(mmdb::Residue *residue_in) copy->GetAtomTable(residue_atoms, nResidueAtoms); for(int i=0; ielement); + std::string element(residue_atoms[i]->GetElementName()); if (element == " H" || element == " D") { copy->DeleteAtom(i); } @@ -4822,7 +4822,7 @@ coot::util::transform_chain(mmdb::Manager *mol, for (int iat=0; iatresidue->chain == moving_chain) { + if (at->GetResidue()->chain == moving_chain) { at->Transform(my_matt); } } @@ -4839,9 +4839,9 @@ coot::util::transform_chain(mmdb::Chain *chain_p, const clipper::RTop_orth &rtop mmdb::Atom *at = residue_p->GetAtom(iat); clipper::Coord_orth pt(co(at)); clipper::Coord_orth new_pt(rtop * pt); - at->x = new_pt.x(); - at->y = new_pt.y(); - at->z = new_pt.z(); + at->x() = new_pt.x(); + at->y() = new_pt.y(); + at->z() = new_pt.z(); } } } @@ -4857,13 +4857,13 @@ coot::util::transform_atoms(mmdb::Residue *res, const clipper::RTop_orth &rtop) clipper::Coord_orth trans_pos; res->GetAtomTable(residue_atoms, natoms); for (int iatom=0; iatomx, - residue_atoms[iatom]->y, - residue_atoms[iatom]->z); + co = clipper::Coord_orth(residue_atoms[iatom]->x(), + residue_atoms[iatom]->y(), + residue_atoms[iatom]->z()); trans_pos = co.transform(rtop); - residue_atoms[iatom]->x = trans_pos.x(); - residue_atoms[iatom]->y = trans_pos.y(); - residue_atoms[iatom]->z = trans_pos.z(); + residue_atoms[iatom]->x() = trans_pos.x(); + residue_atoms[iatom]->y() = trans_pos.y(); + residue_atoms[iatom]->z() = trans_pos.z(); } } @@ -4889,11 +4889,11 @@ coot::util::transform_mol(mmdb::Manager *mol, const clipper::RTop_orth &rtop) { int n_atoms = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - clipper::Coord_orth co(at->x, at->y, at->z); + clipper::Coord_orth co(at->x(), at->y(), at->z()); clipper::Coord_orth trans_pos = co.transform(rtop); - at->x = trans_pos.x(); - at->y = trans_pos.y(); - at->z = trans_pos.z(); + at->x() = trans_pos.x(); + at->y() = trans_pos.y(); + at->z() = trans_pos.z(); } } } @@ -4911,11 +4911,11 @@ coot::util::transform_selection(mmdb::Manager *mol, int SelHnd, const clipper::R mol->GetSelIndex(SelHnd, atoms, n_selected_atoms); for (int iat=0; iatx, at->y, at->z); + clipper::Coord_orth co(at->x(), at->y(), at->z()); clipper::Coord_orth trans_pos = co.transform(rtop); - at->x = trans_pos.x(); - at->y = trans_pos.y(); - at->z = trans_pos.z(); + at->x() = trans_pos.x(); + at->y() = trans_pos.y(); + at->z() = trans_pos.z(); sum_dist += (trans_pos - co).lengthsq(); } if (0) // for debugging @@ -4988,7 +4988,7 @@ coot::util::intelligent_this_residue_mmdb_atom(mmdb::Residue *res_p) { res_p->GetAtomTable(residue_atoms, nResidueAtoms); for (int i=0; iname); + std::string atom_name(residue_atoms[i]->GetAtomName()); if (atom_name == " CA ") { return residue_atoms[i]; } @@ -5013,7 +5013,7 @@ coot::util::occupancy_sum(mmdb::PAtom *atoms, int n_atoms) { for (int i=0; iisTer()) - os += atoms[i]->occupancy; + os += atoms[i]->occupancy(); } return os; } @@ -5026,7 +5026,7 @@ coot::util::is_nucleotide(mmdb::Residue *residue_p) { short int nuc = 0; if (residue_p) { - std::string type(residue_p->name); // all spaces cut + std::string type(residue_p->GetResName()); // all spaces cut if (type == "A") { nuc = 1; @@ -5125,7 +5125,7 @@ coot::util::nucleotide_is_DNA(mmdb::Residue *r) { int n_residue_atoms; r->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iname; + std::string atom_name = residue_atoms[i]->GetAtomName(); if (atom_name == " O2'") { has_o2_prime = 1; break; @@ -5163,7 +5163,7 @@ coot::util::chain_only_of_type(mmdb::Manager *mol, const std::string &residue_ty bool all_same_type_flag = true; for (int ires=0; iresGetResidue(ires); - std::string resname(residue_p->name); + std::string resname(residue_p->GetResName()); if (! (resname == residue_type)) { all_same_type_flag = false; break; @@ -5262,13 +5262,13 @@ coot::util::extents(mmdb::Manager *mol, float least_y = 99999; float least_z = 99999; for (int i=0; ix > most_x) most_x = atoms[i]->x; - if (atoms[i]->y > most_y) most_y = atoms[i]->y; - if (atoms[i]->z > most_z) most_z = atoms[i]->z; + if (atoms[i]->x() > most_x) most_x = atoms[i]->x(); + if (atoms[i]->y() > most_y) most_y = atoms[i]->y(); + if (atoms[i]->z() > most_z) most_z = atoms[i]->z(); - if (atoms[i]->x < least_x) least_x = atoms[i]->x; - if (atoms[i]->y < least_y) least_y = atoms[i]->y; - if (atoms[i]->z < least_z) least_z = atoms[i]->z; + if (atoms[i]->x() < least_x) least_x = atoms[i]->x(); + if (atoms[i]->y() < least_y) least_y = atoms[i]->y(); + if (atoms[i]->z() < least_z) least_z = atoms[i]->z(); } clipper::Coord_orth p1( most_x, most_y, most_z); @@ -5295,12 +5295,12 @@ coot::util::extents(mmdb::Manager *mol, residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatx < least_x) least_x = at->x; - if (at->y < least_y) least_y = at->y; - if (at->z < least_z) least_z = at->z; - if (at->x > most_x) most_x = at->x; - if (at->y > most_y) most_y = at->y; - if (at->z > most_z) most_z = at->z; + if (at->x() < least_x) least_x = at->x(); + if (at->y() < least_y) least_y = at->y(); + if (at->z() < least_z) least_z = at->z(); + if (at->x() > most_x) most_x = at->x(); + if (at->y() > most_y) most_y = at->y(); + if (at->z() > most_z) most_z = at->z(); } } } @@ -5325,12 +5325,12 @@ coot::util::get_ori_to_this_res(mmdb::Residue *residue_p) { std::map > atoms; // first size up the vectors in the atom map for (int iat=0; iataltLoc; + std::string alt_conf = residue_atoms[iat]->altLoc(); atoms[alt_conf].resize(3,0); } for (int iat=0; iataltLoc; - std::string atom_name = residue_atoms[iat]->name; + std::string alt_conf = residue_atoms[iat]->altLoc(); + std::string atom_name = residue_atoms[iat]->GetAtomName(); int name_index = -1; if (atom_name == " N ") name_index = 0; if (atom_name == " CA ") name_index = 1; @@ -5344,9 +5344,9 @@ coot::util::get_ori_to_this_res(mmdb::Residue *residue_p) { std::map >::const_iterator it; for(it=atoms.begin(); it!=atoms.end(); ++it) { if (it->second[0] && it->second[1] && it->second[2]) { - clipper::Coord_orth n(it->second[0]->x, it->second[0]->y, it->second[0]->z); - clipper::Coord_orth ca(it->second[1]->x, it->second[1]->y, it->second[1]->z); - clipper::Coord_orth c(it->second[2]->x, it->second[2]->y, it->second[2]->z); + clipper::Coord_orth n(it->second[0]->x(), it->second[0]->y(), it->second[0]->z()); + clipper::Coord_orth ca(it->second[1]->x(), it->second[1]->y(), it->second[1]->z()); + clipper::Coord_orth c(it->second[2]->x(), it->second[2]->y(), it->second[2]->z()); clipper::Coord_orth can_unit = clipper::Coord_orth((n - ca).unit()); clipper::Coord_orth cac_unit = clipper::Coord_orth((c - ca).unit()); @@ -5525,8 +5525,8 @@ coot::util::omega_torsion(mmdb::Residue *C_residue, mmdb::Residue *N_residue, co mmdb::Atom *N_residue_N_atom_p = NULL; for (int i=0; iname; - std::string altconf_atom = C_residue_atoms[i]->altLoc; + std::string atom_name = C_residue_atoms[i]->GetAtomName(); + std::string altconf_atom = C_residue_atoms[i]->altLoc(); if (atom_name == " CA ") if (altconf_atom == altconf) C_residue_CA_atom_p = C_residue_atoms[i]; @@ -5536,8 +5536,8 @@ coot::util::omega_torsion(mmdb::Residue *C_residue, mmdb::Residue *N_residue, co } for (int i=0; iname; - std::string altconf_atom = N_residue_atoms[i]->altLoc; + std::string atom_name = N_residue_atoms[i]->GetAtomName(); + std::string altconf_atom = N_residue_atoms[i]->altLoc(); if (atom_name == " CA ") if (altconf_atom == altconf) N_residue_CA_atom_p = N_residue_atoms[i]; @@ -5547,18 +5547,18 @@ coot::util::omega_torsion(mmdb::Residue *C_residue, mmdb::Residue *N_residue, co } if (C_residue_CA_atom_p && C_residue_C_atom_p && N_residue_N_atom_p && N_residue_CA_atom_p) { - clipper::Coord_orth ca1(C_residue_CA_atom_p->x, - C_residue_CA_atom_p->y, - C_residue_CA_atom_p->z); - clipper::Coord_orth c1(C_residue_C_atom_p->x, - C_residue_C_atom_p->y, - C_residue_C_atom_p->z); - clipper::Coord_orth ca2(N_residue_CA_atom_p->x, - N_residue_CA_atom_p->y, - N_residue_CA_atom_p->z); - clipper::Coord_orth n2(N_residue_N_atom_p->x, - N_residue_N_atom_p->y, - N_residue_N_atom_p->z); + clipper::Coord_orth ca1(C_residue_CA_atom_p->x(), + C_residue_CA_atom_p->y(), + C_residue_CA_atom_p->z()); + clipper::Coord_orth c1(C_residue_C_atom_p->x(), + C_residue_C_atom_p->y(), + C_residue_C_atom_p->z()); + clipper::Coord_orth ca2(N_residue_CA_atom_p->x(), + N_residue_CA_atom_p->y(), + N_residue_CA_atom_p->z()); + clipper::Coord_orth n2(N_residue_N_atom_p->x(), + N_residue_N_atom_p->y(), + N_residue_N_atom_p->z()); omega = clipper::Coord_orth::torsion(ca1, c1, n2, ca2); istatus = true; @@ -5943,11 +5943,11 @@ coot::util::nucleotide_to_nucleotide(mmdb::Residue *residue, for (int j=0; jname; + std::string atom_name = mol_base_atoms[i]->GetAtomName(); if (refrce_name_vector[j] == atom_name) { - refrce_atom_positions.push_back(clipper::Coord_orth(mol_base_atoms[i]->x, - mol_base_atoms[i]->y, - mol_base_atoms[i]->z)); + refrce_atom_positions.push_back(clipper::Coord_orth(mol_base_atoms[i]->x(), + mol_base_atoms[i]->y(), + mol_base_atoms[i]->z())); if (0) std::cout << "Found " << atom_name << " in reference " << std::endl; } @@ -5956,11 +5956,11 @@ coot::util::nucleotide_to_nucleotide(mmdb::Residue *residue, for (int j=0; jname; + std::string atom_name = std_base_atoms[i]->GetAtomName(); if (moving_name_vector[j] == atom_name) { - moving_atom_positions.push_back(clipper::Coord_orth(std_base_atoms[i]->x, - std_base_atoms[i]->y, - std_base_atoms[i]->z)); + moving_atom_positions.push_back(clipper::Coord_orth(std_base_atoms[i]->x(), + std_base_atoms[i]->y(), + std_base_atoms[i]->z())); if (0) std::cout << "Found " << atom_name << " in moving (std) base " << std::endl; } @@ -6000,20 +6000,20 @@ coot::util::nucleotide_to_nucleotide(mmdb::Residue *residue, for (unsigned int inuc=0; inucname; + std::string std_base_atom_name = std_base_atoms[istd]->GetAtomName(); if (std_base_atom_name == const_nuc_atoms[inuc]) { for (int imol=0; imolname; + std::string mol_base_atom_name = mol_base_atoms[imol]->GetAtomName(); if (mol_base_atom_name == std_base_atom_name) { - std::string altconf1 = std_base_atoms[istd]->altLoc; - std::string altconf2 = mol_base_atoms[imol]->altLoc; + std::string altconf1 = std_base_atoms[istd]->altLoc(); + std::string altconf2 = mol_base_atoms[imol]->altLoc(); if (altconf1 == altconf2) { - clipper::Coord_orth s(std_base_atoms[istd]->x, - std_base_atoms[istd]->y, - std_base_atoms[istd]->z); - clipper::Coord_orth m(mol_base_atoms[imol]->x, - mol_base_atoms[imol]->y, - mol_base_atoms[imol]->z); + clipper::Coord_orth s(std_base_atoms[istd]->x(), + std_base_atoms[istd]->y(), + std_base_atoms[istd]->z()); + clipper::Coord_orth m(mol_base_atoms[imol]->x(), + mol_base_atoms[imol]->y(), + mol_base_atoms[imol]->z()); // std::cout << "---" << std::endl; // std::cout << std_base_atoms[istd]->GetSeqNum() << " " @@ -6079,7 +6079,7 @@ coot::util::gln_asn_b_factor_outliers(mmdb::Manager *mol) { int n_residue_atoms = 0; for (int iat=0; iatGetAtom(iat); - std::string altloc(at->altLoc); + std::string altloc(at->altLoc()); if (altloc == "") { std::string atom_name(at->GetAtomName()); @@ -6108,8 +6108,8 @@ coot::util::gln_asn_b_factor_outliers(mmdb::Manager *mol) { } } else { // is a normal atom of the residue: - b_sum += at->tempFactor; - b_sum_sq += at->tempFactor * at->tempFactor; + b_sum += at->tempFactor(); + b_sum_sq += at->tempFactor() * at->tempFactor(); n_residue_atoms++; } // find the atom to centre on when the button is @@ -6132,7 +6132,7 @@ coot::util::gln_asn_b_factor_outliers(mmdb::Manager *mol) { float mean = b_sum/float(n_residue_atoms); float var = b_sum_sq/float(n_residue_atoms) - mean*mean; float std_dev = sqrt(var); - float diff = (oatom->tempFactor - natom->tempFactor)/2.0; + float diff = (oatom->tempFactor() - natom->tempFactor())/2.0; // we are only interested in cases that have the // O atom B-factor greater than the N atom // B-factor because only they can be fixed by @@ -6187,7 +6187,7 @@ coot::util::residue_has_hydrogens_p(mmdb::Residue *res) { for (int iat=0; iatisTer()) { - std::string ele(at->element); + std::string ele(at->GetElementName()); if ((ele == " H") || (ele == " D")) { result = 1; break; @@ -6240,11 +6240,11 @@ coot::util::rotate_residue(mmdb::Residue *residue_p, mmdb::Atom *at = residue_atoms[iat]; if (at) { if (! at->isTer()) { - clipper::Coord_orth pt(at->x, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); clipper::Coord_orth pt_new = rotate_around_vector(direction, pt, origin_shift, angle); - at->x = pt_new.x(); - at->y = pt_new.y(); - at->z = pt_new.z(); + at->x() = pt_new.x(); + at->y() = pt_new.y(); + at->z() = pt_new.z(); } } } @@ -6259,11 +6259,11 @@ coot::util::rotate_atom_about(const clipper::Coord_orth &direction, double angle, mmdb::Atom *at) { if (at) { - clipper::Coord_orth pos(at->x, at->y, at->z); + clipper::Coord_orth pos(at->x(), at->y(), at->z()); clipper::Coord_orth new_pos = rotate_around_vector(direction, pos, origin_shift, angle); - at->x = new_pos.x(); - at->y = new_pos.y(); - at->z = new_pos.z(); + at->x() = new_pos.x(); + at->y() = new_pos.y(); + at->z() = new_pos.z(); } } @@ -6287,12 +6287,12 @@ coot::util::standardize_peptide_C_N_distances(const std::vectorx += shift * uv.x(); - c_at->y += shift * uv.y(); - c_at->z += shift * uv.z(); - n_at->x -= shift * uv.x(); - n_at->y -= shift * uv.y(); - n_at->z -= shift * uv.z(); + c_at->x() += shift * uv.x(); + c_at->y() += shift * uv.y(); + c_at->z() += shift * uv.z(); + n_at->x() -= shift * uv.x(); + n_at->y() -= shift * uv.y(); + n_at->z() -= shift * uv.z(); } } } @@ -6335,8 +6335,8 @@ coot::util::peptide_C_N_pairs(mmdb::Chain *chain_p) { if (c_first) { if (n_next) { if (! c_first->isTer() && ! n_next->isTer()) { - std::string alt_conf_1(c_first->altLoc); - std::string alt_conf_2(n_next->altLoc); + std::string alt_conf_1(c_first->altLoc()); + std::string alt_conf_2(n_next->altLoc()); if (alt_conf_1.empty() || alt_conf_2.empty() || alt_conf_1 == alt_conf_2) { clipper::Coord_orth pt_1 = co(c_first); clipper::Coord_orth pt_2 = co(n_next); @@ -6449,10 +6449,10 @@ coot::util::cis_peptides_info_from_coords(mmdb::Manager *mol) { } } if (! is_ter) { - clipper::Coord_orth caf(ca_first->x, ca_first->y, ca_first->z); - clipper::Coord_orth cf( c_first->x, c_first->y, c_first->z); - clipper::Coord_orth can( ca_next->x, ca_next->y, ca_next->z); - clipper::Coord_orth nn( n_next->x, n_next->y, n_next->z); + clipper::Coord_orth caf(ca_first->x(), ca_first->y(), ca_first->z()); + clipper::Coord_orth cf( c_first->x(), c_first->y(), c_first->z()); + clipper::Coord_orth can( ca_next->x(), ca_next->y(), ca_next->z()); + clipper::Coord_orth nn( n_next->x(), n_next->y(), n_next->z()); double tors = clipper::Coord_orth::torsion(caf, cf, nn, can); double torsion = clipper::Util::rad2d(tors); double pos_torsion = (torsion > 0.0) ? torsion : 360.0 + torsion; @@ -6688,7 +6688,7 @@ coot::util::cis_trans_convert(std::pair mol_re int n_residue_atoms; mol_residues.first->GetAtomTable(mol_residue_atoms, n_residue_atoms); for (int i=0; iname; + std::string atom_name = mol_residue_atoms[i]->GetAtomName(); if (atom_name == " CA ") { mol_residue_CA_1 = mol_residue_atoms[i]; } @@ -6702,7 +6702,7 @@ coot::util::cis_trans_convert(std::pair mol_re mol_residue_atoms = NULL; mol_residues.second->GetAtomTable(mol_residue_atoms, n_residue_atoms); for (int i=0; iname; + std::string atom_name = mol_residue_atoms[i]->GetAtomName(); if (atom_name == " CA ") { mol_residue_CA_2 = mol_residue_atoms[i]; } @@ -6731,7 +6731,7 @@ coot::util::cis_trans_convert(std::pair mol_re cis_trans_init_match[0]->GetAtomTable(cis_trans_init_match_residue_atoms, n_residue_atoms); for (int i=0; iname; + std::string atom_name = cis_trans_init_match_residue_atoms[i]->GetAtomName(); if (atom_name == " CA ") { cis_trans_init_match_residue_CA_1 = cis_trans_init_match_residue_atoms[i]; } @@ -6746,7 +6746,7 @@ coot::util::cis_trans_convert(std::pair mol_re cis_trans_init_match[1]->GetAtomTable(cis_trans_init_match_residue_atoms, n_residue_atoms); for (int i=0; iname; + std::string atom_name = cis_trans_init_match_residue_atoms[i]->GetAtomName(); if (atom_name == " CA ") { cis_trans_init_match_residue_CA_2 = cis_trans_init_match_residue_atoms[i]; } @@ -6775,7 +6775,7 @@ coot::util::cis_trans_convert(std::pair mol_re converted_residues[0]->GetAtomTable(converted_residues_residue_atoms, n_residue_atoms_converted); for (int i=0; iname; + std::string atom_name = converted_residues_residue_atoms[i]->GetAtomName(); if (atom_name == " CA ") { converted_residues_residue_CA_1 = converted_residues_residue_atoms[i]; } @@ -6791,7 +6791,7 @@ coot::util::cis_trans_convert(std::pair mol_re converted_residues[1]->GetAtomTable(converted_residues_residue_atoms, n_residue_atoms_converted); for (int i=0; iname; + std::string atom_name = converted_residues_residue_atoms[i]->GetAtomName(); if (atom_name == " CA ") { converted_residues_residue_CA_2 = converted_residues_residue_atoms[i]; } @@ -6810,61 +6810,61 @@ coot::util::cis_trans_convert(std::pair mol_re std::vector cis_trans_init; std::vector converted; - current.push_back(clipper::Coord_orth(mol_residue_CA_1->x, - mol_residue_CA_1->y, - mol_residue_CA_1->z)); - current.push_back(clipper::Coord_orth(mol_residue_C_1->x, - mol_residue_C_1->y, - mol_residue_C_1->z)); - current.push_back(clipper::Coord_orth(mol_residue_O_1->x, - mol_residue_O_1->y, - mol_residue_O_1->z)); - current.push_back(clipper::Coord_orth(mol_residue_CA_2->x, - mol_residue_CA_2->y, - mol_residue_CA_2->z)); - current.push_back(clipper::Coord_orth(mol_residue_N_2->x, - mol_residue_N_2->y, - mol_residue_N_2->z)); - - cis_trans_init.push_back(clipper::Coord_orth(cis_trans_init_match_residue_CA_1->x, - cis_trans_init_match_residue_CA_1->y, - cis_trans_init_match_residue_CA_1->z)); - - cis_trans_init.push_back(clipper::Coord_orth(cis_trans_init_match_residue_C_1->x, - cis_trans_init_match_residue_C_1->y, - cis_trans_init_match_residue_C_1->z)); - - cis_trans_init.push_back(clipper::Coord_orth(cis_trans_init_match_residue_O_1->x, - cis_trans_init_match_residue_O_1->y, - cis_trans_init_match_residue_O_1->z)); - - cis_trans_init.push_back(clipper::Coord_orth(cis_trans_init_match_residue_CA_2->x, - cis_trans_init_match_residue_CA_2->y, - cis_trans_init_match_residue_CA_2->z)); - - cis_trans_init.push_back(clipper::Coord_orth(cis_trans_init_match_residue_N_2->x, - cis_trans_init_match_residue_N_2->y, - cis_trans_init_match_residue_N_2->z)); - - converted.push_back(clipper::Coord_orth(converted_residues_residue_CA_1->x, - converted_residues_residue_CA_1->y, - converted_residues_residue_CA_1->z)); - - converted.push_back(clipper::Coord_orth(converted_residues_residue_C_1->x, - converted_residues_residue_C_1->y, - converted_residues_residue_C_1->z)); - - converted.push_back(clipper::Coord_orth(converted_residues_residue_O_1->x, - converted_residues_residue_O_1->y, - converted_residues_residue_O_1->z)); - - converted.push_back(clipper::Coord_orth(converted_residues_residue_CA_2->x, - converted_residues_residue_CA_2->y, - converted_residues_residue_CA_2->z)); - - converted.push_back(clipper::Coord_orth(converted_residues_residue_N_2->x, - converted_residues_residue_N_2->y, - converted_residues_residue_N_2->z)); + current.push_back(clipper::Coord_orth(mol_residue_CA_1->x(), + mol_residue_CA_1->y(), + mol_residue_CA_1->z())); + current.push_back(clipper::Coord_orth(mol_residue_C_1->x(), + mol_residue_C_1->y(), + mol_residue_C_1->z())); + current.push_back(clipper::Coord_orth(mol_residue_O_1->x(), + mol_residue_O_1->y(), + mol_residue_O_1->z())); + current.push_back(clipper::Coord_orth(mol_residue_CA_2->x(), + mol_residue_CA_2->y(), + mol_residue_CA_2->z())); + current.push_back(clipper::Coord_orth(mol_residue_N_2->x(), + mol_residue_N_2->y(), + mol_residue_N_2->z())); + + cis_trans_init.push_back(clipper::Coord_orth(cis_trans_init_match_residue_CA_1->x(), + cis_trans_init_match_residue_CA_1->y(), + cis_trans_init_match_residue_CA_1->z())); + + cis_trans_init.push_back(clipper::Coord_orth(cis_trans_init_match_residue_C_1->x(), + cis_trans_init_match_residue_C_1->y(), + cis_trans_init_match_residue_C_1->z())); + + cis_trans_init.push_back(clipper::Coord_orth(cis_trans_init_match_residue_O_1->x(), + cis_trans_init_match_residue_O_1->y(), + cis_trans_init_match_residue_O_1->z())); + + cis_trans_init.push_back(clipper::Coord_orth(cis_trans_init_match_residue_CA_2->x(), + cis_trans_init_match_residue_CA_2->y(), + cis_trans_init_match_residue_CA_2->z())); + + cis_trans_init.push_back(clipper::Coord_orth(cis_trans_init_match_residue_N_2->x(), + cis_trans_init_match_residue_N_2->y(), + cis_trans_init_match_residue_N_2->z())); + + converted.push_back(clipper::Coord_orth(converted_residues_residue_CA_1->x(), + converted_residues_residue_CA_1->y(), + converted_residues_residue_CA_1->z())); + + converted.push_back(clipper::Coord_orth(converted_residues_residue_C_1->x(), + converted_residues_residue_C_1->y(), + converted_residues_residue_C_1->z())); + + converted.push_back(clipper::Coord_orth(converted_residues_residue_O_1->x(), + converted_residues_residue_O_1->y(), + converted_residues_residue_O_1->z())); + + converted.push_back(clipper::Coord_orth(converted_residues_residue_CA_2->x(), + converted_residues_residue_CA_2->y(), + converted_residues_residue_CA_2->z())); + + converted.push_back(clipper::Coord_orth(converted_residues_residue_N_2->x(), + converted_residues_residue_N_2->y(), + converted_residues_residue_N_2->z())); clipper::RTop_orth lsq_mat(cis_trans_init, current); @@ -6875,29 +6875,29 @@ coot::util::cis_trans_convert(std::pair mol_re clipper::Coord_orth newpos; newpos = converted[0].transform(lsq_mat); - mol_residue_CA_1->x = newpos.x(); - mol_residue_CA_1->y = newpos.y(); - mol_residue_CA_1->z = newpos.z(); + mol_residue_CA_1->x() = newpos.x(); + mol_residue_CA_1->y() = newpos.y(); + mol_residue_CA_1->z() = newpos.z(); newpos = converted[1].transform(lsq_mat); - mol_residue_C_1->x = newpos.x(); - mol_residue_C_1->y = newpos.y(); - mol_residue_C_1->z = newpos.z(); + mol_residue_C_1->x() = newpos.x(); + mol_residue_C_1->y() = newpos.y(); + mol_residue_C_1->z() = newpos.z(); newpos = converted[2].transform(lsq_mat); - mol_residue_O_1->x = newpos.x(); - mol_residue_O_1->y = newpos.y(); - mol_residue_O_1->z = newpos.z(); + mol_residue_O_1->x() = newpos.x(); + mol_residue_O_1->y() = newpos.y(); + mol_residue_O_1->z() = newpos.z(); newpos = converted[3].transform(lsq_mat); - mol_residue_CA_2->x = newpos.x(); - mol_residue_CA_2->y = newpos.y(); - mol_residue_CA_2->z = newpos.z(); + mol_residue_CA_2->x() = newpos.x(); + mol_residue_CA_2->y() = newpos.y(); + mol_residue_CA_2->z() = newpos.z(); newpos = converted[4].transform(lsq_mat); - mol_residue_N_2->x = newpos.x(); - mol_residue_N_2->y = newpos.y(); - mol_residue_N_2->z = newpos.z(); + mol_residue_N_2->x() = newpos.x(); + mol_residue_N_2->y() = newpos.y(); + mol_residue_N_2->z() = newpos.z(); if (mol_residue_H_2) { // 20180510 place H on N as a riding atom, not using transformation @@ -6907,9 +6907,9 @@ coot::util::cis_trans_convert(std::pair mol_re double bl = 0.86; double angle = clipper::Util::d2rad(125.0); clipper::Coord_orth H_pos(at_ca_pos, at_c_pos, at_n_pos, bl, angle, M_PI); - mol_residue_H_2->x = H_pos.x(); - mol_residue_H_2->y = H_pos.y(); - mol_residue_H_2->z = H_pos.z(); + mol_residue_H_2->x() = H_pos.x(); + mol_residue_H_2->y() = H_pos.y(); + mol_residue_H_2->z() = H_pos.z(); } istatus = 1; } @@ -7163,14 +7163,14 @@ coot::mol_by_symmetry(mmdb::Manager *mol, int n_atoms = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - clipper::Coord_orth co(at->x, at->y, at->z); + clipper::Coord_orth co(at->x(), at->y(), at->z()); co -= origin_shift_orth; clipper::Coord_orth to = co.transform(rtop); to += origin_shift_orth; // std::cout << " atom from " // << at->x << " " << at->y << " " << at->z << " " // << " to " << to.format() << std::endl; - at->x = to.x(); at->y = to.y(); at->z = to.z(); + at->x() = to.x(); at->y() = to.y(); at->z() = to.z(); } } } @@ -7467,7 +7467,7 @@ coot::util::move_waters_around_protein(mmdb::Manager *mol) { for (int ires=0; iresGetResidue(ires); int n_atoms = residue_p->GetNumberOfAtoms(); - std::string residue_name(residue_p->name); + std::string residue_name(residue_p->GetResName()); if (residue_name == "WAT" || residue_name == "HOH") { @@ -7475,7 +7475,7 @@ coot::util::move_waters_around_protein(mmdb::Manager *mol) { at = residue_p->GetAtom(iat); if (! at->isTer()) { at = residue_p->GetAtom(iat); - clipper::Coord_orth c(at->x, at->y, at->z); + clipper::Coord_orth c(at->x(), at->y(), at->z()); std::pair pair(at, c); water_atoms.push_back(pair); } @@ -7484,9 +7484,9 @@ coot::util::move_waters_around_protein(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - std::string ele(at->element); + std::string ele(at->GetElementName()); if (ele != " C") { - clipper::Coord_orth pt(at->x, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); protein_coords.push_back(pt); } } @@ -7516,9 +7516,9 @@ coot::util::move_waters_around_protein(mmdb::Manager *mol) { for (unsigned int iw=0; iwx = water_atoms_moved[iw].second.x(); - water_atoms_moved[iw].first->y = water_atoms_moved[iw].second.y(); - water_atoms_moved[iw].first->z = water_atoms_moved[iw].second.z(); + water_atoms_moved[iw].first->x() = water_atoms_moved[iw].second.x(); + water_atoms_moved[iw].first->y() = water_atoms_moved[iw].second.y(); + water_atoms_moved[iw].first->z() = water_atoms_moved[iw].second.z(); n_moved++; } } @@ -7577,9 +7577,9 @@ coot::util::move_hetgroups_around_protein(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); if (! at->Het) { - std::string element(at->element); + std::string element(at->GetElementName()); if (element != "C" && element != " C") { - clipper::Coord_orth pt(at->x, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); protein_coords.push_back(pt); } } @@ -7596,7 +7596,7 @@ coot::util::move_hetgroups_around_protein(mmdb::Manager *mol) { mmdb::Atom *at = 0; for (int ires=0; iresGetResidue(ires); - std::string residue_name(residue_p->name); + std::string residue_name(residue_p->GetResName()); if (residue_name == "WAT" || residue_name == "HOH") { // Waters are handled above. @@ -7612,9 +7612,9 @@ coot::util::move_hetgroups_around_protein(mmdb::Manager *mol) { int n_residue_atoms; residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatx, - residue_atoms[iat]->y, - residue_atoms[iat]->z); + clipper::Coord_orth co(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); std::pair p(residue_atoms[iat], co); hetgroup_atoms.push_back(p); } @@ -7624,9 +7624,9 @@ coot::util::move_hetgroups_around_protein(mmdb::Manager *mol) { for (unsigned int iw=0; iwx = atoms_moved[iw].second.x(); - atoms_moved[iw].first->y = atoms_moved[iw].second.y(); - atoms_moved[iw].first->z = atoms_moved[iw].second.z(); + atoms_moved[iw].first->x() = atoms_moved[iw].second.x(); + atoms_moved[iw].first->y() = atoms_moved[iw].second.y(); + atoms_moved[iw].first->z() = atoms_moved[iw].second.z(); } } } @@ -7827,11 +7827,11 @@ coot::util::residue_orientation(mmdb::Residue *residue_p, const clipper::Mat33GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; ix, - residue_atoms[i]->y, - residue_atoms[i]->z)); + pts.push_back(clipper::Coord_orth(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z())); } else { - std::string atom_name(residue_atoms[i]->name); + std::string atom_name(residue_atoms[i]->GetAtomName()); if (atom_name == " CA ") ca = residue_atoms[i]; if (atom_name == " N ") @@ -7842,13 +7842,13 @@ coot::util::residue_orientation(mmdb::Residue *residue_p, const clipper::Mat33 0) { if (ca) { - clipper::Coord_orth ca_pos(ca->x, ca->y, ca->z); + clipper::Coord_orth ca_pos(ca->x(), ca->y(), ca->z()); clipper::Coord_orth average_pos = coot::util::average_position(pts); clipper::Coord_orth u((average_pos-ca_pos).unit()); // reset n_vect to something sensible, if we have the CA and N. if (ca && n) { - clipper::Coord_orth n_pos( n->x, n->y, n->z); + clipper::Coord_orth n_pos( n->x(), n->y(), n->z()); n_vec = n_pos - ca_pos; } @@ -7968,9 +7968,9 @@ coot::util::median_position(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - pts_x.push_back(at->x); - pts_y.push_back(at->y); - pts_z.push_back(at->z); + pts_x.push_back(at->x()); + pts_y.push_back(at->y()); + pts_z.push_back(at->z()); } } } @@ -8108,9 +8108,9 @@ coot::centre_of_molecule(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - xs += at->x; - ys += at->y; - zs += at->z; + xs += at->x(); + ys += at->y(); + zs += at->z(); n_atoms++; } } @@ -8170,12 +8170,12 @@ coot::centre_of_molecule_using_masses(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - std::string ele = at->element; + std::string ele = at->GetElementName(); double w = 6.0; std::map::const_iterator it; it = pdb_element_weights.find(ele); if (it != pdb_element_weights.end()) w = it->second; - xs += w * at->x; ys += w * at->y; zs += w * at->z; + xs += w * at->x(); ys += w * at->y(); zs += w * at->z(); sum_weight += w; n_atoms++; } @@ -8239,12 +8239,12 @@ coot::radius_of_gyration(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - std::string ele = at->element; + std::string ele = at->GetElementName(); double w = 14.0; std::map::const_iterator it; it = pdb_element_weights.find(ele); if (it != pdb_element_weights.end()) w = it->second; - clipper::Coord_orth pt(at->x, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); clipper::Coord_orth delta = pt - centre; double dd = delta.lengthsq(); sum_dd += dd * w; @@ -8286,12 +8286,12 @@ coot::hiranuma_inversion(mmdb::Manager *mol) { mmdb::Atom *at = residue_p->GetAtom(iat); if (! at) continue; if (at->isTer()) continue; - double plddt = at->tempFactor; + double plddt = at->tempFactor(); if (plddt < 0.0) plddt = 0.0; if (plddt > 100.0) plddt = 100.0; double rmsd = 1.5 * std::exp(4.0 * (0.7 - plddt / 100.0)); double b = eight_pi_sq_over_3 * rmsd * rmsd; - at->tempFactor = static_cast(b); + at->tempFactor() = static_cast(b); } } } @@ -8313,9 +8313,9 @@ coot::centre_of_residues(const std::vector &residues) { int n_residue_atoms; residues[ires]->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatx; - ys += residue_atoms[iat]->y; - zs += residue_atoms[iat]->z; + xs += residue_atoms[iat]->x(); + ys += residue_atoms[iat]->y(); + zs += residue_atoms[iat]->z(); n_atoms++; } } @@ -8497,7 +8497,7 @@ coot::position_residue_by_internal_coordinates::get_atom(mmdb::Residue *res_1, residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); + std::string atom_name(atom->GetAtomName()); if (atom_name == torsion_atom_name) { at = atom; break; @@ -8515,9 +8515,9 @@ coot::arc_info_type::arc_info_type(mmdb::Atom *at_1, mmdb::Atom *at_2, mmdb::Ato if (! at_2) throw("null at_2"); if (! at_3) throw("null at_3"); - clipper::Coord_orth p1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth p2(at_2->x, at_2->y, at_2->z); - clipper::Coord_orth p3(at_3->x, at_3->y, at_3->z); + clipper::Coord_orth p1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth p2(at_2->x(), at_2->y(), at_2->z()); + clipper::Coord_orth p3(at_3->x(), at_3->y(), at_3->z()); clipper::Coord_orth v1(clipper::Coord_orth(p3 - p2).unit()); clipper::Coord_orth v2(clipper::Coord_orth(p1 - p2).unit()); // vectors away from central atom @@ -8539,14 +8539,14 @@ coot::arc_info_type::arc_info_type(mmdb::Atom *at_1, mmdb::Atom *at_2, mmdb::Ato clipper::Coord_orth coot::co(mmdb::Atom *at) { - return clipper::Coord_orth(at->x, at->y, at->z); + return clipper::Coord_orth(at->x(), at->y(), at->z()); } void coot::update_position(mmdb::Atom *at, const clipper::Coord_orth &pos) { - at->x = pos.x(); - at->y = pos.y(); - at->z = pos.z(); + at->x() = pos.x(); + at->y() = pos.y(); + at->z() = pos.z(); } @@ -8563,7 +8563,7 @@ coot::chiral_4th_atom(mmdb::Residue *residue_p, mmdb::Atom *at_centre, mmdb::PPAtom residue_atoms = 0; int n_residue_atoms; clipper::Coord_orth p_c = co(at_centre); - std::string alt_conf = at_centre->altLoc; + std::string alt_conf = at_centre->altLoc(); residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iattempFactor / (8 * M_PI * M_PI); + double u = at->tempFactor() / (8 * M_PI * M_PI); double v = 2 * u; v = std::max(v, 0.38); // don't have tiny atoms @@ -8841,8 +8841,8 @@ coot::interface_residues(mmdb::Manager *mol, for (int i=0; iresidue; - mmdb::Residue *r_2 = at_2->residue; + mmdb::Residue *r_1 = at_1->GetResidue(); + mmdb::Residue *r_2 = at_2->GetResidue(); mmdb::Chain *ch_1 = r_1->chain; mmdb::Chain *ch_2 = r_2->chain; if (r_1 != r_2) { @@ -8916,9 +8916,9 @@ coot::util::copy_atoms_from_chain_to_chain(mmdb::Chain *from_chain, mmdb::Chain for (int iat=0; iatGetAtom(iat); mmdb::Atom *at_to = residue_to_p->GetAtom(iat); - at_to->x = at_from->x; - at_to->y = at_from->y; - at_to->z = at_from->z; + at_to->x() = at_from->x(); + at_to->y() = at_from->y(); + at_to->z() = at_from->z(); } } else { std::cout << "ERROR:: mismatching atom count in copy_atoms_from_chain_to_chain() " << std::endl; @@ -8977,10 +8977,10 @@ coot::get_position_hash(mmdb::Manager *mol) { mmdb::Atom *at = residue_p->GetAtom(iat); if (! at->isTer()) { if (atom_count > 0) { - h += at->x - x_prev; + h += at->x() - x_prev; } atom_count++; - x_prev = at->x; + x_prev = at->x(); } } } @@ -9009,7 +9009,7 @@ coot::atoms_with_zero_occupancy(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - if (at->occupancy < 0.01) { + if (at->occupancy() < 0.01) { v.push_back(at); } } @@ -9041,7 +9041,7 @@ coot::residues_with_alt_confs(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - std::string a(at->altLoc); + std::string a(at->altLoc()); if (a.length() > 0) { found = true; break; @@ -9213,7 +9213,7 @@ coot::util::alt_confs_in_molecule(mmdb::Manager *mol) { int n_atoms = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - std::string alt_conf(at->altLoc); + std::string alt_conf(at->altLoc()); if (! at->isTer()) { s.insert(alt_conf); } diff --git a/coot-utils/coot-fffear.cc b/coot-utils/coot-fffear.cc index 089be12801..16ed4f04d1 100644 --- a/coot-utils/coot-fffear.cc +++ b/coot-utils/coot-fffear.cc @@ -263,11 +263,11 @@ coot::util::fffear_search::fill_nxmap(mmdb::Manager *mol, int SelectionHandle, clipper::NXmap::Map_reference_coord i0, iu, iv, iw; for ( int i = 0; i < n_atoms; i++ ) if ( atom_selection[i] ) { - clipper::Coord_orth p(atom_selection[i]->x, atom_selection[i]->y, atom_selection[i]->z); + clipper::Coord_orth p(atom_selection[i]->x(), atom_selection[i]->y(), atom_selection[i]->z()); p -= mid_point; - clipper::AtomShapeFn sf( p, std::string(atom_selection[i]->element), - atom_selection[i]->tempFactor, - atom_selection[i]->occupancy); + clipper::AtomShapeFn sf( p, std::string(atom_selection[i]->GetElementName()), + atom_selection[i]->tempFactor(), + atom_selection[i]->occupancy()); g0 = nxmap.coord_map(p).coord_grid() + gd.min(); g1 = nxmap.coord_map(p).coord_grid() + gd.max(); i0 = clipper::NXmap::Map_reference_coord( nxmap, g0 ); @@ -337,7 +337,7 @@ coot::util::fffear_search::fill_nxmap_mask(mmdb::Manager *mol, int SelectionHand clipper::NXmap::Map_reference_coord i0, iu, iv, iw; for ( int i = 0; i < n_atoms; i++ ) if ( atom_selection[i] ) { - clipper::Coord_orth xyz(atom_selection[i]->x, atom_selection[i]->y, atom_selection[i]->z); + clipper::Coord_orth xyz(atom_selection[i]->x(), atom_selection[i]->y(), atom_selection[i]->z()); xyz -= mid_point; g0 = nxmap.coord_map( xyz ).coord_grid() + gd.min(); g1 = nxmap.coord_map( xyz ).coord_grid() + gd.max(); diff --git a/coot-utils/coot-h-bonds.cc b/coot-utils/coot-h-bonds.cc index 006101c1cd..35e69c5fea 100644 --- a/coot-utils/coot-h-bonds.cc +++ b/coot-utils/coot-h-bonds.cc @@ -382,13 +382,13 @@ coot::h_bonds::get_mcdonald_and_thornton(int selHnd_1, int selHnd_2, mmdb::Manag mmdb::Atom *at_2 = sel_2_atoms[pscontact[i_contact].id2]; // move on if these are interacting atoms - std::string alt_conf_1 = at_1->altLoc; - std::string alt_conf_2 = at_2->altLoc; + std::string alt_conf_1 = at_1->altLoc(); + std::string alt_conf_2 = at_2->altLoc(); if (!alt_conf_1.empty() && ! alt_conf_2.empty()) if (alt_conf_1 != alt_conf_2) continue; - if (at_1->residue != at_2->residue) { + if (at_1->GetResidue() != at_2->GetResidue()) { // are they HB_HYDROGEN and HB_ACCEPTOR? // @@ -729,7 +729,7 @@ coot::h_bonds::mark_donors_and_acceptors(int selHnd_1, int selHnd_2, mmdb::Manag int udd_h_bond_type_handle = mol->RegisterUDInteger(mmdb::UDR_ATOM, "hb_type"); for (int i=0; iname; + std::string name = sel_1_atoms[i]->GetAtomName(); std::string res_name = sel_1_atoms[i]->GetResName(); int h_bond_type = geom.get_h_bond_type(name, res_name, imol); @@ -745,7 +745,7 @@ coot::h_bonds::mark_donors_and_acceptors(int selHnd_1, int selHnd_2, mmdb::Manag if (selHnd_1 != selHnd_2) { for (int i=0; iname; + std::string name = sel_2_atoms[i]->GetAtomName(); std::string res_name = sel_2_atoms[i]->GetResName(); int h_bond_type = geom.get_h_bond_type(name, res_name, imol); sel_2_atoms[i]->PutUDData(udd_h_bond_type_handle, h_bond_type); @@ -795,12 +795,12 @@ coot::h_bonds::make_neighbour_map(int selHnd_1, int selHnd_2, mmdb::Manager *mol if (n_contacts) { if (pscontact) { for (int i_contact=0; i_contactx, - sel_1_atoms[pscontact[i_contact].id1]->y, - sel_1_atoms[pscontact[i_contact].id1]->z); - clipper::Coord_orth pt_2(sel_1_atoms[pscontact[i_contact].id2]->x, - sel_1_atoms[pscontact[i_contact].id2]->y, - sel_1_atoms[pscontact[i_contact].id2]->z); + clipper::Coord_orth pt_1(sel_1_atoms[pscontact[i_contact].id1]->x(), + sel_1_atoms[pscontact[i_contact].id1]->y(), + sel_1_atoms[pscontact[i_contact].id1]->z()); + clipper::Coord_orth pt_2(sel_1_atoms[pscontact[i_contact].id2]->x(), + sel_1_atoms[pscontact[i_contact].id2]->y(), + sel_1_atoms[pscontact[i_contact].id2]->z()); float d = clipper::Coord_orth::length(pt_1, pt_2); coot::residue_spec_t res_1(sel_1_atoms[pscontact[i_contact].id1]->GetResidue()); coot::residue_spec_t res_2(sel_1_atoms[pscontact[i_contact].id2]->GetResidue()); @@ -829,12 +829,12 @@ coot::h_bonds::make_neighbour_map(int selHnd_1, int selHnd_2, mmdb::Manager *mol if (n_contacts) { if (pscontact) { for (int i_contact=0; i_contactx, - sel_2_atoms[pscontact[i_contact].id1]->y, - sel_2_atoms[pscontact[i_contact].id1]->z); - clipper::Coord_orth pt_2(sel_2_atoms[pscontact[i_contact].id2]->x, - sel_2_atoms[pscontact[i_contact].id2]->y, - sel_2_atoms[pscontact[i_contact].id2]->z); + clipper::Coord_orth pt_1(sel_2_atoms[pscontact[i_contact].id1]->x(), + sel_2_atoms[pscontact[i_contact].id1]->y(), + sel_2_atoms[pscontact[i_contact].id1]->z()); + clipper::Coord_orth pt_2(sel_2_atoms[pscontact[i_contact].id2]->x(), + sel_2_atoms[pscontact[i_contact].id2]->y(), + sel_2_atoms[pscontact[i_contact].id2]->z()); coot::residue_spec_t res_1(sel_2_atoms[pscontact[i_contact].id1]->GetResidue()); coot::residue_spec_t res_2(sel_2_atoms[pscontact[i_contact].id2]->GetResidue()); diff --git a/coot-utils/coot-map-heavy.cc b/coot-utils/coot-map-heavy.cc index 218cda4927..ec094e4722 100644 --- a/coot-utils/coot-map-heavy.cc +++ b/coot-utils/coot-map-heavy.cc @@ -62,9 +62,9 @@ coot::util::fit_to_map_by_simplex_rigid(mmdb::PPAtom atom_selection, par.orig_atoms = atom_selection; clipper::Coord_orth co(0.0, 0.0, 0.0); for (int i=0; ix, - atom_selection[i]->y, - atom_selection[i]->z); + co += clipper::Coord_orth(atom_selection[i]->x(), + atom_selection[i]->y(), + atom_selection[i]->z()); co = 1/float(n_selected_atoms) * co; par.atoms_centre = co; par.xmap = ⟼ @@ -167,16 +167,16 @@ coot::util::simplex_apply_shifts_rigid_internal(gsl_vector *s, for (int i=0; ix, - par.orig_atoms[i]->y, - par.orig_atoms[i]->z); + clipper::Coord_orth orig_p(par.orig_atoms[i]->x(), + par.orig_atoms[i]->y(), + par.orig_atoms[i]->z()); clipper::Coord_orth point = orig_p.transform(rtop); point = par.atoms_centre + (orig_p - par.atoms_centre).transform(rtop); - par.orig_atoms[i]->x = point.x(); - par.orig_atoms[i]->y = point.y(); - par.orig_atoms[i]->z = point.z(); + par.orig_atoms[i]->x() = point.x(); + par.orig_atoms[i]->y() = point.y(); + par.orig_atoms[i]->z() = point.z(); } } @@ -220,9 +220,9 @@ coot::util::my_f_simplex_rigid_internal (const gsl_vector *v, for (int i=0; in_atoms; i++) { - clipper::Coord_orth orig_p(p->orig_atoms[i]->x, - p->orig_atoms[i]->y, - p->orig_atoms[i]->z); + clipper::Coord_orth orig_p(p->orig_atoms[i]->x(), + p->orig_atoms[i]->y(), + p->orig_atoms[i]->z()); point = p->atoms_centre + (orig_p - p->atoms_centre).transform(rtop); // we are trying to minimize, don't forget: @@ -278,8 +278,8 @@ coot::util::z_weighted_density_score(const std::vector &atoms, const clipper::Xmap &map) { float sum_d = 0; for (unsigned int iat=0; iatx, atoms[iat]->y, atoms[iat]->z); - float d = z_weighted_density_at_point(co, atoms[iat]->element, atom_number_list, map); + clipper::Coord_orth co(atoms[iat]->x(), atoms[iat]->y(), atoms[iat]->z()); + float d = z_weighted_density_at_point(co, atoms[iat]->GetElementName(), atom_number_list, map); sum_d += d; } return sum_d; @@ -332,7 +332,7 @@ coot::util::z_weighted_density_score_new(const std::vectorx, at->y, at->z); + clipper::Coord_orth co(at->x(), at->y(), at->z()); float d = coot::util::density_at_point(map, co) * atom_atom_number_pairs[iat].second; sum_d += d; } @@ -348,12 +348,12 @@ coot::util::debug_z_weighted_density_score_new(const std::vector(atc); - clipper::Coord_orth co(at->x, at->y, at->z); + clipper::Coord_orth co(at->x(), at->y(), at->z()); float d = coot::util::density_at_point(map, co); float w = atom_atom_number_pairs[iat].second; sum_d += d * w; std::cout << "debug score " << iat << " " << atom_spec_t(at) - << " pos " << at->x << " " << at->y << " " << at->z + << " pos " << at->x() << " " << at->y() << " " << at->z() << " weight: " << w << " density:" << d << " running sum " << sum_d << std::endl; } std::cout << "debug:: debug_z_weighted_density_score_new(): total: " << sum_d << std::endl; @@ -418,14 +418,14 @@ coot::util::jiggle_atoms(const std::vector &atoms, // now apply rtop to atoms (shift the atoms relative to the // centre_pt before doing the wiggle for (unsigned int i=0; ix - centre_pt.x(), - atoms[i]->y - centre_pt.y(), - atoms[i]->z - centre_pt.z()); + clipper::Coord_orth pt_rel(atoms[i]->x() - centre_pt.x(), + atoms[i]->y() - centre_pt.y(), + atoms[i]->z() - centre_pt.z()); clipper::Coord_orth new_pt = pt_rel.transform(rtop); new_pt += centre_pt; - new_atoms[i].x = new_pt.x(); - new_atoms[i].y = new_pt.y(); - new_atoms[i].z = new_pt.z(); + new_atoms[i].x() = new_pt.x(); + new_atoms[i].y() = new_pt.y(); + new_atoms[i].z() = new_pt.z(); } return std::pair > (rtop, new_atoms); } @@ -447,14 +447,14 @@ coot::util::jiggle_atoms(const std::vector &atoms, // centre_pt before doing the wiggle clipper::RTop_orth rtop = make_rtop_orth_for_jiggle_atoms(jiggle_trans_scale_factor, annealing_factor); for (unsigned int i=0; i > (rtop, new_atoms); } @@ -772,12 +772,12 @@ coot::util::make_edcalc_map(const clipper::NXmap& map_ref, // for metric mol->GetSelIndex(atom_selection_handle, sel_atoms, n_sel_atoms); for (int ii=0; iielement); - clipper::Coord_orth pt(at->x, at->y, at->z); + std::string ele(at->GetElementName()); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); clipper::Atom cat; cat.set_element(ele); cat.set_coord_orth(pt); - cat.set_u_iso(at->tempFactor * 0.0125); + cat.set_u_iso(at->tempFactor() * 0.0125); // cat.set_u_iso(0.1); cat.set_occupancy(1.0); l.push_back(cat); diff --git a/coot-utils/coot-map-utils.cc b/coot-utils/coot-map-utils.cc index e6dec99493..40e402f30b 100644 --- a/coot-utils/coot-map-utils.cc +++ b/coot-utils/coot-map-utils.cc @@ -441,10 +441,10 @@ coot::util::map_score(mmdb::PPAtom atom_selection, for (int i=0; iisTer()) { - f1 = density_at_point(xmap, clipper::Coord_orth(atom_selection[i]->x, - atom_selection[i]->y, - atom_selection[i]->z)); - f1 *= atom_selection[i]->occupancy; + f1 = density_at_point(xmap, clipper::Coord_orth(atom_selection[i]->x(), + atom_selection[i]->y(), + atom_selection[i]->z())); + f1 *= atom_selection[i]->occupancy(); f += f1; // std::cout << "debug:: map_score() adding " << atom_spec_t(at) << " f1 " << f1 << std::endl; } @@ -460,7 +460,7 @@ coot::util::map_score(std::vector atoms, for (unsigned int i=0; ioccupancy; + f1 *= atoms[i]->occupancy(); f += f1; } } @@ -473,7 +473,7 @@ float coot::util::map_score_atom(mmdb::Atom *atom, float f = 0; if (atom) { - f = density_at_point(xmap, clipper::Coord_orth(atom->x, atom->y, atom->z)); + f = density_at_point(xmap, clipper::Coord_orth(atom->x(), atom->y(), atom->z())); } return f; } @@ -1069,10 +1069,10 @@ coot::util::spin_search(const clipper::Xmap &xmap, mmdb::Residue *res, co std::cout << " (found " << match_atoms.size() << " atoms.)" << std::endl; } else { - clipper::Coord_orth pa1(match_atoms[0]->x, match_atoms[0]->y, match_atoms[0]->z); - clipper::Coord_orth pa2(match_atoms[1]->x, match_atoms[1]->y, match_atoms[1]->z); - clipper::Coord_orth pa3(match_atoms[2]->x, match_atoms[2]->y, match_atoms[2]->z); - clipper::Coord_orth pa4(match_atoms[3]->x, match_atoms[3]->y, match_atoms[3]->z); + clipper::Coord_orth pa1(match_atoms[0]->x(), match_atoms[0]->y(), match_atoms[0]->z()); + clipper::Coord_orth pa2(match_atoms[1]->x(), match_atoms[1]->y(), match_atoms[1]->z()); + clipper::Coord_orth pa3(match_atoms[2]->x(), match_atoms[2]->y(), match_atoms[2]->z()); + clipper::Coord_orth pa4(match_atoms[3]->x(), match_atoms[3]->y(), match_atoms[3]->z()); float best_d = -99999999.9; clipper::Coord_orth best_pos; @@ -1280,8 +1280,8 @@ coot::util::backrub_residue_triple_t::trim_residue_atoms_generic(mmdb::Residue * int n_residue_atoms; residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iname); - std::string atom_alt_conf(residue_atoms[i]->altLoc); + std::string atom_name(residue_atoms[i]->GetAtomName()); + std::string atom_alt_conf(residue_atoms[i]->altLoc()); bool delete_this_atom_flag = 1; if (use_keep_atom_vector) { @@ -2037,15 +2037,15 @@ coot::util::calc_atom_map(mmdb::Manager *mol, for (int iat=0; iatisTer()) continue; - clipper::Coord_orth pt(at->x, at->y, at->z); - std::string ele(at->element); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); + std::string ele(at->GetElementName()); clipper::Atom cat; cat.set_element(ele); cat.set_coord_orth(pt); - float u_iso = at->tempFactor * rescale_b_u; + float u_iso = at->tempFactor() * rescale_b_u; if (u_iso < 0.1f) u_iso = 0.1f; // B < ~8.0: EDcalc_iso produces NaN from 0/0 cat.set_u_iso(u_iso); - cat.set_occupancy(at->occupancy); + cat.set_occupancy(at->occupancy()); l.push_back(cat); } @@ -2306,7 +2306,7 @@ coot::util::map_to_model_correlation_stats(mmdb::Manager *mol, if (debug) { std::cout << "debug:: selected " << n_atoms << " atoms " << std::endl; for (int iat=0; iatname << " " + std::cout << " " << iat << ": " << atom_selection[iat]->GetAtomName() << " " << atom_spec_t(atom_selection[iat]) << std::endl; } @@ -2401,9 +2401,9 @@ coot::util::map_to_model_correlation_stats(mmdb::Manager *mol, } for (int iat=0; iatx, - atom_selection[iat]->y, - atom_selection[iat]->z); + clipper::Coord_orth co(atom_selection[iat]->x(), + atom_selection[iat]->y(), + atom_selection[iat]->z()); if (atom_mask_mode == ATOM_MASK_ALL_ATOM_B_FACTOR) atom_radius = refmac_atom_radius(atom_selection[iat]); @@ -2809,9 +2809,9 @@ coot::util::map_to_model_correlation_per_residue(mmdb::Manager *mol, for (int iat=0; iatGetResidue()); int spec_idx = spec_to_index[res_spec]; - clipper::Coord_orth co(atom_selection[iat]->x, - atom_selection[iat]->y, - atom_selection[iat]->z); + clipper::Coord_orth co(atom_selection[iat]->x(), + atom_selection[iat]->y(), + atom_selection[iat]->z()); clipper::Coord_frac cf = co.coord_frac(reference_map.cell()); clipper::Coord_frac box0( cf.u() - atom_radius/reference_map.cell().descr().a(), @@ -2981,9 +2981,9 @@ coot::util::map_to_model_correlation_stats_per_residue(mmdb::Manager *mol, for (int iat=0; iatGetResidue()); - clipper::Coord_orth co(atom_selection[iat]->x, - atom_selection[iat]->y, - atom_selection[iat]->z); + clipper::Coord_orth co(atom_selection[iat]->x(), + atom_selection[iat]->y(), + atom_selection[iat]->z()); clipper::Coord_frac cf = co.coord_frac(xmap.cell()); clipper::Coord_frac box0( cf.u() - atom_radius/xmap.cell().descr().a(), @@ -3222,7 +3222,7 @@ coot::util::map_to_model_correlation_stats_per_residue_run(mmdb::Manager *mol, mmdb::Atom *at = residue_atoms[iat]; if (! at->isTer()) { - clipper::Coord_orth co(at->x, at->y, at->z); + clipper::Coord_orth co(at->x(), at->y(), at->z()); clipper::Coord_frac cf = co.coord_frac(contributor_map.cell()); clipper::Coord_frac box0(cf.u() - atom_radius/contributor_map.cell().descr().a(), cf.v() - atom_radius/contributor_map.cell().descr().b(), @@ -3297,9 +3297,9 @@ coot::util::map_to_model_correlation_stats_per_residue_run(mmdb::Manager *mol, mol->GetSelIndex(SelHnd, atom_selection, n_atoms); for (int iat=0; iatresidue; + mmdb::Residue *residue_p = at->GetResidue(); residue_spec_t res_spec(at->GetResidue()); - clipper::Coord_orth co(at->x, at->y, at->z); + clipper::Coord_orth co(at->x(), at->y(), at->z()); clipper::Coord_frac cf = co.coord_frac(contributor_map.cell()); clipper::Coord_frac box0(cf.u() - atom_radius/contributor_map.cell().descr().a(), cf.v() - atom_radius/contributor_map.cell().descr().b(), @@ -3470,7 +3470,7 @@ coot::util::qq_plot_for_map_over_model(mmdb::Manager *mol, for (int iat=0; iattempFactor*1.5/80.0; // should be some function of tempFactor; + float radius = 1.5 + at->tempFactor()*1.5/80.0; // should be some function of tempFactor; float radius_sq = radius * radius; clipper::Coord_frac cf = c_o.coord_frac(xmap.cell()); @@ -5460,10 +5460,10 @@ coot::util::split_residue_using_map(mmdb::Residue *residue_p, mmdb::Atom *at = residue_atoms[iat]; if (! at->isTer()) { // let's handle the perverse case where B alt confs come before the A alt confs - std::string atom_name(at->name); + std::string atom_name(at->GetAtomName()); std::map >::iterator it; it = atom_name_map.find(atom_name); - std::string alt_loc = at->altLoc; + std::string alt_loc = at->altLoc(); if (it == atom_name_map.end()) { if (alt_loc == "A") atom_name_map[atom_name] = std::make_pair(at, nullptr); if (alt_loc == "B") atom_name_map[atom_name] = std::make_pair(nullptr, at); @@ -5515,10 +5515,10 @@ coot::util::split_residue_using_map(mmdb::Residue *residue_p, mmdb::Atom *at = residue_atoms[iat]; mmdb::Atom *at_copy = new mmdb::Atom; at_copy->Copy(at); - strncpy(at->altLoc, "A", 2); - strncpy(at_copy->altLoc, "B", 2); - at->x += h.x(); at->y += h.y(); at->z += h.z(); - at_copy->x -= h.x(); at_copy->y -= h.y(); at_copy->z -= h.z(); + strncpy(at->altLoc(), "A", 2); + strncpy(at_copy->altLoc(), "B", 2); + at->x() += h.x(); at->y() += h.y(); at->z() += h.z(); + at_copy->x() -= h.x(); at_copy->y() -= h.y(); at_copy->z() -= h.z(); atoms_to_be_added.push_back(at_copy); } for(mmdb::Atom *at_copy : atoms_to_be_added) diff --git a/coot-utils/coot-rama.cc b/coot-utils/coot-rama.cc index d888c02070..924e553121 100644 --- a/coot-utils/coot-rama.cc +++ b/coot-utils/coot-rama.cc @@ -80,11 +80,11 @@ coot::util::get_phi_psi(mmdb::Residue *residue_0, mmdb::Residue *residue_1, mmdb residue_0->GetAtomTable(res_selection, nResidueAtoms); if (nResidueAtoms > 0) { for (int j=0; jname; + std::string atom_name = res_selection[j]->GetAtomName(); if (atom_name == " C ") { - c_prev = clipper::Coord_orth(res_selection[j]->x, - res_selection[j]->y, - res_selection[j]->z); + c_prev = clipper::Coord_orth(res_selection[j]->x(), + res_selection[j]->y(), + res_selection[j]->z()); natom++; } } @@ -92,23 +92,23 @@ coot::util::get_phi_psi(mmdb::Residue *residue_0, mmdb::Residue *residue_1, mmdb residue_1->GetAtomTable(res_selection, nResidueAtoms); if (nResidueAtoms > 0) { for (int j=0; jname; + std::string atom_name = res_selection[j]->GetAtomName(); if (atom_name == " C ") { - c_this = clipper::Coord_orth(res_selection[j]->x, - res_selection[j]->y, - res_selection[j]->z); + c_this = clipper::Coord_orth(res_selection[j]->x(), + res_selection[j]->y(), + res_selection[j]->z()); natom++; } if (atom_name == " CA ") { - ca_this = clipper::Coord_orth(res_selection[j]->x, - res_selection[j]->y, - res_selection[j]->z); + ca_this = clipper::Coord_orth(res_selection[j]->x(), + res_selection[j]->y(), + res_selection[j]->z()); natom++; } if (atom_name == " N ") { - n_this = clipper::Coord_orth(res_selection[j]->x, - res_selection[j]->y, - res_selection[j]->z); + n_this = clipper::Coord_orth(res_selection[j]->x(), + res_selection[j]->y(), + res_selection[j]->z()); natom++; } } @@ -119,11 +119,11 @@ coot::util::get_phi_psi(mmdb::Residue *residue_0, mmdb::Residue *residue_1, mmdb is_pre_pro = 1; if (nResidueAtoms > 0) { for (int j=0; jname; + std::string atom_name = res_selection[j]->GetAtomName(); if (atom_name == " N ") { - n_next = clipper::Coord_orth(res_selection[j]->x, - res_selection[j]->y, - res_selection[j]->z); + n_next = clipper::Coord_orth(res_selection[j]->x(), + res_selection[j]->y(), + res_selection[j]->z()); natom++; } } @@ -139,13 +139,13 @@ coot::util::get_phi_psi(mmdb::Residue *residue_0, mmdb::Residue *residue_1, mmdb label += " "; label += segid; label += " "; - label += residue_1->name; + label += residue_1->GetResName(); double phi = clipper::Util::rad2d(ca_this.torsion(c_prev, n_this, ca_this, c_this)); double psi = clipper::Util::rad2d(ca_this.torsion(n_this, ca_this, c_this, n_next)); phi_psi = coot::util::phi_psi_t(phi, psi, - residue_1->name, + residue_1->GetResName(), label.c_str(), ires, inscode, diff --git a/coot-utils/coot-shelx-ins.cc b/coot-utils/coot-shelx-ins.cc index 42715d59bb..9f918c9c19 100644 --- a/coot-utils/coot-shelx-ins.cc +++ b/coot-utils/coot-shelx-ins.cc @@ -667,14 +667,14 @@ coot::ShelxIns::read_file(const std::string &filename) { } else { if (false) // debug std::cout << "Mol Hierarchy atom: " << iat << " " - << " " << at->name << " " + << " " << at->GetAtomName() << " " << at->GetResName() << " " << at->GetSeqNum() << " " - << at->x << " " << at->y << " " << at->z << std::endl; - clipper::Coord_frac pf(at->x, at->y, at->z); + << at->x() << " " << at->y() << " " << at->z() << std::endl; + clipper::Coord_frac pf(at->x(), at->y(), at->z()); clipper::Coord_orth po = pf.coord_orth(cell); - at->x = po.x(); - at->y = po.y(); - at->z = po.z(); + at->x() = po.x(); + at->y() = po.y(); + at->z() = po.z(); } } } @@ -763,9 +763,9 @@ coot::ShelxIns::make_atom(const coot::shelx_card_info_t &card, const std::string } else { at->SetAtomName(make_atom_name(card.words[0].c_str(), element).c_str()); - at->x = atof(card.words[2].c_str()); - at->y = atof(card.words[3].c_str()); - at->z = atof(card.words[4].c_str()); + at->x() = atof(card.words[2].c_str()); + at->y() = atof(card.words[3].c_str()); + at->z() = atof(card.words[4].c_str()); float occupancy = 1.0; float b_synth= 10.0; @@ -778,7 +778,7 @@ coot::ShelxIns::make_atom(const coot::shelx_card_info_t &card, const std::string util::string_to_float(card.words[4].c_str()), occupancy, b_synth); at->SetElementName(element.c_str()); - strncpy(at->altLoc, altconf.c_str(), 2); + strncpy(at->altLoc(), altconf.c_str(), 2); } catch (const std::runtime_error &rte) { // do nothing @@ -798,7 +798,7 @@ coot::ShelxIns::make_atom(const coot::shelx_card_info_t &card, const std::string // isotropic temperature factor mmdb::realtype u_factor_from_card = atof(card.words[6].c_str()); if (u_factor_from_card > 0.0 ) { - at->tempFactor = u_to_b * u_factor_from_card; + at->tempFactor() = u_to_b * u_factor_from_card; at->WhatIsSet = at->WhatIsSet | 4; // is isotropic at->PutUDData(udd_non_riding_atom_flag_handle_in, 1); } else { @@ -812,26 +812,26 @@ coot::ShelxIns::make_atom(const coot::shelx_card_info_t &card, const std::string mmdb::Atom *prev = previous_non_riding_atom(atom_vector, udd_non_riding_atom_flag_handle_in); if (prev) { int status = at->PutUDData(udd_riding_atom_negative_u_value_handle_in, u_factor_from_card); - at->tempFactor = prev->tempFactor * -u_factor_from_card; + at->tempFactor() = prev->tempFactor() * -u_factor_from_card; } else { // Don't know what to do. Does this ever happen? - at->tempFactor = u_factor_from_card; + at->tempFactor() = u_factor_from_card; } // } else { // Don't know what to do. Does this ever happen? - at->tempFactor = u_factor_from_card; + at->tempFactor() = u_factor_from_card; } } } else { if (card.words.size() > 11) { // anisotropic temperature factor - at->u11 = atof(card.words[ 6].c_str()); - at->u22 = atof(card.words[ 7].c_str()); - at->u33 = atof(card.words[ 8].c_str()); - at->u23 = atof(card.words[ 9].c_str()); - at->u13 = atof(card.words[10].c_str()); - at->u12 = atof(card.words[11].c_str()); + at->u11() = atof(card.words[ 6].c_str()); + at->u22() = atof(card.words[ 7].c_str()); + at->u33() = atof(card.words[ 8].c_str()); + at->u23() = atof(card.words[ 9].c_str()); + at->u13() = atof(card.words[10].c_str()); + at->u12() = atof(card.words[11].c_str()); double a = cell_in.a(); double b = cell_in.b(); @@ -840,31 +840,31 @@ coot::ShelxIns::make_atom(const coot::shelx_card_info_t &card, const std::string // Now othogonalize the U values: // clipper::U_aniso_frac ocaf(at->u11, at->u22, at->u33, // at->u12, at->u13, at->u23); - clipper::U_aniso_frac caf(at->u11/(a*a), at->u22/(b*b), at->u33/(c*c), - at->u12/(a*b), at->u13/(a*c), at->u23/(b*c)); + clipper::U_aniso_frac caf(at->u11()/(a*a), at->u22()/(b*b), at->u33()/(c*c), + at->u12()/(a*b), at->u13()/(a*c), at->u23()/(b*c)); clipper::U_aniso_orth cao = caf.u_aniso_orth(cell_in); - at->u11 = cao(0,0); - at->u22 = cao(1,1); - at->u33 = cao(2,2); - at->u12 = cao(0,1); - at->u13 = cao(0,2); - at->u23 = cao(1,2); + at->u11() = cao(0,0); + at->u22() = cao(1,1); + at->u33() = cao(2,2); + at->u12() = cao(0,1); + at->u13() = cao(0,2); + at->u23() = cao(1,2); // std::cout << "DEBUG:: pre-orthog:\n" << ocaf.format() << std::endl; // std::cout << "DEBUG:: post-orthog:\n" << cao.format() << std::endl; at->WhatIsSet |= mmdb::ASET_Anis_tFac; // is anisotropic - float u_synth = (at->u11 + at->u22 + at->u33)/3.0; + float u_synth = (at->u11() + at->u22() + at->u33())/3.0; at->WhatIsSet |= mmdb::ASET_tempFactor; // has synthetic B factor - at->tempFactor = 8.0 * M_PI * M_PI * u_synth; + at->tempFactor() = 8.0 * M_PI * M_PI * u_synth; at->PutUDData(udd_non_riding_atom_flag_handle_in, 1); } } } else { // An atom with minimal description. Let's make up a // temperature factor: - at->tempFactor = 1.0; + at->tempFactor() = 1.0; at->WhatIsSet = at->WhatIsSet | 4; // is isotropic } // std::cout << "on setting WhatIsSet is " @@ -957,7 +957,7 @@ coot::ShelxIns::add_shelx_residue(std::vector &atom_vector, mmdb::Residue *residue = new mmdb::Residue; residue->SetResName(current_res_name.c_str()); - residue->seqNum = current_res_no; + residue->GetSeqNum() = current_res_no; bool srn = util::is_standard_residue_name(current_res_name); for (unsigned int i=0; ielement) << "_" + << util::remove_leading_spaces(hr.range_first->GetElementName()) << "_" << hr.range_first->GetSeqNum() + hr.resno_offset << " > " - << util::remove_leading_spaces(hr.range_last->element) << "_" + << util::remove_leading_spaces(hr.range_last->GetElementName()) << "_" << hr.range_last->GetSeqNum() + hr.resno_offset << "\n"; } } for (unsigned int ir=0; irelement) << "_" + << util::remove_leading_spaces(hr.range_first->GetElementName()) << "_" << hr.range_first->GetSeqNum() + hr.resno_offset << " > " - << util::remove_leading_spaces(hr.range_last->element) << "_" + << util::remove_leading_spaces(hr.range_last->GetElementName()) << "_" << hr.range_last->GetSeqNum() + hr.resno_offset << "\n"; // << " > LAST\n"; } @@ -1508,7 +1508,7 @@ coot::ShelxIns::get_atomic_contents(mmdb::Manager *mol) const { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - std::string ele(at->element); + std::string ele(at->GetElementName()); if (! ele.empty()) // now we added the isTer() test this probably // won't catch anything. m[ele]++; // initial/default value is 0. @@ -1635,15 +1635,15 @@ coot::ShelxIns::write_ins_file_internal(mmdb::Manager *mol, for (int iat=0; iatGetAtom(iat); - float site_occ_factor = at->occupancy; + float site_occ_factor = at->occupancy(); // reset occupancy to shelx standard occ // (FVAR 1 is implied if not set in the .ins file) if (! mol_is_from_shelx_ins) site_occ_factor = 11.000; - clipper::Coord_orth co(at->x, at->y, at->z); + clipper::Coord_orth co(at->x(), at->y(), at->z()); clipper::Coord_frac cf = co.coord_frac(cell); - int sfac_index = get_sfac_index(at->element); + int sfac_index = get_sfac_index(at->GetElementName()); // AFIX comes before PART if (at->GetUDData(udd_afix_handle, ic) == mmdb::UDDATA_Ok) { @@ -1665,19 +1665,19 @@ coot::ShelxIns::write_ins_file_internal(mmdb::Manager *mol, // std::cout << "on writting WhatIsSet is " << at->WhatIsSet // << "\n"; - std::string this_altloc = at->altLoc; + std::string this_altloc = at->altLoc(); if (this_altloc != current_altloc) { - int ipart = altloc_to_part_no(std::string(at->altLoc)); + int ipart = altloc_to_part_no(std::string(at->altLoc())); f << "PART " << ipart << "\n"; } if (at->WhatIsSet & mmdb::ASET_Anis_tFac) { // Anisotropic - clipper::U_aniso_orth cao(at->u11, at->u22, at->u33, - at->u12, at->u13, at->u23); + clipper::U_aniso_orth cao(at->u11(), at->u22(), at->u33(), + at->u12(), at->u13(), at->u23()); clipper::U_aniso_frac caf = cao.u_aniso_frac(cell); - std::string at_name(at->name); + std::string at_name(at->GetAtomName()); f.setf(std::ios::fixed); f.precision(9); f << coot::util::remove_leading_spaces(at_name) @@ -1695,8 +1695,8 @@ coot::ShelxIns::write_ins_file_internal(mmdb::Manager *mol, } else { if (at->WhatIsSet & mmdb::ASET_tempFactor) { // Isotropic B factor - std::string at_name(at->name); - float b_factor = at->tempFactor; + std::string at_name(at->GetAtomName()); + float b_factor = at->tempFactor(); f.setf(std::ios::fixed); f.precision(7); @@ -1799,10 +1799,10 @@ coot::ShelxIns::message_for_atom(const std::string &in_string, mmdb::Atom *at) c s += "\""; s += at->GetAtomName(); s += "\""; - if (std::string(at->altLoc).length()) { + if (std::string(at->altLoc()).length()) { s += " ,"; s += "\""; - s += at->altLoc; + s += at->altLoc(); s += "\""; } return s; @@ -2620,7 +2620,7 @@ coot::unshelx(mmdb::Manager *shelx_mol) { for (int ires=0; iresGetResidue(ires); if (residue_p) - residue_p->index = ires; + residue_p->GetIndex() = ires; } } mol->FinishStructEdit(); @@ -2680,7 +2680,7 @@ coot::reshelx(mmdb::Manager *mol) { for (int ires=0; iresGetResidue(ires); mmdb::Residue *copy_residue_p = coot::util::deep_copy_this_residue(residue_p); - copy_residue_p->seqNum = residue_p->GetSeqNum() + residue_offset; + copy_residue_p->GetSeqNum() = residue_p->GetSeqNum() + residue_offset; shelx_chain_p->AddResidue(copy_residue_p); // apply the shelx afix numbers: diff --git a/coot-utils/coot-tree-extras.cc b/coot-utils/coot-tree-extras.cc index c0916f3866..875c05e87a 100644 --- a/coot-utils/coot-tree-extras.cc +++ b/coot-utils/coot-tree-extras.cc @@ -131,7 +131,7 @@ void coot::atom_tree_t::construct_internal(const coot::dictionary_residue_restra for (int iat=0; iatGetAtom(iat); if (! atom_p->isTer()) { - std::string atom_ele(atom_p->element); + std::string atom_ele(atom_p->GetElementName()); if (atom_ele == " D") { has_deuterium_atoms = true; break; @@ -163,8 +163,8 @@ void coot::atom_tree_t::construct_internal(const coot::dictionary_residue_restra int idx1 = -1; int idx2 = -1; for (int iat=0; iatname; - std::string atom_altl = residue_atoms[iat]->altLoc; + std::string atom_name = residue_atoms[iat]->GetAtomName(); + std::string atom_altl = residue_atoms[iat]->altLoc(); // std::cout << "comparing :" << atom_name << ": with :" << rest.bond_restraint[i].atom_id_1() // << ":" << std::endl; if (atom_name == rest.bond_restraint[i].atom_id_1_4c()) @@ -184,8 +184,8 @@ void coot::atom_tree_t::construct_internal(const coot::dictionary_residue_restra // same again with dictionary atom name changes for (int iat=0; iatname; - std::string atom_altl = residue_atoms[iat]->altLoc; + std::string atom_name = residue_atoms[iat]->GetAtomName(); + std::string atom_altl = residue_atoms[iat]->altLoc(); // std::cout << "comparing :" << atom_name << ": with :" << rest.bond_restraint[i].atom_id_1() // << ":" << std::endl; std::string bond_restraint_atom_name_1 = rest.bond_restraint[i].atom_id_1_4c(); @@ -237,8 +237,8 @@ coot::atom_tree_t::fill_name_map(const std::string &altconf) { // atom-name -> index, now class variable // std::map > name_to_index; for (int iat=0; iatname); - std::string atom_altl = residue_atoms[iat]->altLoc; + std::string atom_name(residue_atoms[iat]->GetAtomName()); + std::string atom_altl = residue_atoms[iat]->altLoc(); if (false) std::cout << "debug:: in fill_name_map(): comparing altconf of this atom :" << atom_altl << ": to (passed arg) :" << altconf << ": or blank" << std::endl; @@ -471,8 +471,8 @@ coot::atom_tree_t::get_atom_index_quad(const coot::dict_torsion_restraint_t &tr, int n_residue_atoms; res->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); - std::string atom_altconf(residue_atoms[iat]->altLoc); + std::string atom_name( residue_atoms[iat]->GetAtomName()); + std::string atom_altconf(residue_atoms[iat]->altLoc()); if (atom_name == tr.atom_id_1_4c()) if (atom_altconf == "" || atom_altconf == altconf) quad.index1 = iat; @@ -957,8 +957,8 @@ coot::atom_tree_t::rotate_about(const std::string &atom1, const std::string &ato residue->GetAtomTable(residue_atoms, n_residue_atoms); mmdb::Atom *at2 = residue_atoms[index2.index()]; mmdb::Atom *at3 = residue_atoms[index3.index()]; - clipper::Coord_orth base_atom_pos(at2->x, at2->y, at2->z); - clipper::Coord_orth third_atom(at3->x, at3->y, at3->z);; + clipper::Coord_orth base_atom_pos(at2->x(), at2->y(), at2->z()); + clipper::Coord_orth third_atom(at3->x(), at3->y(), at3->z());; clipper::Coord_orth direction = third_atom - base_atom_pos; if (xor_reverse) { direction = base_atom_pos - third_atom; @@ -1127,8 +1127,8 @@ coot::atom_tree_t::rotate_about(int index2, int index3, double angle, bool rever } if (at2 && at3) { - clipper::Coord_orth base_atom_pos(at2->x, at2->y, at2->z); - clipper::Coord_orth third_atom(at3->x, at3->y, at3->z);; + clipper::Coord_orth base_atom_pos(at2->x(), at2->y(), at2->z()); + clipper::Coord_orth third_atom(at3->x(), at3->y(), at3->z());; clipper::Coord_orth direction = third_atom - base_atom_pos; if (xor_reverse) { direction = base_atom_pos - third_atom; @@ -1168,18 +1168,18 @@ coot::atom_tree_t::quad_to_torsion(const coot::map_index_t &index2) const { mmdb::PPAtom residue_atoms; int n_residue_atoms; residue->GetAtomTable(residue_atoms, n_residue_atoms); - co[0] = clipper::Coord_orth(residue_atoms[quad.index1]->x, - residue_atoms[quad.index1]->y, - residue_atoms[quad.index1]->z); - co[1] = clipper::Coord_orth(residue_atoms[quad.index2]->x, - residue_atoms[quad.index2]->y, - residue_atoms[quad.index2]->z); - co[2] = clipper::Coord_orth(residue_atoms[quad.index3]->x, - residue_atoms[quad.index3]->y, - residue_atoms[quad.index3]->z); - co[3] = clipper::Coord_orth(residue_atoms[quad.index4]->x, - residue_atoms[quad.index4]->y, - residue_atoms[quad.index4]->z); + co[0] = clipper::Coord_orth(residue_atoms[quad.index1]->x(), + residue_atoms[quad.index1]->y(), + residue_atoms[quad.index1]->z()); + co[1] = clipper::Coord_orth(residue_atoms[quad.index2]->x(), + residue_atoms[quad.index2]->y(), + residue_atoms[quad.index2]->z()); + co[2] = clipper::Coord_orth(residue_atoms[quad.index3]->x(), + residue_atoms[quad.index3]->y(), + residue_atoms[quad.index3]->z()); + co[3] = clipper::Coord_orth(residue_atoms[quad.index4]->x(), + residue_atoms[quad.index4]->y(), + residue_atoms[quad.index4]->z()); double ar = clipper::Coord_orth::torsion(co[0], co[1], co[2], co[3]); double new_torsion = clipper::Util::rad2d(ar); return new_torsion; @@ -1371,15 +1371,15 @@ coot::atom_tree_t::rotate_internal(std::vector moving_atom_in for (unsigned int im=0; imx, at->y, at->z); + clipper::Coord_orth po(at->x(), at->y(), at->z()); clipper::Coord_orth pt = coot::util::rotate_around_vector(dir, po, base_atom_pos, angle); if (debug) - std::cout << " rotate_internal() moving atom number " << im << " " << at->name - << " from\n " << at->x << "," << at->y << "," << at->z << " to " + std::cout << " rotate_internal() moving atom number " << im << " " << at->GetAtomName() + << " from\n " << at->x() << "," << at->y() << "," << at->z() << " to " << pt.format() << std::endl; - at->x = pt.x(); - at->y = pt.y(); - at->z = pt.z(); + at->x() = pt.x(); + at->y() = pt.y(); + at->z() = pt.z(); } } diff --git a/coot-utils/coot_shiftfield.cpp b/coot-utils/coot_shiftfield.cpp index 68f49a988f..2c681f29dc 100644 --- a/coot-utils/coot_shiftfield.cpp +++ b/coot-utils/coot_shiftfield.cpp @@ -70,23 +70,23 @@ test_import_minimol(clipper::MMDBfile* mfile, clipper::MiniMol& minimol, const i if ( !p_atm->Ter ) { // import the atom clipper::MAtom atm( clipper::Atom::null() ); - atm.set_name( p_atm->GetAtomName(), p_atm->altLoc ); - atm.set_element( p_atm->element ); + atm.set_name( p_atm->GetAtomName(), p_atm->altLoc() ); + atm.set_element( p_atm->GetElementName() ); if ( p_atm->WhatIsSet & ::mmdb::ASET_Coordinates ) - atm.set_coord_orth(clipper::Coord_orth( p_atm->x, p_atm->y, p_atm->z ) ); + atm.set_coord_orth(clipper::Coord_orth( p_atm->x(), p_atm->y(), p_atm->z() ) ); if ( p_atm->WhatIsSet & ::mmdb::ASET_Occupancy ) - atm.set_occupancy( p_atm->occupancy ); + atm.set_occupancy( p_atm->occupancy() ); if ( p_atm->WhatIsSet & ::mmdb::ASET_tempFactor ) - atm.set_u_iso( clipper::Util::b2u( p_atm->tempFactor ) ); + atm.set_u_iso( clipper::Util::b2u( p_atm->tempFactor() ) ); if ( p_atm->WhatIsSet & ::mmdb::ASET_Anis_tFac ) atm.set_u_aniso_orth( - clipper::U_aniso_orth( p_atm->u11, p_atm->u22, p_atm->u33, - p_atm->u12, p_atm->u13, p_atm->u23 ) ); + clipper::U_aniso_orth( p_atm->u11(), p_atm->u22(), p_atm->u33(), + p_atm->u12(), p_atm->u13(), p_atm->u23() ) ); p_atm->GetAtomID( txt ); atm.set_property("CID",clipper::Property(clipper::String(txt))); - if ( p_atm->altLoc[0] != '\0' ) + if ( p_atm->altLoc()[0] != '\0' ) atm.set_property("AltConf", - clipper::Property(clipper::String(p_atm->altLoc))); + clipper::Property(clipper::String(p_atm->altLoc()))); mon.insert( atm ); // store the atom } } diff --git a/coot-utils/dict-link-info.cc b/coot-utils/dict-link-info.cc index eec534cd43..8b3f929891 100644 --- a/coot-utils/dict-link-info.cc +++ b/coot-utils/dict-link-info.cc @@ -56,14 +56,14 @@ coot::dict_link_info_t::dict_link_info_t(mmdb::Residue *residue_ref, int n_residue_atoms_1; res_1->GetAtomTable(residue_atoms_1, n_residue_atoms_1); for (int iat1=0; iat1name); + std::string atom_name_1(residue_atoms_1[iat1]->GetAtomName()); if (atom_name_1 == rr.link_bond_restraint[ibond].atom_id_1_4c()) { // OK so the first atom matched mmdb::PPAtom residue_atoms_2 = 0; int n_residue_atoms_2; res_2->GetAtomTable(residue_atoms_2, n_residue_atoms_2); for (int iat2=0; iat2name); + std::string atom_name_2(residue_atoms_2[iat2]->GetAtomName()); if (atom_name_2 == rr.link_bond_restraint[ibond].atom_id_2_4c()) { ifound = 1; spec_ref = coot::atom_spec_t(res_spec_ref.chain_id, diff --git a/coot-utils/edcalc.cc b/coot-utils/edcalc.cc index 7d263d3fbb..4d4b945d22 100644 --- a/coot-utils/edcalc.cc +++ b/coot-utils/edcalc.cc @@ -77,13 +77,13 @@ coot::calc_atom_map_edcalc(mmdb::Manager *mol, if (at->isTer()) continue; atom_edcalc_data_t ad; - ad.pos = clipper::Coord_orth(at->x, at->y, at->z); - ad.occ = at->occupancy; + ad.pos = clipper::Coord_orth(at->x(), at->y(), at->z()); + ad.occ = at->occupancy(); - float u_iso = at->tempFactor * rescale_b_u; + float u_iso = at->tempFactor() * rescale_b_u; if (u_iso < 0.1f) u_iso = 0.1f; // avoid NaN from very low B-factors - std::string ele(at->element); + std::string ele(at->GetElementName()); const clipper::ScatteringFactorsData &sf = clipper::ScatteringFactors::instance()[ele]; for (int i = 0; i < 6; i++) { diff --git a/coot-utils/find-water-baddies.cc b/coot-utils/find-water-baddies.cc index 516b94bb36..7923887240 100644 --- a/coot-utils/find-water-baddies.cc +++ b/coot-utils/find-water-baddies.cc @@ -105,8 +105,8 @@ coot::find_water_baddies_OR(atom_selection_container_t atom_sel, at = residue_p->GetAtom(iat); bool water_atom_is_hydrogen_atom = false; // PDBv3 FIXME - if (! strncmp(at->name, " H", 2)) water_atom_is_hydrogen_atom = true; - if (! strncmp(at->name, " D", 2)) water_atom_is_hydrogen_atom = true; + if (! strncmp(at->GetAtomName(), " H", 2)) water_atom_is_hydrogen_atom = true; + if (! strncmp(at->GetAtomName(), " D", 2)) water_atom_is_hydrogen_atom = true; if (water_atom_is_hydrogen_atom) continue; @@ -119,7 +119,7 @@ coot::find_water_baddies_OR(atom_selection_container_t atom_sel, // density check: if (map_in_sigma > 0.0) { // it *should* be! - clipper::Coord_orth a(at->x, at->y, at->z); + clipper::Coord_orth a(at->x(), at->y(), at->z()); den = coot::util::density_at_point(xmap_in, a); den /= map_in_sigma; @@ -136,7 +136,7 @@ coot::find_water_baddies_OR(atom_selection_container_t atom_sel, // B factor check: if (! this_is_marked) { - if (at->tempFactor > b_factor_lim && use_b_factor_limit_test) { + if (at->tempFactor() > b_factor_lim && use_b_factor_limit_test) { marked_for_display.push_back(std::pair(at, den)); } } @@ -148,23 +148,23 @@ coot::find_water_baddies_OR(atom_selection_container_t atom_sel, // (ignoring things means less marked atoms) if (ignore_part_occ_contact_flag == 0) { - if (ignore_zero_occ_flag == false || at->occupancy > 0.01) { + if (ignore_zero_occ_flag == false || at->occupancy() > 0.01) { double dist_to_atoms_min = 99999; double dc_sqrd = dist_to_atoms_min * dist_to_atoms_min; double d_sqrd_min = 999999999; - clipper::Coord_orth a(at->x, at->y, at->z); + clipper::Coord_orth a(at->x(), at->y(), at->z()); for (int j=0; jelement, " H", 2)) + if (! strncmp(atom_sel.atom_selection[j]->GetElementName(), " H", 2)) is_H = true; if (! is_H) { - clipper::Coord_orth p(atom_sel.atom_selection[j]->x, - atom_sel.atom_selection[j]->y, - atom_sel.atom_selection[j]->z); + clipper::Coord_orth p(atom_sel.atom_selection[j]->x(), + atom_sel.atom_selection[j]->y(), + atom_sel.atom_selection[j]->z()); double d_sqrd = (p-a).lengthsq(); if (d_sqrd < d_sqrd_min) { d_sqrd_min = d_sqrd; @@ -209,14 +209,14 @@ coot::find_water_baddies_OR(atom_selection_container_t atom_sel, for (unsigned int i=0; itempFactor); + s += coot::util::float_to_string(marked_for_display[i].first->tempFactor()); if (map_in_sigma > 0.0) { s += " ED: "; s += coot::util::float_to_string(marked_for_display[i].second); s += " rmsd"; } coot::atom_spec_t as(marked_for_display[i].first, s); - as.float_user_data = marked_for_display[i].first->occupancy; + as.float_user_data = marked_for_display[i].first->occupancy(); v.push_back(as); } return v; diff --git a/coot-utils/gaussian-atom-map-for-mask.cc b/coot-utils/gaussian-atom-map-for-mask.cc index 2b2d5704b9..dfcb54c94b 100644 --- a/coot-utils/gaussian-atom-map-for-mask.cc +++ b/coot-utils/gaussian-atom-map-for-mask.cc @@ -66,7 +66,7 @@ clipper::Xmap coot::util::make_gaussian_atom_map_for_mask(const clipper:: for (int i=0; iisTer()) { - clipper::Coord_orth pos(at->x, at->y, at->z); + clipper::Coord_orth pos(at->x(), at->y(), at->z()); place_atom_in_grid(pos, xmap, sigma, box_radius); // change xmap } } diff --git a/coot-utils/glyco-torsions.cc b/coot-utils/glyco-torsions.cc index b6709db1ba..c95b705244 100644 --- a/coot-utils/glyco-torsions.cc +++ b/coot-utils/glyco-torsions.cc @@ -215,7 +215,7 @@ coot::link_by_torsion_t::make_residue(mmdb::Residue *base_residue_p) const { if (geom_atom_torsions.size()) { r = new mmdb::Residue; r->SetResName(new_residue_type.c_str()); - r->seqNum = new_res_no; + r->GetSeqNum() = new_res_no; for (unsigned int i=0; iname); + std::string nb_name = coot::util::remove_whitespace(at->GetAtomName()); if (names.prior_atom_1.first) if (names.prior_atom_1.second == nb_name) p_1 = at; @@ -275,7 +275,7 @@ coot::atom_by_torsion_t::atom_by_torsion_t(const atom_by_torsion_base_t &names, } for (int iat=0; iatname); + std::string nb_name = coot::util::remove_whitespace(at->GetAtomName()); if (! names.prior_atom_1.first) if (names.prior_atom_1.second == nb_name) p_1 = at; diff --git a/coot-utils/helix-analysis.cc b/coot-utils/helix-analysis.cc index 64a502e43b..cc01a7d044 100644 --- a/coot-utils/helix-analysis.cc +++ b/coot-utils/helix-analysis.cc @@ -120,8 +120,8 @@ void coot::helix_params_t::calc_B() { if (quad.atom_2 && quad.atom_3) { - clipper::Coord_orth pt_2(quad.atom_2->x, quad.atom_2->y, quad.atom_2->z); - clipper::Coord_orth pt_3(quad.atom_3->x, quad.atom_3->y, quad.atom_3->z); + clipper::Coord_orth pt_2(quad.atom_2->x(), quad.atom_2->y(), quad.atom_2->z()); + clipper::Coord_orth pt_3(quad.atom_3->x(), quad.atom_3->y(), quad.atom_3->z()); double d = clipper::Coord_orth::length(pt_2, pt_3); B = clipper::Coord_orth(d, 0, 0); clipper::RTop_orth A_rtop(A, clipper::Coord_orth(0,0,0)); diff --git a/coot-utils/helix-like.cc b/coot-utils/helix-like.cc index f4172f1a4f..8463f5af00 100644 --- a/coot-utils/helix-like.cc +++ b/coot-utils/helix-like.cc @@ -129,14 +129,14 @@ coot::compare_to_helix(const std::vector &helical_residues, for (int iat=0; iatname); + std::string atom_name(at->GetAtomName()); if (atom_name == " N ") idx = 0; if (atom_name == " CA ") idx = 1; if (atom_name == " C ") idx = 2; if (atom_name == " O ") idx = 3; if (idx != -1) { int idx_match_set = i*4 + idx; - clipper::Coord_orth co(at->x, at->y, at->z); + clipper::Coord_orth co(at->x(), at->y(), at->z()); match_set[idx_match_set] = co; n_found++; // also count n_found_this (for this residue) diff --git a/coot-utils/hole.cc b/coot-utils/hole.cc index 0ec70554d9..a7927e504d 100644 --- a/coot-utils/hole.cc +++ b/coot-utils/hole.cc @@ -72,7 +72,7 @@ coot::hole::assign_vdw_radii(const coot::protein_geometry &geom) { for (int iat=0; iatGetAtom(iat); - std::string atom_name = at->name; + std::string atom_name = at->GetAtomName(); // try cache first std::pair p(atom_name, residue_name); @@ -85,7 +85,7 @@ coot::hole::assign_vdw_radii(const coot::protein_geometry &geom) { if (radius > 0) { at->PutUDData(radius_handle, radius); } else { - std::string ele = at->element; + std::string ele = at->GetElementName(); // make a reasonable default mmdb::realtype radius = 1.7; if (ele == " N") @@ -317,9 +317,9 @@ coot::hole::sphere_size(const clipper::Coord_orth &pt, int selhnd) const { mmdb::realtype atom_vdw_radius; for (int iat=0; iatx, - atom_selection[iat]->y, - atom_selection[iat]->z); + clipper::Coord_orth atom_pos(atom_selection[iat]->x(), + atom_selection[iat]->y(), + atom_selection[iat]->z()); double r_1 = clipper::Coord_orth::length(atom_pos, pt); atom_selection[iat]->GetUDData(radius_handle, atom_vdw_radius); double r = r_1 - atom_vdw_radius; diff --git a/coot-utils/jed-flip.cc b/coot-utils/jed-flip.cc index f6c58ff73a..7ddd876e53 100644 --- a/coot-utils/jed-flip.cc +++ b/coot-utils/jed-flip.cc @@ -88,7 +88,7 @@ coot::util::jed_flip(int imol_no, mmdb::Residue *residue_p, mmdb::Atom *atom_p, message = "Selected atom was not in the residue"; } else { // Happy Path - std::string alt_conf(atom_p->altLoc); + std::string alt_conf(atom_p->altLoc()); atom_selection_container_t residue_asc(residue_atoms, n_residue_atoms); contact_info contact = getcontacts(residue_asc, monomer_type, imol_no, geom); std::vector > contact_indices = diff --git a/coot-utils/lsq-improve.cc b/coot-utils/lsq-improve.cc index b085f5c394..7cfb7b59e0 100644 --- a/coot-utils/lsq-improve.cc +++ b/coot-utils/lsq-improve.cc @@ -122,7 +122,7 @@ coot::lsq_improve::CAs_to_model(mmdb::Manager *mol_in, int model_number) { mmdb::Residue *residue_new = new mmdb::Residue(chain_new); chain_new->AddResidue(residue_new); residue_new->SetResName(residue_p->GetResName()); - residue_new->seqNum = residue_p->GetSeqNum(); + residue_new->GetSeqNum() = residue_p->GetSeqNum(); strncpy(residue_new->insCode, residue_p->GetInsCode(), 3); mmdb::Atom *atom_new = new mmdb::Atom(residue_new); residue_new->AddAtom(atom_new); diff --git a/coot-utils/merge-C-and-N-terminii.cc b/coot-utils/merge-C-and-N-terminii.cc index 1a0e538884..e10f992a09 100644 --- a/coot-utils/merge-C-and-N-terminii.cc +++ b/coot-utils/merge-C-and-N-terminii.cc @@ -277,7 +277,7 @@ coot::merge_C_and_N_terminii(mmdb::Manager *mol, mmdb::Residue *residue_p = chain_with_N_p->GetResidue(ires); if (residue_p) { mmdb::Residue *new_residue = util::deep_copy_this_residue(residue_p); - new_residue->seqNum = rn_base + ires + gap_size; + new_residue->GetSeqNum() = rn_base + ires + gap_size; chain_with_CO_p->AddResidue(new_residue); } } @@ -335,11 +335,11 @@ coot::merge_C_and_N_terminii(mmdb::Manager *mol, mmdb::Atom *at_ca = residue_p->GetAtom(" CA "); mmdb::Atom *at_c = residue_p->GetAtom(" C "); if (at_n) - n_pos = clipper::Coord_orth( at_n->x, at_n->y, at_n->z); + n_pos = clipper::Coord_orth( at_n->x(), at_n->y(), at_n->z()); if (at_ca) - ca_pos = clipper::Coord_orth(at_ca->x, at_ca->y, at_ca->z); + ca_pos = clipper::Coord_orth(at_ca->x(), at_ca->y(), at_ca->z()); if (at_c) - n_pos = clipper::Coord_orth( at_c->x, at_c->y, at_c->z); + n_pos = clipper::Coord_orth( at_c->x(), at_c->y(), at_c->z()); if (at_n && at_ca && at_c) { @@ -389,7 +389,7 @@ coot::merge_C_and_N_terminii(mmdb::Manager *mol, // we have a CA at least, and possibly a N and C too. mmdb::Residue *residue_p = new mmdb::Residue; chain_p->AddResidue(residue_p); - residue_p->seqNum = ires+first_res_no; + residue_p->GetSeqNum() = ires+first_res_no; mmdb::Atom *at_p = new mmdb::Atom; residue_p->AddAtom(at_p); residue_p->SetResName("UNK"); // Or ALA. diff --git a/coot-utils/merge-atom-selections.cc b/coot-utils/merge-atom-selections.cc index 1761fb02d0..4d0cd8ef09 100644 --- a/coot-utils/merge-atom-selections.cc +++ b/coot-utils/merge-atom-selections.cc @@ -127,8 +127,8 @@ coot::mergeable_atom_selections(mmdb::Manager *mol, int selection_handle_1, int void coot::match_container_t::add(mmdb::Atom *at_1, mmdb::Atom *at_2) { - mmdb::Residue *res_1 = at_1->residue; - mmdb::Residue *res_2 = at_2->residue; + mmdb::Residue *res_1 = at_1->GetResidue(); + mmdb::Residue *res_2 = at_2->GetResidue(); if (res_1) { if (res_2) { bool added = false; @@ -172,8 +172,8 @@ coot::match_container_t::find_best_match() const { for (unsigned int iat=0; iatx, at_1->y, at_1->z); - clipper::Coord_orth pt_2(at_2->x, at_2->y, at_2->z); + clipper::Coord_orth pt_1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth pt_2(at_2->x(), at_2->y(), at_2->z()); double dd = (pt_1-pt_2).lengthsq(); sum_devi += sqrt(dd); } @@ -452,7 +452,7 @@ coot::renumber_chains_start_at_least_at_1(mmdb::Manager *mol) { if (offset != 0) { for (int ires=0; iresGetResidue(ires); - residue_p->seqNum += offset; + residue_p->GetSeqNum() += offset; } } } @@ -494,13 +494,13 @@ coot::match_container_for_residues_t::delete_upstream(mmdb::Manager *mol, bool f if (atom_pairs[ip].first == at) { found_matchers = true; std::cout << "DEBUG:: -- A -- setting matchers residue from atom " << atom_spec_t(at) << std::endl; - matchers_residue = at->residue; + matchers_residue = at->GetResidue(); break; } } else { if (atom_pairs[ip].second == at) { found_matchers = true; - matchers_residue = at->residue; + matchers_residue = at->GetResidue(); std::cout << "DEBUG:: -- B -- setting matchers residue from atom " << atom_spec_t(at) << std::endl; break; } @@ -509,9 +509,9 @@ coot::match_container_for_residues_t::delete_upstream(mmdb::Manager *mol, bool f if (found_matchers) break; - if (at->residue != matchers_residue) - if (std::find(delete_these_residues.begin(), delete_these_residues.end(), at->residue) == delete_these_residues.end()) - delete_these_residues.push_back(at->residue); + if (at->GetResidue() != matchers_residue) + if (std::find(delete_these_residues.begin(), delete_these_residues.end(), at->GetResidue()) == delete_these_residues.end()) + delete_these_residues.push_back(at->GetResidue()); } if (delete_these_residues.size() > 0) { @@ -558,7 +558,7 @@ coot::match_container_for_residues_t::delete_downstream(mmdb::Manager *mol, bool for (unsigned int ip=0; ip < atom_pairs.size(); ip++) { if (atom_pairs[ip].first == at) { found_matchers = true; - matchers_residue = at->residue; + matchers_residue = at->GetResidue(); break; } } @@ -566,7 +566,7 @@ coot::match_container_for_residues_t::delete_downstream(mmdb::Manager *mol, bool for (unsigned int ip=0; ip residue; + matchers_residue = at->GetResidue(); break; } } @@ -574,9 +574,9 @@ coot::match_container_for_residues_t::delete_downstream(mmdb::Manager *mol, bool // if we are *past* the matching atoms (not in them) if (found_matchers) - if (at->residue != matchers_residue) - if (std::find(delete_these_residues.begin(), delete_these_residues.end(), at->residue) == delete_these_residues.end()) - delete_these_residues.push_back(at->residue); + if (at->GetResidue() != matchers_residue) + if (std::find(delete_these_residues.begin(), delete_these_residues.end(), at->GetResidue()) == delete_these_residues.end()) + delete_these_residues.push_back(at->GetResidue()); } @@ -711,7 +711,7 @@ coot::match_container_for_residues_t::meld(mmdb::Manager *mol, std::pairseqNum += res_no_delta; + residue_p->GetSeqNum() += res_no_delta; } mmdb::Chain *to_chain_p = residue_2->GetChain(); @@ -733,7 +733,7 @@ coot::match_container_for_residues_t::meld(mmdb::Manager *mol, std::pairseqNum += res_no_delta; + r->GetSeqNum() += res_no_delta; } } } @@ -776,7 +776,7 @@ coot::match_container_for_residues_t::meld_residues(std::vector if (! residue_p) continue; if (residue_p != residue_2) { residue_spec_t spec_pre(residue_p); - residue_p->seqNum += res_no_delta; + residue_p->GetSeqNum() += res_no_delta; residue_spec_t spec_post(residue_p); if (false) // debug std::cout << "in meld_residues() res_no_delta " << res_no_delta << " " << " residue " << spec_pre << " becomes " diff --git a/coot-utils/mutate.cc b/coot-utils/mutate.cc index 2609042b65..cfd4c539a7 100644 --- a/coot-utils/mutate.cc +++ b/coot-utils/mutate.cc @@ -60,18 +60,18 @@ coot::util::mutate_internal(mmdb::Residue *residue, std::cout << "mutate_internal() Mutate Atom Tables" << std::endl; std::cout << "mutate_internal() Before " << residue_spec_t(residue) <name << std::endl; + std::cout << residue_atoms[i]->GetAtomName() << std::endl; std::cout << "mutate_internal() To be replaced by: " << residue_spec_t(std_residue) << std::endl; for(int i=0; iname << std::endl; + std::cout << std_residue_atoms[i]->GetAtomName() << std::endl; } // only touch the atoms with given alt conf, ignore the others. std::string to_residue_type = std_residue->GetResName(); for(int i=0; ialtLoc); + std::string atom_alt_conf(residue_atoms[i]->altLoc()); if (atom_alt_conf == alt_conf) { - std::string residue_this_atom (residue_atoms[i]->name); + std::string residue_this_atom (residue_atoms[i]->GetAtomName()); if (coot::is_main_chain_p(residue_atoms[i])) { if (to_residue_type == "MSE") { residue_atoms[i]->Het = 1; @@ -80,12 +80,12 @@ coot::util::mutate_internal(mmdb::Residue *residue, residue_atoms[i]->Het = 0; // from MSE to MET, say } if (to_residue_type == "PRO") { - std::string atom_name(residue_atoms[i]->name); + std::string atom_name(residue_atoms[i]->GetAtomName()); if (atom_name == " H ") // PDBv3 FIXME residue->DeleteAtom(i); } if (to_residue_type == "GLY") { - std::string atom_name(residue_atoms[i]->name); + std::string atom_name(residue_atoms[i]->GetAtomName()); if (atom_name == " HA ") // PDBv3 FIXME residue->DeleteAtom(i); if (atom_name == " CB ") // PDBv3 FIXME @@ -101,11 +101,11 @@ coot::util::mutate_internal(mmdb::Residue *residue, } for(int i=0; iname); + std::string std_residue_this_atom (std_residue_atoms[i]->GetAtomName()); if (! coot::is_main_chain_p(std_residue_atoms[i])) { if (is_from_shelx_ins_flag) - std_residue_atoms[i]->occupancy = 11.0; - std_residue_atoms[i]->tempFactor = b_factor; + std_residue_atoms[i]->occupancy() = 11.0; + std_residue_atoms[i]->tempFactor() = b_factor; mmdb::Atom *copy_at = new mmdb::Atom; copy_at->Copy(std_residue_atoms[i]); // std::cout << "adding atom " << coot::atom_spec_t(copy_at) << std::endl; @@ -114,7 +114,7 @@ coot::util::mutate_internal(mmdb::Residue *residue, strcpy(copy_at->segID, old_seg_id_for_residue_atoms.c_str()); } if (alt_conf != "") - strcpy(copy_at->altLoc, alt_conf.c_str()); + strcpy(copy_at->altLoc(), alt_conf.c_str()); } } @@ -147,14 +147,14 @@ coot::util::mutate(mmdb::Residue *res, mmdb::Residue *std_res_unoriented, const } else { for(int iat=0; iatx, at->y, at->z); + clipper::Coord_orth co(at->x(), at->y(), at->z()); std::map::const_iterator it = rtops.find(alt_conf); if (it != rtops.end()) { clipper::Coord_orth rotted = co.transform(it->second); - at->x = rotted.x(); - at->y = rotted.y(); - at->z = rotted.z(); + at->x() = rotted.x(); + at->y() = rotted.y(); + at->z() = rotted.z(); } } @@ -393,11 +393,11 @@ coot::util::mutate_base(mmdb::Residue *residue, mmdb::Residue *std_base, for (int j=0; jname; + std::string atom_name = mol_base_atoms[i]->GetAtomName(); if (refrce_name_vector[j] == atom_name) { - refrce_atom_positions.push_back(clipper::Coord_orth(mol_base_atoms[i]->x, - mol_base_atoms[i]->y, - mol_base_atoms[i]->z)); + refrce_atom_positions.push_back(clipper::Coord_orth(mol_base_atoms[i]->x(), + mol_base_atoms[i]->y(), + mol_base_atoms[i]->z())); if (debug) std::cout << "Found " << atom_name << " in reference " << std::endl; } @@ -406,11 +406,11 @@ coot::util::mutate_base(mmdb::Residue *residue, mmdb::Residue *std_base, for (int j=0; jname; + std::string atom_name = std_base_atoms[i]->GetAtomName(); if (moving_name_vector[j] == atom_name) { - moving_atom_positions.push_back(clipper::Coord_orth(std_base_atoms[i]->x, - std_base_atoms[i]->y, - std_base_atoms[i]->z)); + moving_atom_positions.push_back(clipper::Coord_orth(std_base_atoms[i]->x(), + std_base_atoms[i]->y(), + std_base_atoms[i]->z())); if (debug) std::cout << "Found " << atom_name << " in moving (std) base " << std::endl; } @@ -505,10 +505,10 @@ coot::util::mutate_base(mmdb::Residue *residue, mmdb::Residue *std_base, for (int i=0; iname) { + if (mol_base_atom_names[iat] == mol_base_atoms[i]->GetAtomName()) { if (debug) - std::cout << ".... Deleting Atom " << mol_base_atoms[i]->name + std::cout << ".... Deleting Atom " << mol_base_atoms[i]->GetAtomName() << " i = " << i << std::endl; residue->DeleteAtom(i); @@ -543,18 +543,18 @@ coot::util::mutate_base(mmdb::Residue *residue, mmdb::Residue *std_base, for (unsigned int iat=0; iatname) { - clipper::Coord_orth p(std_base_atoms[i]->x, - std_base_atoms[i]->y, - std_base_atoms[i]->z); + if (std_base_atom_names[iat] == std_base_atoms[i]->GetAtomName()) { + clipper::Coord_orth p(std_base_atoms[i]->x(), + std_base_atoms[i]->y(), + std_base_atoms[i]->z()); clipper::Coord_orth pt = p.transform(rtop); std::string ele = std_base_atom_names[iat].substr(0,2); at = new mmdb::Atom; if (debug) - std::cout << ".... Adding Atom " << std_base_atoms[i]->name + std::cout << ".... Adding Atom " << std_base_atoms[i]->GetAtomName() << std::endl; at->SetCoordinates(pt.x(), pt.y(), pt.z(), 1.0, b_factor); - std::string new_atom_name = std_base_atoms[i]->name; + std::string new_atom_name = std_base_atoms[i]->GetAtomName(); if (std_base_name == "DT") if (new_atom_name == " C5M") if (! use_old_style_naming) @@ -563,7 +563,7 @@ coot::util::mutate_base(mmdb::Residue *residue, mmdb::Residue *std_base, at->SetElementName(ele.c_str()); std::string new_alt_conf(""); // force it down the atom's throat :) [is there a better way?] - strncpy(at->altLoc, new_alt_conf.c_str(), 2); + strncpy(at->altLoc(), new_alt_conf.c_str(), 2); residue->AddAtom(at); if (use_old_seg_id) strcpy(at->segID, old_seg_id_for_residue_atoms.c_str()); diff --git a/coot-utils/peak-search.cc b/coot-utils/peak-search.cc index 364df2330e..1c036aafd6 100644 --- a/coot-utils/peak-search.cc +++ b/coot-utils/peak-search.cc @@ -710,7 +710,7 @@ coot::peak_search::make_sample_protein_coords(mmdb::Manager *mol, int every_n) c for (int iat=0; iatGetAtom(iat); - r.push_back(clipper::Coord_orth(at->x, at->y, at->z)); + r.push_back(clipper::Coord_orth(at->x(), at->y(), at->z())); atom_count = 0; } atom_count++; diff --git a/coot-utils/pepflip-using-difference-map.cc b/coot-utils/pepflip-using-difference-map.cc index 0601e75baa..53e4450434 100644 --- a/coot-utils/pepflip-using-difference-map.cc +++ b/coot-utils/pepflip-using-difference-map.cc @@ -74,7 +74,7 @@ coot::pepflip_using_difference_map::get_suggested_flips(float n_sigma) const { float d2 = util::density_at_point(diff_map, pt_2); float delta = d2-d1; if (delta > cut) { - residue_spec_t spec(t.CA_this->residue); + residue_spec_t spec(t.CA_this->GetResidue()); rv.push_back(spec); // std::cout << "INFO:: Adding pepflip: " << spec << " z: " << delta/sd << std::endl; } @@ -120,13 +120,13 @@ coot::pepflip_using_difference_map::get_peptide_atom_triplets() const { if (! at->isTer()) { std::string atom_name(at->GetAtomName()); if (atom_name == " O ") { - std::string alt_loc(at->altLoc); + std::string alt_loc(at->altLoc()); if (alt_loc == "") { O_this = at; } } if (atom_name == " CA ") { - std::string alt_loc(at->altLoc); + std::string alt_loc(at->altLoc()); if (alt_loc == "") { CA_this = at; } @@ -141,7 +141,7 @@ coot::pepflip_using_difference_map::get_peptide_atom_triplets() const { if (! at->isTer()) { std::string atom_name(at->GetAtomName()); if (atom_name == " CA ") { - std::string alt_loc(at->altLoc); + std::string alt_loc(at->altLoc()); if (alt_loc == "") { CA_next = at; break; diff --git a/coot-utils/plane-utils.cc b/coot-utils/plane-utils.cc index c21a1734d4..55692b9919 100644 --- a/coot-utils/plane-utils.cc +++ b/coot-utils/plane-utils.cc @@ -49,7 +49,7 @@ coot::angle_betwen_plane_and_vector(mmdb::Residue *residue_p, for (int iat=0; iatGetAtomName()); - std::string alt_conf(at->altLoc); + std::string alt_conf(at->altLoc()); std::vector::const_iterator it = std::find(ring_atom_names.begin(), ring_atom_names.end(), atom_name); if (it != ring_atom_names.end()) { @@ -84,7 +84,7 @@ coot::angle_betwen_plane_and_vector(mmdb::Residue *residue_p, clipper::Coord_orth pt_2 = co(bonding_atom); clipper::Coord_orth dv = pt_1 - pt_2; - std::string alt_conf(bonding_atom->altLoc); + std::string alt_conf(bonding_atom->altLoc()); std::string res_name(residue_p->GetResName()); std::vector ring_atom_names; diff --git a/coot-utils/polar-atoms.cc b/coot-utils/polar-atoms.cc index 8c4c790764..c44961d596 100644 --- a/coot-utils/polar-atoms.cc +++ b/coot-utils/polar-atoms.cc @@ -83,7 +83,7 @@ coot::buried_unsatisfied_polar_atoms(mmdb::Manager *mol) { std::vector is_polar(n_selected_atoms, false); for (int i=0; iresidue->GetResName()); + std::string res_name(at->GetResidue()->GetResName()); std::string at_name(at->GetAtomName()); quick_protein_donor_acceptors::key k(res_name, at_name); hb_t hb_type = pda.get_type(k); @@ -103,7 +103,7 @@ coot::buried_unsatisfied_polar_atoms(mmdb::Manager *mol) { if (at) { if (! at->isTer()) { bool found_something = false; - std::string res_name(at->residue->GetResName()); + std::string res_name(at->GetResidue()->GetResName()); std::string at_name(at->GetAtomName()); quick_protein_donor_acceptors::key key_1(res_name, at_name); std::set::const_iterator it; @@ -111,7 +111,7 @@ coot::buried_unsatisfied_polar_atoms(mmdb::Manager *mol) { mmdb::Atom *at_neighb = atom_selection[*it]; if (at_neighb) { if (! at_neighb->isTer()) { - std::string res_name_n(at->residue->GetResName()); + std::string res_name_n(at->GetResidue()->GetResName()); std::string at_name_n(at->GetAtomName()); quick_protein_donor_acceptors::key key_2(res_name_n, at_name_n); std::pair is_valid = pda.is_hydrogen_bond_by_types(key_1, key_2); diff --git a/coot-utils/q-score.hh b/coot-utils/q-score.hh index 218271e040..86551b2bc3 100644 --- a/coot-utils/q-score.hh +++ b/coot-utils/q-score.hh @@ -270,7 +270,7 @@ namespace coot { at->PutUDData(udd_q_score, q_score); if (false) std::cout << "results per atom " << atom_spec_t(at) << " " << q_score - << " B-factor " << at->tempFactor << std::endl; + << " B-factor " << at->tempFactor() << std::endl; if (q_score > -1000.0) residue_q_scores[res_spec].add(q_score); } diff --git a/coot-utils/read-sm-cif.cc b/coot-utils/read-sm-cif.cc index 29597f616f..95eecb0ab2 100644 --- a/coot-utils/read-sm-cif.cc +++ b/coot-utils/read-sm-cif.cc @@ -262,10 +262,10 @@ coot::smcif::read_coordinates(mmdb::mmcif::PData data, const clipper::Cell &cell if (ele.first == "BR") charge = -1; if (ele.first == "I") charge = -1; - at->charge = charge; + at->charge() = charge; if (alt_loc.length()) - strncpy(at->altLoc, alt_loc.c_str(), (alt_loc.size()+1)); // shove. + strncpy(at->altLoc(), alt_loc.c_str(), (alt_loc.size()+1)); // shove. if (false) std::cout << " found atom: \"" << label << "\" symbol: \"" << symbol @@ -331,12 +331,12 @@ coot::smcif::read_coordinates(mmdb::mmcif::PData data, const clipper::Cell &cell clipper::U_aniso_frac caf(u11/(a*a), u22/(b*b), u33/(c*c), u12/(a*b), u13/(a*c), u23/(b*c)); clipper::U_aniso_orth cao = caf.u_aniso_orth(cell); - at->u11 = cao(0,0); - at->u22 = cao(1,1); - at->u33 = cao(2,2); - at->u12 = cao(0,1); - at->u13 = cao(0,2); - at->u23 = cao(1,2); + at->u11() = cao(0,0); + at->u22() = cao(1,1); + at->u33() = cao(2,2); + at->u12() = cao(0,1); + at->u13() = cao(0,2); + at->u23() = cao(1,2); at->WhatIsSet |= mmdb::ASET_Anis_tFac; // is anisotropic } } @@ -448,7 +448,7 @@ coot::smcif::read_sm_cif(const std::string &file_name) const { mmdb::Chain *chain_p = new mmdb::Chain; mmdb::Residue *residue_p = new mmdb::Residue; chain_p->SetChainID(""); - residue_p->seqNum = 1; + residue_p->GetSeqNum() = 1; residue_p->SetResName("XXX"); for (unsigned int iat=0; iatAddAtom(atoms[iat]); diff --git a/coot-utils/reduce.cc b/coot-utils/reduce.cc index e7411f1cfe..9cbcc09032 100644 --- a/coot-utils/reduce.cc +++ b/coot-utils/reduce.cc @@ -603,7 +603,7 @@ coot::reduce::add_main_chain_H(mmdb::Residue *residue_p, mmdb::Residue *residue_ clipper::Coord_orth at_ca_pos = co(at_ca); double angle = clipper::Util::d2rad(125.0); clipper::Coord_orth H_pos(at_ca_pos, at_c_pos, at_n_pos, bl, angle, M_PI); - mmdb::realtype bf = at_n->tempFactor; + mmdb::realtype bf = at_n->tempFactor(); add_hydrogen_atom(" H ", H_pos, bf, alt_confs[i], residue_p); } } @@ -653,7 +653,7 @@ coot::reduce::add_main_chain_HA(mmdb::Residue *residue_p) { mmdb::Atom *at_n3 = residue_p->GetAtom(" CB ", 0, alt_confs[i].c_str()); if (at_ca && at_n1 && at_n2 && at_n3) { clipper::Coord_orth pos = position_by_tetrahedron(at_ca, at_n1, at_n2, at_n3, bl); - mmdb::realtype bf = at_ca->tempFactor; + mmdb::realtype bf = at_ca->tempFactor(); add_hydrogen_atom(" HA ", pos, bf, alt_confs[i], residue_p); } } @@ -670,7 +670,7 @@ coot::reduce::add_hydrogen_atom(std::string atom_name, clipper::Coord_orth &pos, new_H->SetElementName(" H"); // PDBv3 FIXME new_H->SetCoordinates(pos.x(), pos.y(), pos.z(), 1.0, bf); if (! altconf.empty()) - strncpy(new_H->altLoc, altconf.c_str(), 18); // 19 is mmdb limit, I think + strncpy(new_H->altLoc(), altconf.c_str(), 18); // 19 is mmdb limit, I think // now test if the atom is there already. // @@ -682,8 +682,8 @@ coot::reduce::add_hydrogen_atom(std::string atom_name, clipper::Coord_orth &pos, bool already_exits = 0; residue_p->GetAtomTable(residue_atoms, n_atoms); for (int i=0; iname; - std::string residue_atom_alt_conf = residue_atoms[i]->altLoc; + std::string residue_atom_name = residue_atoms[i]->GetAtomName(); + std::string residue_atom_alt_conf = residue_atoms[i]->altLoc(); if (residue_atom_name == atom_name) { if (residue_atom_alt_conf == altconf) { already_exits = true; @@ -770,7 +770,7 @@ coot::reduce::add_methyl_Hs(const std::string &at_name_1, // HB1 (for example) clipper::Coord_orth pav_2 = p12; clipper::Coord_orth pav_3 = p13; if (at_3) { - mmdb::realtype bf = at_3->tempFactor; + mmdb::realtype bf = at_3->tempFactor(); mmdb::Atom *at_H_0 = add_hydrogen_atom(at_name_1, pav_1, bf, alt_confs[i], residue_p); mmdb::Atom *at_H_1 = add_hydrogen_atom(at_name_2, pav_2, bf, alt_confs[i], residue_p); mmdb::Atom *at_H_2 = add_hydrogen_atom(at_name_3, pav_3, bf, alt_confs[i], residue_p); @@ -819,7 +819,7 @@ coot::reduce::add_methyl_Hs(const std::string &at_name_1, // HB1 (for example) clipper::Coord_orth pav_1 = p11; clipper::Coord_orth pav_2 = p12; clipper::Coord_orth pav_3 = p13; - mmdb::realtype bf = at_3->tempFactor; + mmdb::realtype bf = at_3->tempFactor(); mmdb::Atom *at_0 = add_hydrogen_atom(at_name_1, pav_1, bf, alt_confs[i], residue_p); mmdb::Atom *at_1 = add_hydrogen_atom(at_name_2, pav_2, bf, alt_confs[i], residue_p); mmdb::Atom *at_2 = add_hydrogen_atom(at_name_3, pav_3, bf, alt_confs[i], residue_p); @@ -859,7 +859,7 @@ coot::reduce::add_2_sp3_hydrogens(const std::string &H_at_name_1, std::pair Hs = position_pair_by_bisection(at_1, at_2, at_3, bond_length, clipper::Util::d2rad(angle_between_Hs)); - mmdb::realtype bf = at_2->tempFactor; + mmdb::realtype bf = at_2->tempFactor(); if (! choose_only_farthest_position) { add_hydrogen_atom(H_at_name_1, Hs.first, bf, alt_confs[i], residue_p); add_hydrogen_atom(H_at_name_2, Hs.second, bf, alt_confs[i], residue_p); @@ -937,7 +937,7 @@ coot::reduce::add_tetrahedral_hydrogen(const std::string &H_at_name, if (at_central && at_n_1 && at_n_2 && at_n_3) { clipper::Coord_orth H_pos = position_by_tetrahedron(at_central, at_n_1, at_n_2, at_n_3, bond_length); - mmdb::realtype bf = at_central->tempFactor; + mmdb::realtype bf = at_central->tempFactor(); add_hydrogen_atom(H_at_name, H_pos, bf, alt_confs[i], residue_p); } } @@ -982,7 +982,7 @@ coot::reduce::add_aromatic_hydrogen(const std::string &H_at_name, mmdb::Atom *at_n_2 = residue_p->GetAtom(neighb_at_name_2.c_str(), 0, alt_confs[i].c_str()); mmdb::Atom *at_n_3 = residue_p->GetAtom(neighb_at_name_3.c_str(), 0, alt_confs[i].c_str()); if (at_n_1 && at_n_2 && at_n_3) { - mmdb::realtype bf = at_n_2->tempFactor; + mmdb::realtype bf = at_n_2->tempFactor(); clipper::Coord_orth H_pos = position_by_bisection(at_n_1, at_n_2, at_n_3, bl); add_hydrogen_atom(H_at_name, H_pos, bf, alt_confs[i], residue_p); } else { @@ -1031,7 +1031,7 @@ coot::reduce::add_amino_hydrogens(const std::string &H_at_name_1, bl_amino, clipper::Util::d2rad(120), clipper::Util::d2rad(0)); - mmdb::realtype bf = at_n_1->tempFactor; + mmdb::realtype bf = at_n_1->tempFactor(); add_hydrogen_atom(H_at_name_1, Hp1, bf, alt_confs[i], residue_p); add_hydrogen_atom(H_at_name_2, Hp2, bf, alt_confs[i], residue_p); } @@ -1085,7 +1085,7 @@ coot::reduce::add_guanidinium_hydrogens(mmdb::Residue *residue_p) { mmdb::Atom *at_n_2 = residue_p->GetAtom(" NE ", 0, alt_confs[i].c_str()); mmdb::Atom *at_n_3 = residue_p->GetAtom(" CZ ", 0, alt_confs[i].c_str()); if (at_n_1 && at_n_2 && at_n_3) { - mmdb::realtype bf = at_n_2->tempFactor; + mmdb::realtype bf = at_n_2->tempFactor(); clipper::Coord_orth H_pos = position_by_bisection(at_n_1, at_n_2, at_n_3, bl); add_hydrogen_atom(H_at_name, H_pos, bf, alt_confs[i], residue_p); } else { @@ -1107,8 +1107,8 @@ coot::reduce::add_guanidinium_hydrogens(mmdb::Residue *residue_p) { mmdb::Atom *at_nh1 = residue_p->GetAtom(" NH1", 0, alt_confs[i].c_str()); mmdb::Atom *at_nh2 = residue_p->GetAtom(" NH2", 0, alt_confs[i].c_str()); if (at_n_1 && at_n_2 && at_nh1 && at_nh2) { - double bf_nh1 = at_nh1->tempFactor; - double bf_nh2 = at_nh2->tempFactor; + double bf_nh1 = at_nh1->tempFactor(); + double bf_nh2 = at_nh2->tempFactor(); double a = clipper::Util::d2rad(120); double t = clipper::Util::d2rad(180); clipper::Coord_orth hh11 = position_by_bond_length_angle_torsion(at_n_1, at_n_2, at_nh1, bl, a, 0); @@ -1149,7 +1149,7 @@ coot::reduce::add_trp_indole_hydrogen(const std::string &H_name, mmdb::Atom *at_3 = residue_p->GetAtom(at_name_3.c_str(), 0, alt_confs[i].c_str()); if (at_1 && at_2 && at_3) { clipper::Coord_orth H_pos = position_by_bisection(at_1, at_2, at_3, bl); - double bf = at_2->tempFactor; + double bf = at_2->tempFactor(); add_hydrogen_atom(H_name, H_pos, bf, alt_confs[i], residue_p); } } @@ -1244,7 +1244,7 @@ coot::reduce::add_xH_H(const std::string &H_name, clipper::Coord_orth H_pos = position_by_bond_length_angle_torsion(at_3, at_2, at_1, bl, clipper::Util::d2rad(angle), clipper::Util::d2rad(tor_inital)); - double bf = at_2->tempFactor; + double bf = at_2->tempFactor(); mmdb::Atom *at = add_hydrogen_atom(H_name, H_pos, bf, alt_confs[i], residue_p); r.push_back(at); spinables.add(at_1, atom_with_attached_Hs::HYDROXYL, at); // maybe need SULFHYDRYL separate? @@ -1280,7 +1280,7 @@ coot::reduce::add_his_ring_H(const std::string &H_name, mmdb::Atom *at_3 = residue_p->GetAtom(at_name_3.c_str(), 0, alt_confs[i].c_str()); if (at_1 && at_2 && at_3) { clipper::Coord_orth H_pos = position_by_bisection(at_1, at_2, at_3, bl_arom); - double bf = at_2->tempFactor; + double bf = at_2->tempFactor(); mmdb::Atom *at = add_hydrogen_atom(H_name, H_pos, bf, alt_confs[i], residue_p); r.push_back(at); } @@ -1381,7 +1381,7 @@ coot::reduce::switch_his_protonation(mmdb::Residue *residue_p, // double bl_arom = 0.93; if (current_H_atom) { - std::string atom_name = current_H_atom->name; + std::string atom_name = current_H_atom->GetAtomName(); std::string new_atom_name; if (atom_name == " HD1") new_atom_name = " HE2"; if (atom_name == " HE2") new_atom_name = " HD1"; @@ -1399,7 +1399,7 @@ coot::reduce::switch_his_protonation(mmdb::Residue *residue_p, at_name_2 = " NE2"; at_name_3 = " CD2"; } - std::string alt_conf = current_H_atom->altLoc; + std::string alt_conf = current_H_atom->altLoc(); mmdb::Atom *at_1 = residue_p->GetAtom(at_name_1.c_str(), 0, alt_conf.c_str()); mmdb::Atom *at_2 = residue_p->GetAtom(at_name_2.c_str(), 0, alt_conf.c_str()); mmdb::Atom *at_3 = residue_p->GetAtom(at_name_3.c_str(), 0, alt_conf.c_str()); @@ -1407,7 +1407,7 @@ coot::reduce::switch_his_protonation(mmdb::Residue *residue_p, std::cout << "switch_his_protonation() " << 2 << " " << new_atom_name << std::endl; current_H_atom->SetAtomName(new_atom_name.c_str()); clipper::Coord_orth pos = position_by_bisection(at_1, at_2, at_3, bl_arom); - double bf = current_H_atom->tempFactor; + double bf = current_H_atom->tempFactor(); current_H_atom->SetCoordinates(pos.x(), pos.y(), pos.z(), 1.0, bf); } } @@ -1553,7 +1553,7 @@ coot::reduce::delete_atom_by_name(const std::string &at_name, mmdb::Residue *res int n_atoms = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - std::string ele(at->element); + std::string ele(at->GetElementName()); if (ele == " H" || ele == " D") { residue_p->DeleteAtom(iat); an_atom_was_deleted = true; @@ -1582,7 +1582,7 @@ coot::reduce::delete_hydrogen_atoms() { int n_atoms = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - std::string ele(at->element); + std::string ele(at->GetElementName()); if (ele == " H" || ele == " D") { atoms_to_be_deleted.push_back(at); } @@ -1910,7 +1910,7 @@ coot::reduce::atoms_with_spinnable_Hs::add(mmdb::Atom *at, atom_with_attached_Hs::hydrogen_t type, const std::vector &attached_hydrogen_atoms) { - std::string alt_loc(at->altLoc); + std::string alt_loc(at->altLoc()); atom_with_attached_Hs awaH(at, type, attached_hydrogen_atoms); typed_atoms[alt_loc].push_back(awaH); } @@ -1920,7 +1920,7 @@ coot::reduce::atoms_with_spinnable_Hs::add(mmdb::Atom *at, atom_with_attached_Hs::hydrogen_t type, mmdb::Atom *attahed_hydrogen_atom) { - std::string alt_loc(at->altLoc); + std::string alt_loc(at->altLoc()); std::vector v; v.push_back(attahed_hydrogen_atom); atom_with_attached_Hs awaH(at, type, v); @@ -1958,7 +1958,7 @@ coot::reduce::atoms_with_spinnable_Hs::cliquize() { clipper::Coord_orth at_pos = co(atoms[iat].at); for (unsigned int icl=0; iclresidue != cliques[icl][j].at->residue) { + if (atoms[iat].at->GetResidue() != cliques[icl][j].at->GetResidue()) { clipper::Coord_orth pos = co(cliques[icl][j].at); clipper::Coord_orth diff(at_pos - pos); double dv_sqrd = diff.lengthsq(); diff --git a/coot-utils/secondary-structure-headers.cc b/coot-utils/secondary-structure-headers.cc index 9d07819442..e01746c9de 100644 --- a/coot-utils/secondary-structure-headers.cc +++ b/coot-utils/secondary-structure-headers.cc @@ -371,8 +371,8 @@ coot::secondary_structure_header_records::get_sheet_order(mmdb::Manager *mol, for (int ic=0; icresidue; - mmdb::Residue *r_2 = at_2->residue; + mmdb::Residue *r_1 = at_1->GetResidue(); + mmdb::Residue *r_2 = at_2->GetResidue(); if (r_1 != r_2) { int rn_1 = r_1->GetSeqNum(); int rn_2 = r_2->GetSeqNum(); diff --git a/coot-utils/stack-and-pair.cc b/coot-utils/stack-and-pair.cc index 1e4c3eb212..0c0d678daa 100644 --- a/coot-utils/stack-and-pair.cc +++ b/coot-utils/stack-and-pair.cc @@ -77,7 +77,7 @@ coot::stack_and_pair::get_base_normal(mmdb::Residue *residue_p) const { residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); + std::string atom_name(at->GetAtomName()); if (base_atom_name_set.find(atom_name) != base_atom_name_set.end()) { v.push_back(co(at)); } @@ -100,7 +100,7 @@ coot::stack_and_pair::get_base_atom_names(mmdb::Residue *residue_p) const { residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); + std::string atom_name(at->GetAtomName()); if (base_atom_name_set.find(atom_name) != base_atom_name_set.end()) { v.push_back(atom_name); } @@ -120,7 +120,7 @@ coot::stack_and_pair::get_base_centre(mmdb::Residue *residue_p) const { residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); + std::string atom_name(at->GetAtomName()); if (base_atom_name_set.find(atom_name) != base_atom_name_set.end()) { centre_sum += co(at); n_centres++; @@ -160,7 +160,7 @@ coot::stack_and_pair::calculate_residue_normals(mmdb::Atom **SelAtom, int n_sel_ std::set done_res; std::map m; for (int i=0; iresidue; + mmdb::Residue *r = SelAtom[i]->GetResidue(); if (done_res.find(r) == done_res.end()) { std::pair bn = get_base_normal(r); if (bn.first) { @@ -186,7 +186,7 @@ coot::stack_and_pair::mark_donors_and_acceptors(mmdb::Manager *mol, int selectio int udd_h_bond_type_handle = mol->RegisterUDInteger(mmdb::UDR_ATOM, "hb_type"); for (int i=0; iname; + std::string name = at->GetAtomName(); std::string res_name = at->GetResName(); std::map::const_iterator it; @@ -342,17 +342,17 @@ coot::stack_and_pair::paired_residues(mmdb::Manager *mol, // in different residues and both are are O or N, and are close // enough together and both are nucleic acids - if (at_1->residue != at_2->residue) { - std::string ele_1(at_1->element); - std::string ele_2(at_2->element); + if (at_1->GetResidue() != at_2->GetResidue()) { + std::string ele_1(at_1->GetElementName()); + std::string ele_2(at_2->GetElementName()); // PDBv3 FIXME if (ele_1 == " O" || ele_1 == " N") { if (ele_2 == " O" || ele_2 == " N") { - float dx = at_1->x - at_2->x; - float dy = at_1->y - at_2->y; - float dz = at_1->z - at_2->z; + float dx = at_1->x() - at_2->x(); + float dy = at_1->y() - at_2->y(); + float dz = at_1->z() - at_2->z(); float dd = dx * dx + dy * dy + dz * dz; if (dd < dist_crit_sqrt) { int hb_type_1 = coot::HB_UNASSIGNED; @@ -365,17 +365,17 @@ coot::stack_and_pair::paired_residues(mmdb::Manager *mol, if (hb_type_2 == coot::HB_DONOR || hb_type_2 == coot::HB_BOTH) { if (at_1->GetChain() == at_2->GetChain()) { - int residue_index_1 = at_1->residue->index; - int residue_index_2 = at_2->residue->index; + int residue_index_1 = at_1->GetResidue()->GetIndex(); + int residue_index_2 = at_2->GetResidue()->GetIndex(); int residue_index_delta = residue_index_2 - residue_index_1; if (abs(residue_index_delta) < 2) continue; } - if (util::is_nucleotide(at_1->residue)) { - if (util::is_nucleotide(at_2->residue)) { + if (util::is_nucleotide(at_1->GetResidue())) { + if (util::is_nucleotide(at_2->GetResidue())) { - if (similar_normals(at_1->residue, at_2->residue, normal_map)) { + if (similar_normals(at_1->GetResidue(), at_2->GetResidue(), normal_map)) { // also, to stop base pairing the residue above // or below, we need to check the dot product @@ -388,8 +388,8 @@ coot::stack_and_pair::paired_residues(mmdb::Manager *mol, clipper::Coord_orth pt_2 = co(at_2); clipper::Coord_orth atom_atom_unit_vector((pt_2 - pt_1).unit()); - double dp_1 = clipper::Coord_orth::dot(atom_atom_unit_vector, normal_map[at_1->residue]); - double dp_2 = clipper::Coord_orth::dot(atom_atom_unit_vector, normal_map[at_2->residue]); + double dp_1 = clipper::Coord_orth::dot(atom_atom_unit_vector, normal_map[at_1->GetResidue()]); + double dp_2 = clipper::Coord_orth::dot(atom_atom_unit_vector, normal_map[at_2->GetResidue()]); if (false) { std::cout << " dot product 1 " << dp_1 << " " << atom_spec_t(at_1) << " " << atom_spec_t(at_2) << "\n"; @@ -400,8 +400,8 @@ coot::stack_and_pair::paired_residues(mmdb::Manager *mol, if (std::abs(dp_2) < 0.5) { // no ribose or phosphate atoms: - std::string name_1(at_1->name); - std::string name_2(at_2->name); + std::string name_1(at_1->GetAtomName()); + std::string name_2(at_2->GetAtomName()); if (excluded_oxygens.find(name_1) == excluded_oxygens.end()) { if (excluded_oxygens.find(name_2) == excluded_oxygens.end()) { @@ -438,8 +438,8 @@ coot::stack_and_pair::paired_residues(mmdb::Manager *mol, for (std::size_t i=0; iresidue; - mmdb::Residue *res_2 = at_2->residue; + mmdb::Residue *res_1 = at_1->GetResidue(); + mmdb::Residue *res_2 = at_2->GetResidue(); bool found = false; for (std::size_t j=0; jGetNumberOfResidues(); for (int ires=0; iresGetResidue(ires); - std::string resname = residue_p->name; + std::string resname = residue_p->GetResName(); if (((resname == "WAT" || resname == "HOH") && waters_only_flag) || !waters_only_flag) { @@ -68,7 +68,7 @@ coot::util::trim_molecule_by_map(mmdb::Manager *mol, for (int iat=0; iatGetAtom(iat); - clipper::Coord_orth co(at->x, at->y, at->z); + clipper::Coord_orth co(at->x(), at->y(), at->z()); if (density_at_point(xmap, co) < map_level) { // A baddie. What do we do with it? Set its @@ -80,7 +80,7 @@ coot::util::trim_molecule_by_map(mmdb::Manager *mol, } if (remove_or_zero_occ_flag == coot::util::TRIM_BY_MAP_ZERO_OCC) { - at->occupancy = 0.0; + at->occupancy() = 0.0; n_changed++; } } diff --git a/coot-utils/water-coordination.cc b/coot-utils/water-coordination.cc index 9a46269cd0..dc2d8f1951 100644 --- a/coot-utils/water-coordination.cc +++ b/coot-utils/water-coordination.cc @@ -132,8 +132,8 @@ coot::util::water_coordination_t::init_internal(mmdb::Manager *mol, coot::util::contact_atoms_info_t::contact_atom_t::contact_atom_t(mmdb::Atom *contactor, mmdb::Atom *central_atom) { - clipper::Coord_orth co_1( contactor->x, contactor->y, contactor->z); - clipper::Coord_orth co_2(central_atom->x, central_atom->y, central_atom->z); + clipper::Coord_orth co_1( contactor->x(), contactor->y(), contactor->z()); + clipper::Coord_orth co_2(central_atom->x(), central_atom->y(), central_atom->z()); dist = clipper::Coord_orth::length(co_1, co_2); at = contactor; for (int i=0; i<4; i++) @@ -148,8 +148,8 @@ coot::util::contact_atoms_info_t::contact_atom_t::contact_atom_t(mmdb::Atom *con mmdb::Atom *central_atom, const mmdb::mat44 &m) { - clipper::Coord_orth co_1( contactor->x, contactor->y, contactor->z); - clipper::Coord_orth co_2(central_atom->x, central_atom->y, central_atom->z); + clipper::Coord_orth co_1( contactor->x(), contactor->y(), contactor->z()); + clipper::Coord_orth co_2(central_atom->x(), central_atom->y(), central_atom->z()); dist = clipper::Coord_orth::length(co_1, co_2); at = contactor; for (int i=0; i<4; i++) @@ -165,13 +165,13 @@ coot::util::water_coordination_t::add_contact(mmdb::Atom *atom_central, mmdb::Atom *atom_contactor, const mmdb::mat44 &mat) { - std::string alt_conf_1 = atom_contactor->altLoc; - std::string alt_conf_2 = atom_central->altLoc; + std::string alt_conf_1 = atom_contactor->altLoc(); + std::string alt_conf_2 = atom_central->altLoc(); if ((alt_conf_1 == alt_conf_2) || (alt_conf_1 == "") || (alt_conf_2 == "")) { // filter out H water contacts. - std::string ele(atom_contactor->element); + std::string ele(atom_contactor->GetElementName()); if (ele != " H") { coot::util::contact_atoms_info_t::contact_atom_t con_at(atom_contactor, atom_central, mat); // @@ -363,7 +363,7 @@ coot::util::contact_atoms_info_t::test_for_ele(coot::util::contact_atoms_info_t: int n_contacts = 0; if (contact_atoms.size() > 2) { for (unsigned int j=0; jelement); + std::string ele(contact_atoms[j].at->GetElementName()); double Rj = contact_atoms[j].dist; if (Rj < R0) { // it's too close to a neighbor to be the required metal type. sum_v_j = 0; @@ -371,7 +371,7 @@ coot::util::contact_atoms_info_t::test_for_ele(coot::util::contact_atoms_info_t: } if (ele == " O") { double v_j = pow(Rj/R0, -N); - double occ = contact_atoms[j].at->occupancy; // symmetry overlaps handled. + double occ = contact_atoms[j].at->occupancy(); // symmetry overlaps handled. sum_v_j += v_j * occ; // was it a protein atom contact < 3.5A? We need at least 1 of them. std::string resname(contact_atoms[j].at->GetResName()); @@ -410,7 +410,7 @@ coot::util::contact_atoms_info_t::test_for_ele(coot::util::contact_atoms_info_t: << ele_index << std::endl; sum_v_j = 0.0; for (unsigned int j=0; jelement); + std::string ele(contact_atoms[j].at->GetElementName()); double Rj = contact_atoms[j].dist; if (ele == " O") { double v_j = pow(Rj/R0, -N); diff --git a/db-main/db-strands.cc b/db-main/db-strands.cc index 5b04a6b5c2..41fb2ad626 100644 --- a/db-main/db-strands.cc +++ b/db-main/db-strands.cc @@ -246,7 +246,7 @@ coot::db_strands::trim_to_mainchain(mmdb::Manager *mol) const { for (int iat=0; iatGetAtom(iat); - std::string ele = at->element; + std::string ele = at->GetElementName(); if (!is_main_chain_or_cb_p(at) || ele == " H" || ele == " D") { residue_p->DeleteAtom(iat); @@ -282,17 +282,17 @@ coot::db_strands::orient_strand_on_z(int SelHnd, mmdb::Manager *mol) const { residue_p->GetAtomTable(atoms, n_atoms); for (int iat=0; iatname); + std::string atom_name(at->GetAtomName()); if (atom_name == " N ") { - clipper::Coord_orth pt(at->x, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); atom_vec.push_back(pt); } if (atom_name == " CA ") { - clipper::Coord_orth pt(at->x, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); atom_vec.push_back(pt); } if (atom_name == " C ") { - clipper::Coord_orth pt(at->x, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); atom_vec.push_back(pt); } } @@ -325,11 +325,11 @@ coot::db_strands::apply_rtop_to_strand(int SelHnd, mmdb::Manager *mol, residue_p->GetAtomTable(atoms, n_atoms); for (int iat=0; iatx, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); clipper::Coord_orth n = pt.transform(rtop); - at->x = n.x(); - at->y = n.y(); - at->z = n.z(); + at->x() = n.x(); + at->y() = n.y(); + at->z() = n.z(); } } } diff --git a/density-contour/gaussian-surface.cc b/density-contour/gaussian-surface.cc index 2c3a7b04d0..31b8085bf0 100644 --- a/density-contour/gaussian-surface.cc +++ b/density-contour/gaussian-surface.cc @@ -79,7 +79,7 @@ coot::gaussian_surface_t::using_an_xmap(mmdb::Manager *mol, const std::string &c }; auto mmdb_to_clipper = [] (mmdb::Atom *at) { - return clipper::Coord_orth(at->x, at->y, at->z); + return clipper::Coord_orth(at->x(), at->y(), at->z()); }; auto clipper_to_cart = [] (const clipper::Coord_orth &co) { diff --git a/docking/haddock-utils.cc b/docking/haddock-utils.cc index 00c25de740..a5f9f2c177 100644 --- a/docking/haddock-utils.cc +++ b/docking/haddock-utils.cc @@ -120,22 +120,22 @@ compute_residue_sasa(mmdb::Manager *mol, for (int ia=0; iaelement) + probe_radius; + double atom_radius = mmdb::getVdWaalsRadius(atom->GetElementName()) + probe_radius; double point_area = 4.0 * M_PI * atom_radius * atom_radius / n_points; int accessible = 0; for (int ip=0; ipx + atom_radius * sphere_points[ip].x(); - double py = atom->y + atom_radius * sphere_points[ip].y(); - double pz = atom->z + atom_radius * sphere_points[ip].z(); + double px = atom->x() + atom_radius * sphere_points[ip].x(); + double py = atom->y() + atom_radius * sphere_points[ip].y(); + double pz = atom->z() + atom_radius * sphere_points[ip].z(); bool buried = false; for (int j=0; jelement) + probe_radius; - double dx = px - all_atoms[j]->x; - double dy = py - all_atoms[j]->y; - double dz = pz - all_atoms[j]->z; + double nr = mmdb::getVdWaalsRadius(all_atoms[j]->GetElementName()) + probe_radius; + double dx = px - all_atoms[j]->x(); + double dy = py - all_atoms[j]->y(); + double dz = pz - all_atoms[j]->z(); if (dx*dx + dy*dy + dz*dz < nr*nr) { buried = true; break; diff --git a/docking/intermolecular-energy.cc b/docking/intermolecular-energy.cc index ef5873cf8a..e52963fb50 100644 --- a/docking/intermolecular-energy.cc +++ b/docking/intermolecular-energy.cc @@ -62,12 +62,12 @@ coot::haddock::extract_molecule_data(mmdb::Manager *mol, data.atoms.resize(n_atoms); for (int i=0; ix, at->y, at->z); - data.atoms[i].vdw_radius = mmdb::getVdWaalsRadius(at->element); + data.atoms[i].position = clipper::Coord_orth(at->x(), at->y(), at->z()); + data.atoms[i].vdw_radius = mmdb::getVdWaalsRadius(at->GetElementName()); data.atoms[i].charge = charge_table.getCharge( std::string(at->GetResName()), - std::string(at->name)); - data.atoms[i].atom_name = at->name; + std::string(at->GetAtomName())); + data.atoms[i].atom_name = at->GetAtomName(); data.atoms[i].residue_name = at->GetResName(); // Assign residue index @@ -107,9 +107,9 @@ coot::haddock::extract_molecule_data(mmdb::Manager *mol, residue_atoms_t ra; ra.positions.resize(n_res_atoms); for (int j=0; jx, - res_atoms[j]->y, - res_atoms[j]->z); + ra.positions[j] = clipper::Coord_orth(res_atoms[j]->x(), + res_atoms[j]->y(), + res_atoms[j]->z()); } data.active_residue_atoms.push_back(ra); mol->DeleteSelection(res_sel); @@ -132,9 +132,9 @@ coot::haddock::extract_molecule_data(mmdb::Manager *mol, residue_atoms_t ra; ra.positions.resize(n_res_atoms); for (int j=0; jx, - res_atoms[j]->y, - res_atoms[j]->z); + ra.positions[j] = clipper::Coord_orth(res_atoms[j]->x(), + res_atoms[j]->y(), + res_atoms[j]->z()); } data.partner_residue_atoms.push_back(ra); mol->DeleteSelection(res_sel); diff --git a/docking/test-docking.cc b/docking/test-docking.cc index 1268852477..0e396aa6c8 100644 --- a/docking/test-docking.cc +++ b/docking/test-docking.cc @@ -236,9 +236,9 @@ find_interface(mmdb::Manager *mol, for (int i=0; ix - atoms_lig[j]->x; - double dy = atoms_rec[i]->y - atoms_lig[j]->y; - double dz = atoms_rec[i]->z - atoms_lig[j]->z; + double dx = atoms_rec[i]->x() - atoms_lig[j]->x(); + double dy = atoms_rec[i]->y() - atoms_lig[j]->y(); + double dz = atoms_rec[i]->z() - atoms_lig[j]->z(); if (dx*dx + dy*dy + dz*dz < contact_dist_sq) { mmdb::Residue *r_rec = atoms_rec[i]->GetResidue(); mmdb::Residue *r_lig = atoms_lig[j]->GetResidue(); @@ -277,13 +277,13 @@ static void apply_dock_transform(mmdb::Manager *mol, mol->GetSelIndex(sel, atoms, n_atoms); for (int i=0; i(atoms[i]->x - com_B.x()), - static_cast(atoms[i]->y - com_B.y()), - static_cast(atoms[i]->z - com_B.z())); + glm::vec3 p(static_cast(atoms[i]->x() - com_B.x()), + static_cast(atoms[i]->y() - com_B.y()), + static_cast(atoms[i]->z() - com_B.z())); glm::vec3 rp = R * p; - atoms[i]->x = rp.x + result.translation.x(); - atoms[i]->y = rp.y + result.translation.y(); - atoms[i]->z = rp.z + result.translation.z(); + atoms[i]->x() = rp.x + result.translation.x(); + atoms[i]->y() = rp.y + result.translation.y(); + atoms[i]->z() = rp.z + result.translation.z(); } mol->DeleteSelection(sel); @@ -399,9 +399,9 @@ static void test_dock_9v3f_chain_E(const std::string &pdb_file) { mol->GetSelIndex(sel_E_orig, orig_E_atoms, n_orig_E); double ox = 0, oy = 0, oz = 0; for (int i=0; ix; - oy += orig_E_atoms[i]->y; - oz += orig_E_atoms[i]->z; + ox += orig_E_atoms[i]->x(); + oy += orig_E_atoms[i]->y(); + oz += orig_E_atoms[i]->z(); } clipper::Coord_orth original_com_E(ox/n_orig_E, oy/n_orig_E, oz/n_orig_E); mol->DeleteSelection(sel_E_orig); @@ -572,9 +572,9 @@ static clipper::Coord_orth compute_com(mmdb::Manager *mol, double sx = 0, sy = 0, sz = 0; for (int i=0; ix; - sy += atoms[i]->y; - sz += atoms[i]->z; + sx += atoms[i]->x(); + sy += atoms[i]->y(); + sz += atoms[i]->z(); } mol->DeleteSelection(sel); @@ -647,7 +647,7 @@ static void test_dock_e2a_hpr(const std::string &pdb_e2a, mol_e2a->GetSelIndex(sel_f, atoms_f, n_f); for (int i=0; iGetSeqNum()] = - clipper::Coord_orth(atoms_f[i]->x, atoms_f[i]->y, atoms_f[i]->z); + clipper::Coord_orth(atoms_f[i]->x(), atoms_f[i]->y(), atoms_f[i]->z()); mol_e2a->DeleteSelection(sel_f); // Collect matching pairs from 1GGR chain A @@ -662,9 +662,9 @@ static void test_dock_e2a_hpr(const std::string &pdb_e2a, int resno = atoms_r[i]->GetSeqNum(); auto it = f3g_ca_map.find(resno); if (it != f3g_ca_map.end()) { - cas_ref.push_back(clipper::Coord_orth(atoms_r[i]->x, - atoms_r[i]->y, - atoms_r[i]->z)); + cas_ref.push_back(clipper::Coord_orth(atoms_r[i]->x(), + atoms_r[i]->y(), + atoms_r[i]->z())); cas_tgt.push_back(it->second); } } @@ -803,13 +803,13 @@ static void test_dock_e2a_hpr(const std::string &pdb_e2a, int n_ref_atoms = 0; ref_copy->GetSelIndex(sel_all, ref_atoms, n_ref_atoms); for (int i=0; ix, - ref_atoms[i]->y, - ref_atoms[i]->z); + clipper::Coord_orth orig(ref_atoms[i]->x(), + ref_atoms[i]->y(), + ref_atoms[i]->z()); clipper::Coord_orth transformed = rtop * orig; - ref_atoms[i]->x = transformed.x(); - ref_atoms[i]->y = transformed.y(); - ref_atoms[i]->z = transformed.z(); + ref_atoms[i]->x() = transformed.x(); + ref_atoms[i]->y() = transformed.y(); + ref_atoms[i]->z() = transformed.z(); } ref_copy->DeleteSelection(sel_all); ref_copy->WritePDBASCII("e2a-hpr-native.pdb"); @@ -848,8 +848,8 @@ static void test_dock_e2a_hpr(const std::string &pdb_e2a, int n_b = 0; mol_ref->GetSelIndex(sel_b, b_atoms, n_b); for (int i=0; ix, b_atoms[i]->y, - b_atoms[i]->z); + clipper::Coord_orth orig(b_atoms[i]->x(), b_atoms[i]->y(), + b_atoms[i]->z()); clipper::Coord_orth tfm = rtop * orig; int mapped_resno = b_atoms[i]->GetSeqNum() - 300; native_hpr_ca_map[mapped_resno] = tfm; @@ -877,9 +877,9 @@ static void test_dock_e2a_hpr(const std::string &pdb_e2a, for (int i=0; iGetSeqNum(); - e.position = clipper::Coord_orth(ca_atoms[i]->x, - ca_atoms[i]->y, - ca_atoms[i]->z); + e.position = clipper::Coord_orth(ca_atoms[i]->x(), + ca_atoms[i]->y(), + ca_atoms[i]->z()); hpr_ca_entries.push_back(e); } mol_hpr->DeleteSelection(sel_ca); diff --git a/geometry/dict-utils.cc b/geometry/dict-utils.cc index d6743a5e3c..7d09b2be71 100644 --- a/geometry/dict-utils.cc +++ b/geometry/dict-utils.cc @@ -838,7 +838,7 @@ coot::dictionary_residue_restraints_t::change_names(mmdb::Residue *residue_p, residue_p->GetAtomTable(res_selection, num_residue_atoms); for (int iat=0; iatname; + std::string atom_name = at->GetAtomName(); for (unsigned int j=0; jelement); + std::string ele(residue_atoms[iat]->GetElementName()); if (ele != "H" && ele != " H" && ele != "D" && ele != " D") n_non_H++; } @@ -172,9 +172,9 @@ coot::dictionary_residue_restraints_t::init(mmdb::Residue *residue_p) { // also fill atom_info with dict_atom objects for (int iat=0; iatelement); - dict_atom da(at->name, at->name, ele, "", std::pair (false, 0)); - clipper::Coord_orth pos(at->x, at->y, at->z); + std::string ele(residue_atoms[iat]->GetElementName()); + dict_atom da(at->GetAtomName(), at->GetAtomName(), ele, "", std::pair (false, 0)); + clipper::Coord_orth pos(at->x(), at->y(), at->z()); da.model_Cartn = std::make_pair(true, pos); atom_info.push_back(da); } @@ -191,15 +191,15 @@ coot::dictionary_residue_restraints_t::init(mmdb::Residue *residue_p) { mmdb::Atom *at_2 = AtomBonds[ibond].atom; if (at_2) { if (at_1 < at_2) { // pointer comparison - std::string at_name_1(at_1->name); - std::string at_name_2(at_2->name); + std::string at_name_1(at_1->GetAtomName()); + std::string at_name_2(at_2->GetAtomName()); std::string type = "single"; if (AtomBonds[ibond].order == 2) type = "double"; if (AtomBonds[ibond].order == 3) type = "triple"; - clipper::Coord_orth pt_1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth pt_2(at_2->x, at_2->y, at_2->z); + clipper::Coord_orth pt_1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth pt_2(at_2->x(), at_2->y(), at_2->z()); double dist = sqrt((pt_1-pt_2).lengthsq()); double dist_esd = 0.02; dict_bond_restraint_t br(at_name_1, at_name_2, type, dist, dist_esd, 0, 0, false); @@ -234,17 +234,17 @@ coot::dictionary_residue_restraints_t::init(mmdb::Residue *residue_p) { // if (at_1 && at_2 && at_3) { - clipper::Coord_orth pt_1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth pt_2(at_2->x, at_2->y, at_2->z); - clipper::Coord_orth pt_3(at_3->x, at_3->y, at_3->z); + clipper::Coord_orth pt_1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth pt_2(at_2->x(), at_2->y(), at_2->z()); + clipper::Coord_orth pt_3(at_3->x(), at_3->y(), at_3->z()); // doesn't exist (mmdb problem)? // double angle = BondAngle(at_1, at_2, at_3); double angle = clipper::Util::rad2d(clipper::Coord_orth::angle(pt_1, pt_2, pt_3)); // std::cout << "angle: " << angle << std::endl; if (angle > 0.001) { - std::string at_name_1(at_1->name); - std::string at_name_2(at_2->name); - std::string at_name_3(at_3->name); + std::string at_name_1(at_1->GetAtomName()); + std::string at_name_2(at_2->GetAtomName()); + std::string at_name_3(at_3->GetAtomName()); double angle_esd = 3; dict_angle_restraint_t ar(at_name_1, at_name_2, at_name_3, angle, angle_esd); angle_restraint.push_back(ar); @@ -1324,7 +1324,7 @@ coot::dictionary_residue_restraints_t::GetResidue(bool idealised_flag, float b_f mmdb::Atom *at = residue_atoms[iat]; if (! at->isTer()) { std::cout << "debug:: GetResidue() " << iat << " " << at->GetAtomName() - << at->x << " " << at->y << " " << at->z << std::endl; + << at->x() << " " << at->y() << " " << at->z() << std::endl; } } diff --git a/geometry/dreiding.cc b/geometry/dreiding.cc index 2cfa519588..74800d43e6 100644 --- a/geometry/dreiding.cc +++ b/geometry/dreiding.cc @@ -43,10 +43,10 @@ coot::protein_geometry::dreiding_torsion_energy(const std::string &comp_id, std::vector name(4); std::vector energy_type(4); std::vector sp_hybrid(4); - name[0] = atom_0->name; - name[1] = atom_1->name; - name[2] = atom_2->name; - name[3] = atom_3->name; + name[0] = atom_0->GetAtomName(); + name[1] = atom_1->GetAtomName(); + name[2] = atom_2->GetAtomName(); + name[3] = atom_3->GetAtomName(); for (unsigned int i=0; i<4; i++) { energy_type[i] = restraints.type_energy(name[i]); std::map::const_iterator atom_map_it = @@ -58,10 +58,10 @@ coot::protein_geometry::dreiding_torsion_energy(const std::string &comp_id, } sp_hybrid[i] = atom_map_it->second.sp_hybridisation; } - clipper::Coord_orth p0(atom_0->x, atom_0->y, atom_0->z); - clipper::Coord_orth p1(atom_1->x, atom_1->y, atom_1->z); - clipper::Coord_orth p2(atom_2->x, atom_2->y, atom_2->z); - clipper::Coord_orth p3(atom_3->x, atom_3->y, atom_3->z); + clipper::Coord_orth p0(atom_0->x(), atom_0->y(), atom_0->z()); + clipper::Coord_orth p1(atom_1->x(), atom_1->y(), atom_1->z()); + clipper::Coord_orth p2(atom_2->x(), atom_2->y(), atom_2->z()); + clipper::Coord_orth p3(atom_3->x(), atom_3->y(), atom_3->z()); // double phi = clipper::Coord_orth::torsion(p0,p1,p2,p3); // d = dreiding_torsion_energy(phi, sp_hybrid[1], sp_hybrid[2], "dummy", false, false); } @@ -100,10 +100,10 @@ coot::protein_geometry::dreiding_torsion_energy_params(const std::string &comp_i std::vector name(4); std::vector energy_type(4); std::vector sp_hybrid(4); - name[0] = quad.atom_1->name; - name[1] = quad.atom_2->name; - name[2] = quad.atom_3->name; - name[3] = quad.atom_4->name; + name[0] = quad.atom_1->GetAtomName(); + name[1] = quad.atom_2->GetAtomName(); + name[2] = quad.atom_3->GetAtomName(); + name[3] = quad.atom_4->GetAtomName(); for (unsigned int i=0; i<4; i++) { energy_type[i] = restraints.type_energy(name[i]); std::map::const_iterator atom_map_it = diff --git a/geometry/hydrophobic.cc b/geometry/hydrophobic.cc index 93a26ff0c2..4bf28da6db 100644 --- a/geometry/hydrophobic.cc +++ b/geometry/hydrophobic.cc @@ -80,6 +80,6 @@ bool coot::is_hydrophobic_atom(mmdb::Atom *at) { std::string atom_name(at->GetAtomName()); - std::string res_name(at->residue->GetResName()); + std::string res_name(at->GetResidue()->GetResName()); return is_hydrophobic_atom(res_name, atom_name); } diff --git a/geometry/link.cc b/geometry/link.cc index 7da24bff03..8c501aac50 100644 --- a/geometry/link.cc +++ b/geometry/link.cc @@ -493,13 +493,13 @@ coot::protein_geometry::find_glycosidic_linkage_type_by_distance(mmdb::Residue * second->GetAtomTable(res_selection_2, i_no_res_atoms_2); for (int i1=0; i1x, - res_selection_1[i1]->y, - res_selection_1[i1]->z); + clipper::Coord_orth a1(res_selection_1[i1]->x(), + res_selection_1[i1]->y(), + res_selection_1[i1]->z()); for (int i2=0; i2x, - res_selection_2[i2]->y, - res_selection_2[i2]->z); + clipper::Coord_orth a2(res_selection_2[i2]->x(), + res_selection_2[i2]->y(), + res_selection_2[i2]->z()); d = (a1-a2).lengthsq(); if (d < critical_dist*critical_dist) { close.push_back(coot::glycosidic_distance(res_selection_1[i1], @@ -540,8 +540,8 @@ coot::protein_geometry::find_glycosidic_linkage_type_by_distance(mmdb::Residue * float smallest_link_dist = 99999.9; for (unsigned int i=0; iname); - std::string name_2(close[i].at2->name); + std::string name_1(close[i].at1->GetAtomName()); + std::string name_2(close[i].at2->GetAtomName()); // First test the NAG-ASN link (that order - as per dictionary) diff --git a/geometry/main-chain.cc b/geometry/main-chain.cc index 0960eb8cbd..e3e93c1574 100644 --- a/geometry/main-chain.cc +++ b/geometry/main-chain.cc @@ -32,7 +32,7 @@ bool coot::is_main_chain_p(mmdb::Atom *at) { - std::string mol_atom_name(at->name); + std::string mol_atom_name(at->GetAtomName()); if (mol_atom_name == " N " || mol_atom_name == " C " || mol_atom_name == " CA " || @@ -50,7 +50,7 @@ coot::is_main_chain_p(mmdb::Atom *at) { } // Perhaps N-terminal H atom? - mmdb::Residue *res = at->residue; + mmdb::Residue *res = at->GetResidue(); if (res) { if (res->isNTerminus()) { if (mol_atom_name == " H1 ") return true; @@ -66,7 +66,7 @@ coot::is_main_chain_p(mmdb::Atom *at) { bool coot::is_main_chain_or_cb_p(mmdb::Atom *at) { - std::string mol_atom_name(at->name); + std::string mol_atom_name(at->GetAtomName()); return is_main_chain_or_cb_p(mol_atom_name); } @@ -109,7 +109,7 @@ coot::is_main_chain_or_cb_p(const std::string &mol_atom_name) { // return 0 or 1 bool coot::is_hydrogen_p(mmdb::Atom *at) { - std::string mol_atom_ele(at->element); + std::string mol_atom_ele(at->GetElementName()); if (mol_atom_ele == " H" || mol_atom_ele == " D") { return 1; diff --git a/geometry/mol-utils.cc b/geometry/mol-utils.cc index 41bd110ccc..d691595729 100644 --- a/geometry/mol-utils.cc +++ b/geometry/mol-utils.cc @@ -38,13 +38,13 @@ coot::util::get_residue_alt_confs(mmdb::Residue *res) { for (int iat=0; iataltLoc) == v[i]) { + if (std::string(residue_atoms[iat]->altLoc()) == v[i]) { ifound = 1; break; } } if (! ifound) - v.push_back(std::string(residue_atoms[iat]->altLoc)); + v.push_back(std::string(residue_atoms[iat]->altLoc())); } return v; } diff --git a/geometry/protein-geometry.cc b/geometry/protein-geometry.cc index 287aa9961a..df8c32962a 100644 --- a/geometry/protein-geometry.cc +++ b/geometry/protein-geometry.cc @@ -1468,8 +1468,8 @@ coot::protein_geometry::atoms_match_dictionary(mmdb::Residue *residue_p, if (debug) { std::cout << "=== atoms_match_dictionary() with these residue atom names ======= " << std::endl; for (int i=0; iname << ": and ele " - << residue_atoms[i]->element << std::endl; + std::cout << i << " :" << residue_atoms[i]->GetAtomName() << ": and ele " + << residue_atoms[i]->GetElementName() << std::endl; } std::cout << "=== atoms_match_dictionary() with these residue atom names ======= " << std::endl; for (unsigned int irat=0; iratisTer()) { - std::string residue_atom_name(residue_atoms[i]->name); - std::string ele(residue_atoms[i]->element); + std::string residue_atom_name(residue_atoms[i]->GetAtomName()); + std::string ele(residue_atoms[i]->GetElementName()); bool found = 0; // PDBv3 FIXME @@ -1589,17 +1589,17 @@ coot::protein_geometry::atoms_match_dictionary_bond_distance_check(mmdb::Residue for (unsigned int ibond=0; ibondname); + std::string atom_name_1(at_1->GetAtomName()); if (restraints.bond_restraint[ibond].atom_id_1_4c() == atom_name_1) { for (int jat=iat+1; jatname); + std::string atom_name_2(at_2->GetAtomName()); if (restraints.bond_restraint[ibond].atom_id_2_4c() == atom_name_2) { - std::string alt_conf_1(at_1->altLoc); - std::string alt_conf_2(at_2->altLoc); + std::string alt_conf_1(at_1->altLoc()); + std::string alt_conf_2(at_2->altLoc()); if (alt_conf_1 == alt_conf_2) { - clipper::Coord_orth pt1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth pt2(at_2->x, at_2->y, at_2->z); + clipper::Coord_orth pt1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth pt2(at_2->x(), at_2->y(), at_2->z()); double d = (pt1-pt2).lengthsq(); if (d > 10) { status = false; @@ -2525,8 +2525,8 @@ coot::protein_geometry::get_residue(const std::string &comp_id, int imol_enc, for (int iat=0; iatisTer()) { - std::cout << "debug:: in get_residue(): atom " << iat << " " << at-> name - << " at " << at->x << " " << at->y << " " << at->z << std::endl; + std::cout << "debug:: in get_residue(): atom " << iat << " " << at-> GetAtomName() + << " at " << at->x() << " " << at->y() << " " << at->z() << std::endl; } } }; @@ -2587,8 +2587,8 @@ coot::protein_geometry::mol_from_dictionary(const std::string &three_letter_code for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - std::cout << "pg::mol_from_dictionary(): atom " << iat << " " << at->name - << " at " << at->x << " " << at->y << " " << at->z + std::cout << "pg::mol_from_dictionary(): atom " << iat << " " << at->GetAtomName() + << " at " << at->x() << " " << at->y() << " " << at->z() << std::endl; } } diff --git a/geometry/residue-and-atom-specs.cc b/geometry/residue-and-atom-specs.cc index 0a29c09419..d3a7b8da6e 100644 --- a/geometry/residue-and-atom-specs.cc +++ b/geometry/residue-and-atom-specs.cc @@ -261,7 +261,7 @@ coot::atom_spec_t::get_atom(mmdb::Manager *mol) const { mmdb::Atom *this_at = residue_p->GetAtom(iat); if (! this_at->isTer()) { std::string this_atom_name(this_at->GetAtomName()); - std::string this_alt_loc = (this_at->altLoc); + std::string this_alt_loc = (this_at->altLoc()); if (this_atom_name == this->atom_name) { if (this_alt_loc == this->alt_conf) { at = this_at; @@ -288,11 +288,11 @@ coot::atom_spec_t::get_atom(mmdb::Manager *mol) const { bool coot::atom_spec_t::matches_spec(mmdb::Atom *atom) const { - if (atom_name == std::string(atom->name)) { + if (atom_name == std::string(atom->GetAtomName())) { - if (alt_conf == std::string(atom->altLoc)) { + if (alt_conf == std::string(atom->altLoc())) { - mmdb::Residue *residue_p = atom->residue; + mmdb::Residue *residue_p = atom->GetResidue(); if (residue_p) { @@ -336,7 +336,7 @@ coot::atom_spec_t::matches_spec(mmdb::Atom *atom) const { // std::cout << atom_name << "an atom name mismatch :" << atom->name << ":" << std::endl; return 0; } - std::cout << atom_name << " should not happen (matches_spec()) " << atom->name << ":" << std::endl; + std::cout << atom_name << " should not happen (matches_spec()) " << atom->GetAtomName() << ":" << std::endl; return 0; } diff --git a/geometry/residue-and-atom-specs.hh b/geometry/residue-and-atom-specs.hh index edcab040a0..c324cd9673 100644 --- a/geometry/residue-and-atom-specs.hh +++ b/geometry/residue-and-atom-specs.hh @@ -66,8 +66,8 @@ namespace coot { res_no = at->GetSeqNum(); ins_code = at->GetInsCode(); model_number = at->GetModelNum(); - atom_name = at->name; - alt_conf = at->altLoc; + atom_name = at->GetAtomName(); + alt_conf = at->altLoc(); } else { chain_id = "unset"; res_no = mmdb::MinInt4; @@ -83,8 +83,8 @@ namespace coot { chain_id = at->GetChainID(); res_no = at->GetSeqNum(); ins_code = at->GetInsCode(); - atom_name = at->name; - alt_conf = at->altLoc; + atom_name = at->GetAtomName(); + alt_conf = at->altLoc(); string_user_data = user_data_string; float_user_data = -1; int_user_data = -1; diff --git a/high-res/high-res.cc b/high-res/high-res.cc index 24120f2d10..1bc0e06b71 100644 --- a/high-res/high-res.cc +++ b/high-res/high-res.cc @@ -120,7 +120,7 @@ coot::high_res::get_middle_pos(const coot::minimol::molecule &minimol_mol) const } if (most_contacts >= 0) { mmdb::Atom *at = asc.atom_selection[most_contacts_index]; - r.first = clipper::Coord_orth(at->x, at->y, at->z); + r.first = clipper::Coord_orth(at->x(), at->y(), at->z()); } delete [] pscontact; std::cout << "INFO:: get_middle_pos: returns " << r.first.format() << " with " @@ -304,9 +304,9 @@ coot::high_res::make_trees() { std::vector coords; for (int iat=0; iatx, - asc.atom_selection[iat]->y, - asc.atom_selection[iat]->z)); + coords.push_back(clipper::Coord_orth(asc.atom_selection[iat]->x(), + asc.atom_selection[iat]->y(), + asc.atom_selection[iat]->z())); // std::cout << "There are " << contact_indices.size() // << " atoms "<< std::endl; @@ -395,7 +395,7 @@ coot::high_res::buccafilter_neighbours() { ierr = asc.atom_selection[iat]->GetUDData(uddhandle, ic); if (ierr == mmdb::UDDATA_Ok) { if (ic == -1) { - char *at_name = asc.atom_selection[iat]->name; + char *at_name = asc.atom_selection[iat]->GetAtomName(); std::string atom_name(at_name); mark_neighbours(iat, igroup, at_name, neighbours, asc.atom_selection, uddhandle); @@ -643,7 +643,7 @@ coot::high_res::mark_neighbours(int iatom, int igroup, int ig; atom_selection[iatom]->GetUDData(uddhandle, ig); if (ig == -1) { - std::string this_atom_name = atom_selection[iatom]->name; + std::string this_atom_name = atom_selection[iatom]->GetAtomName(); if (this_atom_name == atom_name) { atom_selection[iatom]->PutUDData(uddhandle, igroup); std::vector n = neighbours[iatom]; @@ -684,7 +684,7 @@ coot::high_res::filter_on_groups(const std::vector > &groups, int n_grp_ats = groups[igroup].size(); for (int iat=0; iatx, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); sum += pt; } double frac = 1.0/double(n_grp_ats); @@ -694,7 +694,7 @@ coot::high_res::filter_on_groups(const std::vector > &groups, int n_group_within_lim = 0; for (int iat=0; iatx, at->y, at->z); + clipper::Coord_orth pt(at->x(), at->y(), at->z()); // double d = clipper::Coord_orth::length(mean_pt, pt); // if (d < dist_crit) { n_group_within_lim++; @@ -705,9 +705,9 @@ coot::high_res::filter_on_groups(const std::vector > &groups, for (unsigned int iat=0; iatx << " " - << atom_selection[groups[igroup][iat]]->y << " " - << atom_selection[groups[igroup][iat]]->z << ")" << std::endl; + << atom_selection[groups[igroup][iat]]->x() << " " + << atom_selection[groups[igroup][iat]]->y() << " " + << atom_selection[groups[igroup][iat]]->z() << ")" << std::endl; } } @@ -717,8 +717,8 @@ coot::high_res::filter_on_groups(const std::vector > &groups, new_sum.y()*frac, new_sum.z()*frac); mmdb::Atom *speced_at = atom_selection[groups[igroup][0]]; - std::string atom_name(speced_at->name); - std::string atom_element(speced_at->element); + std::string atom_name(speced_at->GetAtomName()); + std::string atom_element(speced_at->GetElementName()); int resno = speced_at->GetSeqNum(); std::string chain_id(speced_at->GetChainID()); int ifrag = m.fragment_for_chain(chain_id); diff --git a/high-res/sequence-assignment.cc b/high-res/sequence-assignment.cc index 6f4fcde767..e5302e77c4 100644 --- a/high-res/sequence-assignment.cc +++ b/high-res/sequence-assignment.cc @@ -627,13 +627,13 @@ coot::sequence_assignment::side_chain_score_t::move_std_res_to_this_res_pos(cons std_residue->GetAtomTable(residue_atoms, nResidueAtoms); for (int iat=0; iatx, - residue_atoms[iat]->y, - residue_atoms[iat]->z); + clipper::Coord_orth co(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); clipper::Coord_orth rotted = co.transform(rtop); - residue_atoms[iat]->x = rotted.x(); - residue_atoms[iat]->y = rotted.y(); - residue_atoms[iat]->z = rotted.z(); + residue_atoms[iat]->x() = rotted.x(); + residue_atoms[iat]->y() = rotted.y(); + residue_atoms[iat]->z() = rotted.z(); } } @@ -716,9 +716,9 @@ coot::sequence_assignment::side_chain_score_t::find_unassigned_regions(float pr_ int start_resno = -1; // unset for (int ires=0; iresGetResidue(ires); - int this_resno = residue_p->seqNum; + int this_resno = residue_p->GetSeqNum(); // - std::string restype = residue_p->name; + std::string restype = residue_p->GetResName(); // istate = residue_p->GetUDData(udd_assigned_handle, iassigned); if (istate == mmdb::UDDATA_Ok) { @@ -740,7 +740,7 @@ coot::sequence_assignment::side_chain_score_t::find_unassigned_regions(float pr_ if (previous_residue) { v.push_back(coot::high_res_residue_range_t(chain_id, start_resno, - previous_residue->seqNum)); + previous_residue->GetSeqNum())); in_ala_range_flag = 0; } } @@ -758,7 +758,7 @@ coot::sequence_assignment::side_chain_score_t::find_unassigned_regions(float pr_ if (previous_residue) v.push_back(coot::high_res_residue_range_t(chain_id, start_resno, - previous_residue->seqNum)); + previous_residue->GetSeqNum())); } } } @@ -806,7 +806,7 @@ coot::sequence_assignment::side_chain_score_t::mark_unassigned_residues() { residue_p = chain_p->GetResidue(ires); // - std::string restype = residue_p->name; + std::string restype = residue_p->GetResName(); if (restype == "ALA") consecutive_ala_count++; else diff --git a/ideal/add-linked-cho.cc b/ideal/add-linked-cho.cc index 4940c04b1d..dfe3701861 100644 --- a/ideal/add-linked-cho.cc +++ b/ideal/add-linked-cho.cc @@ -362,11 +362,11 @@ coot::cho::next_residue_number_in_chain(mmdb::Chain *w, if (nres > 0) { for (int ires=nres-1; ires>=0; ires--) { residue_p = w->GetResidue(ires); - if (residue_p->seqNum > max_res_no) { - max_res_no = residue_p->seqNum; + if (residue_p->GetSeqNum() > max_res_no) { + max_res_no = residue_p->GetSeqNum(); bool is_het_residue_flag = is_het_residue(residue_p); if (is_het_residue_flag) { - p = std::pair(1, residue_p->seqNum+1); + p = std::pair(1, residue_p->GetSeqNum()+1); } else { if (new_res_no_by_hundreds) { if (max_res_no < 9999) { @@ -388,7 +388,7 @@ coot::cho::next_residue_number_in_chain(mmdb::Chain *w, while (! is_clear) { is_clear = true; for (int iser=0; iserGetResidue(iser)->seqNum; + int resno_res = w->GetResidue(iser)->GetSeqNum(); if (resno_res >= test_resno_start) { if (resno_res <= (test_resno_start+10)) { is_clear = false; @@ -446,7 +446,7 @@ coot::cho::copy_and_add_residue_to_chain(mmdb::Manager *mol, int new_res_resno = 9999; if (res_info.first) new_res_resno = res_info.second; - residue_copy->seqNum = new_res_resno; // try changing the seqNum before AddResidue(). + residue_copy->GetSeqNum() = new_res_resno; // try changing the seqNum before AddResidue(). this_model_chain->AddResidue(residue_copy); res_copied = residue_copy; } @@ -492,12 +492,12 @@ coot::cho::asn_hydrogen_position_swap(std::vectorx = co22.x(); - at_hd21->y = co22.y(); - at_hd21->z = co22.z(); - at_hd22->x = co21.x(); // this atom will be deleted. - at_hd22->y = co21.y(); - at_hd22->z = co21.z(); + at_hd21->x() = co22.x(); + at_hd21->y() = co22.y(); + at_hd21->z() = co22.z(); + at_hd22->x() = co21.x(); // this atom will be deleted. + at_hd22->y() = co21.y(); + at_hd22->z() = co21.z(); } } } @@ -542,14 +542,14 @@ coot::cho::make_link(mmdb::Manager *mol, const coot::atom_spec_t &spec_1, mmdb::Link *link = new mmdb::Link; // sym ids default to 1555 1555 strncpy(link->atName1, at_1->GetAtomName(), 20); - strncpy(link->aloc1, at_1->altLoc, 20); + strncpy(link->aloc1, at_1->altLoc(), 20); strncpy(link->resName1, at_1->GetResName(), 19); strncpy(link->chainID1, at_1->GetChainID(), 9); strncpy(link->insCode1, at_1->GetInsCode(), 9); link->seqNum1 = at_1->GetSeqNum(); strncpy(link->atName2, at_2->GetAtomName(), 20); - strncpy(link->aloc2, at_2->altLoc, 20); + strncpy(link->aloc2, at_2->altLoc(), 20); strncpy(link->resName2, at_2->GetResName(), 19); strncpy(link->chainID2, at_2->GetChainID(), 9); strncpy(link->insCode2, at_2->GetInsCode(), 9); @@ -562,8 +562,8 @@ coot::cho::make_link(mmdb::Manager *mol, const coot::atom_spec_t &spec_1, // are defined in the dictionary? // std::vector > residues(2); - residues[0] = std::pair (0, at_1->residue); - residues[1] = std::pair (0, at_2->residue); + residues[0] = std::pair (0, at_1->GetResidue()); + residues[1] = std::pair (0, at_2->GetResidue()); std::vector dummy_fixed_atom_specs; // convert to restraints_container_t interface @@ -671,9 +671,9 @@ coot::cho::replace_coords(mmdb::Manager *fragment_mol, mmdb::Manager *mol) { atom_spec_t spec(at); mmdb::Atom *at_mol = util::get_atom(spec, mol); if (at_mol) { - at_mol->x = at->x; - at_mol->y = at->y; - at_mol->z = at->z; + at_mol->x() = at->x(); + at_mol->y() = at->y(); + at_mol->z() = at->z(); } } } @@ -729,9 +729,9 @@ coot::cho::add_linked_residue(atom_selection_container_t *asc, if (icount < 10) { std::cout << "atom: " << icount << " " << at->GetChainID() << " " - << at->residue->GetSeqNum() << " " + << at->GetResidue()->GetSeqNum() << " " << at->GetAtomName() << " " - << at->x << " " << at->y << " " << at->z << " " + << at->x() << " " << at->y() << " " << at->z() << " " << std::endl; } else { break; diff --git a/ideal/chirals.cc b/ideal/chirals.cc index ff6fbe56db..5cb6499d8b 100644 --- a/ideal/chirals.cc +++ b/ideal/chirals.cc @@ -60,19 +60,19 @@ coot::is_inverted_chiral_atom_p(const coot::dict_chiral_restraint_t &chiral_rest int i_no_res_atoms = res->GetNumberOfAtoms(); for (int iat1=0; iat1GetAtom(iat1)->name); + std::string pdb_atom_name1(res->GetAtom(iat1)->GetAtomName()); if (pdb_atom_name1 == chiral_restraint.atom_id_1_4c()) { for (int iat2=0; iat2GetAtom(iat2)->name); + std::string pdb_atom_name2(res->GetAtom(iat2)->GetAtomName()); if (pdb_atom_name2 == chiral_restraint.atom_id_2_4c()) { for (int iat3=0; iat3GetAtom(iat3)->name); + std::string pdb_atom_name3(res->GetAtom(iat3)->GetAtomName()); if (pdb_atom_name3 == chiral_restraint.atom_id_3_4c()) { for (int iatc=0; iatcGetAtom(iatc)->name); + std::string pdb_atom_namec(res->GetAtom(iatc)->GetAtomName()); if (pdb_atom_namec == chiral_restraint.atom_id_c_4c()) { // Now, do they have corresponding @@ -84,10 +84,10 @@ coot::is_inverted_chiral_atom_p(const coot::dict_chiral_restraint_t &chiral_rest // CA CB OG1,A CG2,A (2) // but not: CA CB OG1,A CG2,B (3) - std::string chiral_alt_conf(res->GetAtom(iatc)->altLoc); - std::string altLoc1(res->GetAtom(iat1)->altLoc); - std::string altLoc2(res->GetAtom(iat2)->altLoc); - std::string altLoc3(res->GetAtom(iat3)->altLoc); + std::string chiral_alt_conf(res->GetAtom(iatc)->altLoc()); + std::string altLoc1(res->GetAtom(iat1)->altLoc()); + std::string altLoc2(res->GetAtom(iat2)->altLoc()); + std::string altLoc3(res->GetAtom(iat3)->altLoc()); short int matching_altlocs = 0; // These should catch most cases, @@ -116,18 +116,18 @@ coot::is_inverted_chiral_atom_p(const coot::dict_chiral_restraint_t &chiral_rest if (matching_altlocs) { - clipper::Coord_orth centre(res->GetAtom(iatc)->x, - res->GetAtom(iatc)->y, - res->GetAtom(iatc)->z); - clipper::Coord_orth a1(res->GetAtom(iat1)->x, - res->GetAtom(iat1)->y, - res->GetAtom(iat1)->z); - clipper::Coord_orth a2(res->GetAtom(iat2)->x, - res->GetAtom(iat2)->y, - res->GetAtom(iat2)->z); - clipper::Coord_orth a3(res->GetAtom(iat3)->x, - res->GetAtom(iat3)->y, - res->GetAtom(iat3)->z); + clipper::Coord_orth centre(res->GetAtom(iatc)->x(), + res->GetAtom(iatc)->y(), + res->GetAtom(iatc)->z()); + clipper::Coord_orth a1(res->GetAtom(iat1)->x(), + res->GetAtom(iat1)->y(), + res->GetAtom(iat1)->z()); + clipper::Coord_orth a2(res->GetAtom(iat2)->x(), + res->GetAtom(iat2)->y(), + res->GetAtom(iat2)->z()); + clipper::Coord_orth a3(res->GetAtom(iat3)->x(), + res->GetAtom(iat3)->y(), + res->GetAtom(iat3)->z()); clipper::Coord_orth a = a1 - centre; clipper::Coord_orth b = a2 - centre; @@ -137,8 +137,8 @@ coot::is_inverted_chiral_atom_p(const coot::dict_chiral_restraint_t &chiral_rest chiral_atom = atom_spec_t(res->GetChainID(), res->GetSeqNum(), res->GetInsCode(), - res->GetAtom(iatc)->name, - res->GetAtom(iatc)->altLoc); + res->GetAtom(iatc)->GetAtomName(), + res->GetAtom(iatc)->altLoc()); if (cv*chiral_restraint.volume_sign < 0) { // std::cout << "DEBUG:: " << res->name << " " @@ -209,7 +209,7 @@ coot::inverted_chiral_volumes(int imol, residue_p = chain_p->GetResidue(ires); int n_atoms = residue_p->GetNumberOfAtoms(); if (n_atoms > 3) { - std::string residue_type(residue_p->name); + std::string residue_type(residue_p->GetResName()); if (residue_type == "UNK") residue_type = "ALA"; if (! geom_p->have_dictionary_for_residue_type(residue_type, @@ -229,7 +229,7 @@ coot::inverted_chiral_volumes(int imol, unknown_types_vec.push_back(residue_type); } else { std::vector chiral_restraints = - geom_p->get_monomer_chiral_volumes(std::string(residue_p->name), imol); + geom_p->get_monomer_chiral_volumes(std::string(residue_p->GetResName()), imol); coot::dict_chiral_restraint_t chiral_restraint; for (unsigned int irestr=0; irestrGetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname; + std::string at_name = at->GetAtomName(); if (at_name == " C ") { // PDBv3 fixme v[0] = at; break; @@ -89,7 +89,7 @@ coot::crankshaft_set::crankshaft_set(mmdb::Residue *res_0, residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname; + std::string at_name = at->GetAtomName(); if (at_name == " N ") { // PDBv3 fixme v[1] = at; } @@ -109,7 +109,7 @@ coot::crankshaft_set::crankshaft_set(mmdb::Residue *res_0, residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname; + std::string at_name = at->GetAtomName(); if (at_name == " N ") { // PDBv3 fixme v[4] = at; } @@ -129,7 +129,7 @@ coot::crankshaft_set::crankshaft_set(mmdb::Residue *res_0, residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname; + std::string at_name = at->GetAtomName(); if (at_name == " N ") { // PDBv3 fixme v[7] = at; } @@ -250,8 +250,8 @@ coot::nmer_crankshaft_set::residues() const { for (std::size_t i=0; iresidue; - mmdb::Residue *r_2 = at_2->residue; + mmdb::Residue *r_1 = at_1->GetResidue(); + mmdb::Residue *r_2 = at_2->GetResidue(); if (std::find(v.begin(), v.end(), r_1) == v.end()) v.push_back(r_1); if (std::find(v.begin(), v.end(), r_2) == v.end()) v.push_back(r_2); } @@ -327,9 +327,9 @@ coot::crankshaft_set::move_the_atoms(float ang) { if (at) { clipper::Coord_orth at_pos = co(v[indices[i]]); clipper::Coord_orth at_pos_new = util::rotate_around_vector(dir, at_pos, p_ca_1, ang); - at->x = at_pos_new.x(); - at->y = at_pos_new.y(); - at->z = at_pos_new.z(); + at->x() = at_pos_new.x(); + at->y() = at_pos_new.y(); + at->z() = at_pos_new.z(); } } } @@ -1186,7 +1186,7 @@ coot::crankshaft::get_atom(mmdb::Residue *res_1, const std::string &atom_name_in res_1->GetAtomTable(residue_atoms_1, n_residue_atoms_1); for (int iat=0; iatname; + std::string atom_name = at->GetAtomName(); if (atom_name == atom_name_in) { r = at; break; diff --git a/ideal/distortion.cc b/ideal/distortion.cc index 1f0d9eb2ff..806f18669e 100644 --- a/ideal/distortion.cc +++ b/ideal/distortion.cc @@ -477,8 +477,8 @@ coot::geometry_distortion_info_container_t::distortion() const { mmdb::Atom *at_1 = atom[rest.atom_index_1]; mmdb::Atom *at_2 = atom[rest.atom_index_2]; if (at_1 && at_2) { - clipper::Coord_orth p1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth p2(at_2->x, at_2->y, at_2->z); + clipper::Coord_orth p1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth p2(at_2->x(), at_2->y(), at_2->z()); double d = sqrt((p2-p1).lengthsq()); double distortion = d - rest.target_value; double pen_score = distortion*distortion/(rest.sigma*rest.sigma); @@ -494,9 +494,9 @@ coot::geometry_distortion_info_container_t::distortion() const { mmdb::Atom *at_2 = atom[rest.atom_index_2]; mmdb::Atom *at_3 = atom[rest.atom_index_3]; if (at_1 && at_2 && at_3) { - clipper::Coord_orth p1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth p2(at_2->x, at_2->y, at_2->z); - clipper::Coord_orth p3(at_3->x, at_3->y, at_3->z); + clipper::Coord_orth p1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth p2(at_2->x(), at_2->y(), at_2->z()); + clipper::Coord_orth p3(at_3->x(), at_3->y(), at_3->z()); double angle_rad = clipper::Coord_orth::angle(p1, p2, p3); double angle = clipper::Util::rad2d(angle_rad); double distortion = angle - rest.target_value; @@ -511,10 +511,10 @@ coot::geometry_distortion_info_container_t::distortion() const { mmdb::Atom *at_3 = atom[rest.atom_index_3]; mmdb::Atom *at_4 = atom[rest.atom_index_4]; if (at_1 && at_2 && at_3 && at_4) { - clipper::Coord_orth p1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth p2(at_2->x, at_2->y, at_2->z); - clipper::Coord_orth p3(at_3->x, at_3->y, at_3->z); - clipper::Coord_orth p4(at_4->x, at_4->y, at_4->z); + clipper::Coord_orth p1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth p2(at_2->x(), at_2->y(), at_2->z()); + clipper::Coord_orth p3(at_3->x(), at_3->y(), at_3->z()); + clipper::Coord_orth p4(at_4->x(), at_4->y(), at_4->z()); double torsion_rad = clipper::Coord_orth::torsion(p1, p2, p3, p4); double torsion = clipper::Util::rad2d(torsion_rad); double distortion = rest.torsion_distortion(torsion); @@ -529,10 +529,10 @@ coot::geometry_distortion_info_container_t::distortion() const { mmdb::Atom *at_3 = atom[rest.atom_index_3]; mmdb::Atom *at_4 = atom[rest.atom_index_4]; if (at_1 && at_2 && at_3 && at_4) { - clipper::Coord_orth p1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth p2(at_2->x, at_2->y, at_2->z); - clipper::Coord_orth p3(at_3->x, at_3->y, at_3->z); - clipper::Coord_orth p4(at_4->x, at_4->y, at_4->z); + clipper::Coord_orth p1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth p2(at_2->x(), at_2->y(), at_2->z()); + clipper::Coord_orth p3(at_3->x(), at_3->y(), at_3->z()); + clipper::Coord_orth p4(at_4->x(), at_4->y(), at_4->z()); double torsion_rad = clipper::Coord_orth::torsion(p1, p2, p3, p4); double torsion = clipper::Util::rad2d(torsion_rad); double pen_score = rest.torsion_distortion(torsion); @@ -853,13 +853,13 @@ coot::restraints_container_t::omega_trans_distortions(const coot::protein_geomet if (i_no_res_atoms > 0) { for (int iresatom=0; iresatomname); + std::string atom_name(at->GetAtomName()); if (atom_name == " CA ") { - ca_first = clipper::Coord_orth(at->x, at->y, at->z); + ca_first = clipper::Coord_orth(at->x(), at->y(), at->z()); got_ca_first = 1; } if (atom_name == " C ") { - c_first = clipper::Coord_orth(at->x, at->y, at->z); + c_first = clipper::Coord_orth(at->x(), at->y(), at->z()); got_c_first = 1; } } @@ -868,13 +868,13 @@ coot::restraints_container_t::omega_trans_distortions(const coot::protein_geomet if (i_no_res_atoms > 0) { for (int iresatom=0; iresatomname); + std::string atom_name(at->GetAtomName()); if (atom_name == " CA ") { - ca_next = clipper::Coord_orth(at->x, at->y, at->z); + ca_next = clipper::Coord_orth(at->x(), at->y(), at->z()); got_ca_next = 1; } if (atom_name == " N ") { - n_next = clipper::Coord_orth(at->x, at->y, at->z); + n_next = clipper::Coord_orth(at->x(), at->y(), at->z()); got_n_next = 1; } } @@ -890,7 +890,7 @@ coot::restraints_container_t::omega_trans_distortions(const coot::protein_geomet info += " "; info += coot::util::int_to_string(second->GetSeqNum()); info += " "; - info += second->name; + info += second->GetResName(); info += " Omega: "; info += coot::util::float_to_string(torsion); double distortion = fabs(180.0 - torsion); diff --git a/ideal/extra-restraints-kk.cc b/ideal/extra-restraints-kk.cc index 3fbe5eaab8..2157cc2cb5 100644 --- a/ideal/extra-restraints-kk.cc +++ b/ideal/extra-restraints-kk.cc @@ -72,9 +72,9 @@ coot::restraints_container_t::add_extra_start_pos_restraints(const extra_restrai r_1->GetAtomTable(residue_atoms_1, n_residue_atoms_1); for (int iat=0; iatname); + std::string atom_name_1(residue_atoms_1[iat]->GetAtomName()); if (atom_name_1 == extra_restraints.start_pos_restraints[i].atom_1.atom_name) { - std::string alt_loc_1(residue_atoms_1[iat]->altLoc); + std::string alt_loc_1(residue_atoms_1[iat]->altLoc()); if (alt_loc_1 == extra_restraints.start_pos_restraints[i].atom_1.alt_conf) { at_1 = residue_atoms_1[iat]; break; diff --git a/ideal/extra-restraints.cc b/ideal/extra-restraints.cc index 889a507631..0a3083913c 100644 --- a/ideal/extra-restraints.cc +++ b/ideal/extra-restraints.cc @@ -1235,9 +1235,9 @@ coot::restraints_container_t::add_extra_target_position_restraints(const extra_r int n_residue_atoms; residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); + std::string atom_name(residue_atoms[iat]->GetAtomName()); if (atom_name == extra_restraints.target_position_restraints[i].atom_spec.atom_name) { - std::string alt_loc(residue_atoms[iat]->altLoc); + std::string alt_loc(residue_atoms[iat]->altLoc()); if (alt_loc == extra_restraints.target_position_restraints[i].atom_spec.alt_conf) { at = residue_atoms[iat]; break; @@ -1410,9 +1410,9 @@ coot::restraints_container_t::add_extra_bond_restraints(const extra_restraints_t r_2->GetAtomTable(residue_atoms_2, n_residue_atoms_2); for (int iat=0; iatname); + std::string atom_name_1(residue_atoms_1[iat]->GetAtomName()); if (atom_name_1 == ebr.atom_1.atom_name) { - std::string alt_loc_1(residue_atoms_1[iat]->altLoc); + std::string alt_loc_1(residue_atoms_1[iat]->altLoc()); if (alt_loc_1 == ebr.atom_1.alt_conf) { at_1 = residue_atoms_1[iat]; break; @@ -1420,9 +1420,9 @@ coot::restraints_container_t::add_extra_bond_restraints(const extra_restraints_t } } for (int iat=0; iatname); + std::string atom_name_2(residue_atoms_2[iat]->GetAtomName()); if (atom_name_2 == ebr.atom_2.atom_name) { - std::string alt_loc_2(residue_atoms_2[iat]->altLoc); + std::string alt_loc_2(residue_atoms_2[iat]->altLoc()); if (alt_loc_2 == ebr.atom_2.alt_conf) { at_2 = residue_atoms_2[iat]; break; @@ -1552,9 +1552,9 @@ coot::restraints_container_t::add_extra_geman_mcclure_restraints(const extra_res r_2->GetAtomTable(residue_atoms_2, n_residue_atoms_2); for (int iat=0; iatname); + std::string atom_name_1(residue_atoms_1[iat]->GetAtomName()); if (atom_name_1 == ebr.atom_1.atom_name) { - std::string alt_loc_1(residue_atoms_1[iat]->altLoc); + std::string alt_loc_1(residue_atoms_1[iat]->altLoc()); if (alt_loc_1 == ebr.atom_1.alt_conf) { at_1 = residue_atoms_1[iat]; break; @@ -1562,9 +1562,9 @@ coot::restraints_container_t::add_extra_geman_mcclure_restraints(const extra_res } } for (int iat=0; iatname); + std::string atom_name_2(residue_atoms_2[iat]->GetAtomName()); if (atom_name_2 == ebr.atom_2.atom_name) { - std::string alt_loc_2(residue_atoms_2[iat]->altLoc); + std::string alt_loc_2(residue_atoms_2[iat]->altLoc()); if (alt_loc_2 == ebr.atom_2.alt_conf) { at_2 = residue_atoms_2[iat]; break; @@ -1821,8 +1821,8 @@ coot::restraints_container_t::add_extra_parallel_plane_restraints(int imol, dri_1.second.atom_name_for_tree_4c(r.plane_1_atoms.atom_names[i_rest_at]); for (int iat=0; iatname); - std::string alt_conf(at->altLoc); + std::string atom_name(at->GetAtomName()); + std::string alt_conf(at->altLoc()); if (plane_atom_expanded_name == atom_name) { if (r.plane_1_atoms.alt_conf == alt_conf) { int idx = -1; @@ -1849,8 +1849,8 @@ coot::restraints_container_t::add_extra_parallel_plane_restraints(int imol, dri_2.second.atom_name_for_tree_4c(r.plane_2_atoms.atom_names[i_rest_at]); for (int iat=0; iatname); - std::string alt_conf(at->altLoc); + std::string atom_name(at->GetAtomName()); + std::string alt_conf(at->altLoc()); // std::cout << "testing :" << plane_atom_expanded_name << ": vs :" << atom_name << ":" << std::endl; if (plane_atom_expanded_name == atom_name) { if (r.plane_2_atoms.alt_conf == alt_conf) { @@ -2121,14 +2121,14 @@ coot::extra_restraints_t::position_point_map(mmdb::Manager *mol_running, int n_atoms_1 = residue_1_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - std::string atom_name_1(at_1_p->name); - std::string alt_conf_1(at_1_p->altLoc); + std::string atom_name_1(at_1_p->GetAtomName()); + std::string alt_conf_1(at_1_p->altLoc()); int n_atoms_2 = residue_2_p->GetNumberOfAtoms(); for (int jat=0; jatGetAtom(jat); - std::string atom_name_2(at_2_p->name); - std::string alt_conf_2(at_2_p->altLoc); + std::string atom_name_2(at_2_p->GetAtomName()); + std::string alt_conf_2(at_2_p->altLoc()); if (atom_name_2 == atom_name_1) { if (alt_conf_2 == alt_conf_1) { @@ -2199,9 +2199,9 @@ coot::extra_restraints_t::write_interpolated_models(mmdb::Manager *mol_running, const clipper::Coord_orth &pt_1 = it_1->second; const clipper::Coord_orth &pt_2 = it_2->second; clipper::Coord_orth pt(pt_1 + (pt_2 - pt_1) * frac); - at->x = pt.x(); - at->y = pt.y(); - at->z = pt.z(); + at->x() = pt.x(); + at->y() = pt.y(); + at->z() = pt.z(); } else { std::cout << "failed to find spec for it_2 " << spec << std::endl; } diff --git a/ideal/flanking.cc b/ideal/flanking.cc index e57a03a45d..4a7fb8057d 100644 --- a/ideal/flanking.cc +++ b/ideal/flanking.cc @@ -129,13 +129,13 @@ coot::restraints_container_t::add_fixed_atoms_from_flanking_residues(bool have_f for (int iat=0; iatresidue->GetSeqNum() == iselection_start_res) { + if (at->GetResidue()->GetSeqNum() == iselection_start_res) { // perhaps this should be a set - yes. fixed_atom_indices.insert(iat); } } if (have_flanking_residue_at_end) { - if (at->residue->GetSeqNum() == iselection_end_res) { + if (at->GetResidue()->GetSeqNum() == iselection_end_res) { fixed_atom_indices.insert(iat); } } diff --git a/ideal/gradients.cc b/ideal/gradients.cc index 739ffbb587..d54f5b9bf4 100644 --- a/ideal/gradients.cc +++ b/ideal/gradients.cc @@ -335,7 +335,7 @@ void coot::my_df_bonds(const gsl_vector *v, idx = 3*restraints->at(i).atom_index_1; std::cout << "BOND Fixed atom[0] " << restraints->get_atom((*restraints)[i].atom_index_1)->GetSeqNum() << " " - << restraints->get_atom((*restraints)[i].atom_index_1)->name << " " + << restraints->get_atom((*restraints)[i].atom_index_1)->GetAtomName() << " " << ", Not adding " << x_k_contrib << " " << y_k_contrib << " " << z_k_contrib << " to " << gsl_vector_get(df, idx) << " " @@ -356,7 +356,7 @@ void coot::my_df_bonds(const gsl_vector *v, idx = 3*restraints->at(i).atom_index_2; std::cout << "BOND Fixed atom[1] " << restraints->get_atom((*restraints)[i].atom_index_2)->GetSeqNum() << " " - << restraints->get_atom((*restraints)[i].atom_index_2)->name << " " + << restraints->get_atom((*restraints)[i].atom_index_2)->GetAtomName() << " " << ", Not adding " << x_k_contrib << " " << y_k_contrib << " " << z_k_contrib << " to " diff --git a/ideal/link-restraints.cc b/ideal/link-restraints.cc index be0e953574..496a7f8552 100644 --- a/ideal/link-restraints.cc +++ b/ideal/link-restraints.cc @@ -123,7 +123,7 @@ coot::restraints_container_t::bonded_residues_by_linear(int SelResHnd, // an insertion code, or simply a gap - and we don't want // to make a bond for a gap. // - if (abs(SelResidue[i]->index - SelResidue[i+1]->index) <= 1) { + if (abs(SelResidue[i]->GetIndex() - SelResidue[i+1]->GetIndex()) <= 1) { // link_type = find_link_type(SelResidue[i], SelResidue[i+1], geom); std::cout << "####################### find_link_type_compli() called from bonded_residues_by_linear()" << std::endl; @@ -247,8 +247,8 @@ coot::restraints_container_t::bonded_residues_from_res_vec(const coot::protein_g bool was_straight_forward_trans_link = false; int resno_1 = res_f->GetSeqNum(); int resno_2 = res_s->GetSeqNum(); - int ser_num_1 = res_f->index; - int ser_num_2 = res_s->index; + int ser_num_1 = res_f->GetIndex(); + int ser_num_2 = res_s->GetIndex(); if (resno_2 == (resno_1 + 1)) { if (ser_num_2 == (ser_num_1 + 1)) { std::string rn_1 = res_f->GetResName(); @@ -314,10 +314,10 @@ coot::restraints_container_t::add_link_bond(std::string link_type, std::cout << "INFO:: geom.link_size() is " << geom.link_size() << std::endl; std::cout << "first residue:\n"; for (int i=0; iname << " " << first_sel[i]->GetSeqNum() << "\n"; + std::cout << " " << first_sel[i]->GetAtomName() << " " << first_sel[i]->GetSeqNum() << "\n"; std::cout << "second residue:\n"; for (int i=0; iname << " " << second_sel[i]->GetSeqNum() << "\n"; + std::cout << " " << second_sel[i]->GetAtomName() << " " << second_sel[i]->GetSeqNum() << "\n"; } int nbond = 0; @@ -333,26 +333,26 @@ coot::restraints_container_t::add_link_bond(std::string link_type, std::cout << "bad things will now happen..." << std::endl; } for (int ifat=0; ifatname); + std::string pdb_atom_name_1(first_sel[ifat]->GetAtomName()); if (pdb_atom_name_1 == geom.link(i).link_bond_restraint[j].atom_id_1_4c()) { for (int isat=0; isatname); + std::string pdb_atom_name_2(second_sel[isat]->GetAtomName()); if (pdb_atom_name_2 == geom.link(i).link_bond_restraint[j].atom_id_2_4c()) { if (debug) std::cout << "DEBUG:: adding " << link_type << " bond for " - << first->seqNum - << " -> " << second->seqNum << " atoms " + << first->GetSeqNum() + << " -> " << second->GetSeqNum() << " atoms " << first_sel [ifat]->GetAtomName() << " to " << second_sel[isat]->GetAtomName() << std::endl; // Now, do the alt confs match? // - std::string alt_conf_1 = first_sel[ifat]->altLoc; - std::string alt_conf_2 = second_sel[isat]->altLoc; + std::string alt_conf_1 = first_sel[ifat]->altLoc(); + std::string alt_conf_2 = second_sel[isat]->altLoc(); if ((alt_conf_1 == alt_conf_2) || (alt_conf_1 == "") || (alt_conf_2 == "")) { // 20230110-PE are you here again? Check that udd_atom_index_handle @@ -470,15 +470,15 @@ coot::restraints_container_t::add_link_angle(std::string link_type, } for (int ifat=0; ifatname); + std::string pdb_atom_name_1(atom_1_sel[ifat]->GetAtomName()); if (pdb_atom_name_1 == geom.link(i).link_angle_restraint[j].atom_id_1_4c()) { for (int isat=0; isatname); + std::string pdb_atom_name_2(atom_2_sel[isat]->GetAtomName()); if (pdb_atom_name_2 == geom.link(i).link_angle_restraint[j].atom_id_2_4c()) { for (int itat=0; itatname); + std::string pdb_atom_name_3(atom_3_sel[itat]->GetAtomName()); if (pdb_atom_name_3 == geom.link(i).link_angle_restraint[j].atom_id_3_4c()) { @@ -502,9 +502,9 @@ coot::restraints_container_t::add_link_angle(std::string link_type, // atom_3_sel[itat]->residue->seqNum, // atom_3_sel[itat]->residue->GetChainID()); - std::string alt_conf_1 = atom_1_sel[ifat]->altLoc; - std::string alt_conf_2 = atom_2_sel[isat]->altLoc; - std::string alt_conf_3 = atom_3_sel[itat]->altLoc; + std::string alt_conf_1 = atom_1_sel[ifat]->altLoc(); + std::string alt_conf_2 = atom_2_sel[isat]->altLoc(); + std::string alt_conf_3 = atom_3_sel[itat]->altLoc(); // either they are all the same (including the ususal case of all "") // or at_1 and at_2 are the same and at_3 is blank @@ -809,45 +809,45 @@ coot::restraints_container_t::add_link_torsion_for_phi_psi(std::string link_type fixed_flag[3] = is_fixed_second; } for (int ifat=0; ifatname); + std::string pdb_atom_name_1(atom_1_sel[ifat]->GetAtomName()); if (pdb_atom_name_1 == geom.link(i).link_torsion_restraint[j].atom_id_1_4c()) { for (int isat=0; isatname); + std::string pdb_atom_name_2(atom_2_sel[isat]->GetAtomName()); if (pdb_atom_name_2 == geom.link(i).link_torsion_restraint[j].atom_id_2_4c()) { for (int itat=0; itatname); + std::string pdb_atom_name_3(atom_3_sel[itat]->GetAtomName()); if (pdb_atom_name_3 == geom.link(i).link_torsion_restraint[j].atom_id_3_4c()) { for (int iffat=0; iffatname); + std::string pdb_atom_name_4(atom_4_sel[iffat]->GetAtomName()); if (pdb_atom_name_4 == geom.link(i).link_torsion_restraint[j].atom_id_4_4c()) { - int index1 = get_asc_index(atom_1_sel[ifat]->name, - atom_1_sel[ifat]->altLoc, - atom_1_sel[ifat]->residue->seqNum, + int index1 = get_asc_index(atom_1_sel[ifat]->GetAtomName(), + atom_1_sel[ifat]->altLoc(), + atom_1_sel[ifat]->GetResidue()->GetSeqNum(), atom_1_sel[ifat]->GetInsCode(), atom_1_sel[ifat]->GetChainID()); - int index2 = get_asc_index(atom_2_sel[isat]->name, - atom_2_sel[isat]->altLoc, - atom_2_sel[isat]->residue->seqNum, + int index2 = get_asc_index(atom_2_sel[isat]->GetAtomName(), + atom_2_sel[isat]->altLoc(), + atom_2_sel[isat]->GetResidue()->GetSeqNum(), atom_2_sel[isat]->GetInsCode(), atom_2_sel[isat]->GetChainID()); - int index3 = get_asc_index(atom_3_sel[itat]->name, - atom_3_sel[itat]->altLoc, - atom_3_sel[itat]->residue->seqNum, + int index3 = get_asc_index(atom_3_sel[itat]->GetAtomName(), + atom_3_sel[itat]->altLoc(), + atom_3_sel[itat]->GetResidue()->GetSeqNum(), atom_3_sel[itat]->GetInsCode(), atom_3_sel[itat]->GetChainID()); - int index4 = get_asc_index(atom_4_sel[iffat]->name, - atom_4_sel[iffat]->altLoc, - atom_4_sel[iffat]->residue->seqNum, + int index4 = get_asc_index(atom_4_sel[iffat]->GetAtomName(), + atom_4_sel[iffat]->altLoc(), + atom_4_sel[iffat]->GetResidue()->GetSeqNum(), atom_4_sel[iffat]->GetInsCode(), - atom_4_sel[iffat]->residue->GetChainID()); + atom_4_sel[iffat]->GetResidue()->GetChainID()); // std::cout << "torsion restraint.... " << geom.link(i).link_torsion_restraint[j].id() // << " from atoms \n " @@ -1434,8 +1434,8 @@ coot::restraints_container_t::find_link_type(mmdb::Residue *first, // Should return TRANS, PTRANS (PRO-TRANS), CIS, PCIS, p, BETA1-2, BETA1-4 etc. std::string link_type(""); // unset - std::string residue_type_1 = first->name; - std::string residue_type_2 = second->name; + std::string residue_type_1 = first->GetResName(); + std::string residue_type_2 = second->GetResName(); if (residue_type_1 == "UNK") residue_type_1 = "ALA"; // hack for KDC. if (residue_type_2 == "UNK") residue_type_2 = "ALA"; @@ -1544,8 +1544,8 @@ coot::restraints_container_t::find_link_type_2022(mmdb::Residue *first_residue, auto get_consecutive = [] (mmdb::Residue *first_residue, mmdb::Residue *second_residue) { bool state = false; - int idx_1 = first_residue->index; - int idx_2 = second_residue->index; + int idx_1 = first_residue->GetIndex(); + int idx_2 = second_residue->GetIndex(); int d = idx_2 - idx_1; if (d <= 1) if (d >= -1) @@ -1564,7 +1564,7 @@ coot::restraints_container_t::find_link_type_2022(mmdb::Residue *first_residue, for (int iat=0; iatisTer()) { - std::string name(at->name); + std::string name(at->GetAtomName()); if (name == " SG ") { found = true; break; @@ -1579,7 +1579,7 @@ coot::restraints_container_t::find_link_type_2022(mmdb::Residue *first_residue, for (int iat=0; iatisTer()) { - std::string name(at->name); + std::string name(at->GetAtomName()); if (name == " SG ") { found = true; break; // micro-optimiziation! @@ -1607,10 +1607,10 @@ coot::restraints_container_t::find_link_type_2022(mmdb::Residue *first_residue, for (int iat=0; iatisTer()) { - std::string name(at->name); + std::string name(at->GetAtomName()); if (name == " C ") { found_1 = true; - pt_1 = clipper::Coord_orth(at->x, at->y, at->z); + pt_1 = clipper::Coord_orth(at->x(), at->y(), at->z()); } } } @@ -1620,10 +1620,10 @@ coot::restraints_container_t::find_link_type_2022(mmdb::Residue *first_residue, for (int iat=0; iatisTer()) { - std::string name(at->name); + std::string name(at->GetAtomName()); if (name == " O3'") { found_2 = true; - pt_2 = clipper::Coord_orth(at->x, at->y, at->z); + pt_2 = clipper::Coord_orth(at->x(), at->y(), at->z()); } } } @@ -1653,10 +1653,10 @@ coot::restraints_container_t::find_link_type_2022(mmdb::Residue *first_residue, for (int iat=0; iatisTer()) { - std::string name(at->name); + std::string name(at->GetAtomName()); if (name == " C1 ") { found_1 = true; - pt_1 = clipper::Coord_orth(at->x, at->y, at->z); + pt_1 = clipper::Coord_orth(at->x(), at->y(), at->z()); } } } @@ -1666,10 +1666,10 @@ coot::restraints_container_t::find_link_type_2022(mmdb::Residue *first_residue, for (int iat=0; iatisTer()) { - std::string name(at->name); + std::string name(at->GetAtomName()); if (name == " OG ") { found_2 = true; - pt_2 = clipper::Coord_orth(at->x, at->y, at->z); + pt_2 = clipper::Coord_orth(at->x(), at->y(), at->z()); } } } @@ -1716,10 +1716,10 @@ coot::restraints_container_t::find_link_type_2022(mmdb::Residue *first_residue, for (int iat=0; iatisTer()) { - std::string name(at->name); + std::string name(at->GetAtomName()); if (name == link_atom_1_name) { found_1 = true; - pt_1 = clipper::Coord_orth(at->x, at->y, at->z); + pt_1 = clipper::Coord_orth(at->x(), at->y(), at->z()); } } } @@ -1729,10 +1729,10 @@ coot::restraints_container_t::find_link_type_2022(mmdb::Residue *first_residue, for (int iat=0; iatisTer()) { - std::string name(at->name); + std::string name(at->GetAtomName()); if (name == link_atom_2_name) { found_2 = true; - pt_2 = clipper::Coord_orth(at->x, at->y, at->z); + pt_2 = clipper::Coord_orth(at->x(), at->y(), at->z()); } } } @@ -2043,8 +2043,8 @@ coot::restraints_container_t::general_link_find_close_link_inner(const std::vect mmdb::Atom *at_1 = r1->GetAtom(atom_id_1.c_str()); mmdb::Atom *at_2 = r2->GetAtom(atom_id_2.c_str()); if (at_1 && at_2) { - clipper::Coord_orth p1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth p2(at_2->x, at_2->y, at_2->z); + clipper::Coord_orth p1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth p2(at_2->x(), at_2->y(), at_2->z()); double d = clipper::Coord_orth::length(p1,p2); if (debug) std::cout << " dist check " << " link-bond-number: " @@ -2084,14 +2084,14 @@ coot::restraints_container_t::general_link_find_close_link_inner(const std::vect r1->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iGetResName() << " " - << i << " :" << residue_atoms[i]->name + << i << " :" << residue_atoms[i]->GetAtomName() << ":" << std::endl; } residue_atoms = 0; r2->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iGetResName() << " " - << i << " :" << residue_atoms[i]->name + << i << " :" << residue_atoms[i]->GetAtomName() << ":" << std::endl; } } @@ -2152,7 +2152,7 @@ int coot::restraints_container_t::add_link_plane(std::string link_type, // std::map > atom_indices_map; for (int iat=0; iataltLoc); + std::string alt_loc(first_sel[iat]->altLoc()); std::map >::const_iterator it = atom_indices_map.find(alt_loc); if (it == atom_indices_map.end()) { std::vector v; @@ -2160,7 +2160,7 @@ int coot::restraints_container_t::add_link_plane(std::string link_type, } } for (int iat=0; iataltLoc); + std::string alt_loc(second_sel[iat]->altLoc()); std::map >::const_iterator it = atom_indices_map.find(alt_loc); if (it == atom_indices_map.end()) { std::vector v; @@ -2192,14 +2192,14 @@ int coot::restraints_container_t::add_link_plane(std::string link_type, fixed_flags[irest_at] = is_fixed_second_res; } for (int iat=0; iatname); + std::string pdb_atom_name(atom_sel[iat]->GetAtomName()); if (geom.link(i).link_plane_restraint[ip].atom_id(irest_at) == pdb_atom_name) { if (debug) - std::cout << " pushing back to :" << atom_sel[iat]->altLoc << ": vector " + std::cout << " pushing back to :" << atom_sel[iat]->altLoc() << ": vector " << res->GetChainID() << " " - << res->seqNum << " :" - << atom_sel[iat]->name << ": :" - << atom_sel[iat]->altLoc << ":" << std::endl; + << res->GetSeqNum() << " :" + << atom_sel[iat]->GetAtomName() << ": :" + << atom_sel[iat]->altLoc() << ":" << std::endl; // Too slow for ribosomes @@ -2209,7 +2209,7 @@ int coot::restraints_container_t::add_link_plane(std::string link_type, // res->GetInsCode(), // res->GetChainID())); - std::string key(atom_sel[iat]->altLoc); + std::string key(atom_sel[iat]->altLoc()); int idx_t_2 = -1; atom_sel[iat]->GetUDData(udd_atom_index_handle, idx_t_2); atom_indices_map[key].push_back(idx_t_2); @@ -2232,8 +2232,8 @@ int coot::restraints_container_t::add_link_plane(std::string link_type, for (unsigned int ind=0; indsecond.size(); ind++) { std::cout << ind << " " << atom[it->second[ind]]->GetChainID() << " " << atom[it->second[ind]]->GetSeqNum() << " :" - << atom[it->second[ind]]->name << ": :" - << atom[it->second[ind]]->altLoc << ":\n"; + << atom[it->second[ind]]->GetAtomName() << ": :" + << atom[it->second[ind]]->altLoc() << ":\n"; } std::cout << "DEBUG:: add_link_plane() with pos indexes "; for (unsigned int ipos=0; ipossecond.size(); ipos++) diff --git a/ideal/make-restraints.cc b/ideal/make-restraints.cc index 6dec784e8f..826ed11079 100644 --- a/ideal/make-restraints.cc +++ b/ideal/make-restraints.cc @@ -378,23 +378,23 @@ coot::restraints_container_t::make_helix_pseudo_bond_restraints() { // nO -> (n+4)N 2.91 // and backwards directions. SelResidue[i]->GetAtomTable(res_1_atoms, n_res_1_atoms); for (int iat1=0; iat1name); + std::string at_1_name(res_1_atoms[iat1]->GetAtomName()); if (at_1_name == " N ") { mmdb::Residue *contact_res = SelResidue[i-4]; if (SelResidue[i]->GetSeqNum() == (contact_res->GetSeqNum() + 4)) { contact_res->GetAtomTable(res_2_atoms, n_res_2_atoms); for (int iat2=0; iat2name); + std::string at_2_name(res_2_atoms[iat2]->GetAtomName()); if (at_2_name == " O ") { res_1_atoms[iat1]->GetUDData(udd_atom_index_handle, index1); res_2_atoms[iat2]->GetUDData(udd_atom_index_handle, index2); std::vector fixed_flags = make_fixed_flags(index1, index2); add(BOND_RESTRAINT, index1, index2, fixed_flags, 2.91, pseudo_bond_esd, 1.2); - std::cout << "Helix Bond restraint (" << res_1_atoms[iat1]->name << " " + std::cout << "Helix Bond restraint (" << res_1_atoms[iat1]->GetAtomName() << " " << res_1_atoms[iat1]->GetSeqNum() << ") to (" - << res_2_atoms[iat2]->name << " " + << res_2_atoms[iat2]->GetAtomName() << " " << res_2_atoms[iat2]->GetSeqNum() << ") 2.91" << std::endl; } } @@ -404,16 +404,16 @@ coot::restraints_container_t::make_helix_pseudo_bond_restraints() { if (SelResidue[i]->GetSeqNum() == (contact_res->GetSeqNum() + 3)) { contact_res->GetAtomTable(res_2_atoms, n_res_2_atoms); for (int iat2=0; iat2name); + std::string at_2_name(res_2_atoms[iat2]->GetAtomName()); if (at_2_name == " O ") { std::vector fixed_flags = make_fixed_flags(index1, index2); res_1_atoms[iat1]->GetUDData(udd_atom_index_handle, index1); res_2_atoms[iat2]->GetUDData(udd_atom_index_handle, index2); add(BOND_RESTRAINT, index1, index2, fixed_flags, 3.18, pseudo_bond_esd, 1.2); - std::cout << "Helix Bond restraint (" << res_1_atoms[iat1]->name << " " + std::cout << "Helix Bond restraint (" << res_1_atoms[iat1]->GetAtomName() << " " << res_1_atoms[iat1]->GetSeqNum() << ") to (" - << res_2_atoms[iat2]->name << " " + << res_2_atoms[iat2]->GetAtomName() << " " << res_2_atoms[iat2]->GetSeqNum() << ") 3.18" << std::endl; } } @@ -579,13 +579,13 @@ coot::restraints_container_t::make_helix_pseudo_bond_restraints_from_res_vec_aut // std::cout << "INFO:: Alpha Helix Bond restraint (" // << at_1->name << " " << at_1->GetSeqNum() << ") to (" // << at_3->name << " " << at_3->GetSeqNum() << ") " << ideal_dist_i_3 << std::endl; - logger.log(log_t::INFO, "Alpha Helix Bond restraint (" + std::string(at_1->name) + " " + std::to_string(at_1->GetSeqNum()) + - ") to (" + std::string(at_3->name) + " " + std::to_string(at_3->GetSeqNum()) + ") " + std::to_string(ideal_dist_i_3)); + logger.log(log_t::INFO, "Alpha Helix Bond restraint (" + std::string(at_1->GetAtomName()) + " " + std::to_string(at_1->GetSeqNum()) + + ") to (" + std::string(at_3->GetAtomName()) + " " + std::to_string(at_3->GetSeqNum()) + ") " + std::to_string(ideal_dist_i_3)); // std::cout << "INFO:: Alpha Helix Bond restraint (" // << at_1->name << " " << at_1->GetSeqNum() << ") to (" // << at_2->name << " " << at_2->GetSeqNum() << ") " << ideal_dist_i_4 << std::endl; - logger.log(log_t::INFO, "Alpha Helix Bond restraint (" + std::string(at_1->name) + " " + std::to_string(at_1->GetSeqNum()) + - ") to (" + std::string(at_2->name) + " " + std::to_string(at_2->GetSeqNum()) + ") " + std::to_string(ideal_dist_i_4)); + logger.log(log_t::INFO, "Alpha Helix Bond restraint (" + std::string(at_1->GetAtomName()) + " " + std::to_string(at_1->GetSeqNum()) + + ") to (" + std::string(at_2->GetAtomName()) + " " + std::to_string(at_2->GetSeqNum()) + ") " + std::to_string(ideal_dist_i_4)); } n_helical_restraints += 2; } else { @@ -600,8 +600,8 @@ coot::restraints_container_t::make_helix_pseudo_bond_restraints_from_res_vec_aut // std::cout << "INFO:: Alpha Helix Bond restraint (" // << at_1->name << " " << at_1->GetSeqNum() << ") to (" // << at_3->name << " " << at_3->GetSeqNum() << ") " << ideal_dist_i_3 << std::endl; - logger.log(log_t::INFO, "Alpha Helix Bond restraint (" + std::string(at_1->name) + " " + std::to_string(at_1->GetSeqNum()) + - ") to (" + std::string(at_3->name) + " " + std::to_string(at_3->GetSeqNum()) + ") " + std::to_string(ideal_dist_i_3)); + logger.log(log_t::INFO, "Alpha Helix Bond restraint (" + std::string(at_1->GetAtomName()) + " " + std::to_string(at_1->GetSeqNum()) + + ") to (" + std::string(at_3->GetAtomName()) + " " + std::to_string(at_3->GetSeqNum()) + ") " + std::to_string(ideal_dist_i_3)); } n_helical_restraints += 1; } @@ -678,8 +678,8 @@ coot::restraints_container_t::make_helix_pseudo_bond_restraints_from_res_vec() { mmdb::Atom *at_2 = residue_atoms_2[jat]; std::string atom_name_2 = at_2->GetAtomName(); if (atom_name_2 == " N ") { - std::string alt_conf_1 = at_1->altLoc; - std::string alt_conf_2 = at_2->altLoc; + std::string alt_conf_1 = at_1->altLoc(); + std::string alt_conf_2 = at_2->altLoc(); if (alt_conf_1 == alt_conf_2) { int index_1 = -1; @@ -692,13 +692,13 @@ coot::restraints_container_t::make_helix_pseudo_bond_restraints_from_res_vec() { ideal_dist = 3.181; add(BOND_RESTRAINT, index_1, index_2, fixed_flags, ideal_dist, pseudo_bond_esd, 1.2); std::cout << "Helix Bond restraint (" - << at_1->name << " " << at_1->GetSeqNum() << ") to (" - << at_2->name << " " << at_2->GetSeqNum() << ") " << ideal_dist << std::endl; + << at_1->GetAtomName() << " " << at_1->GetSeqNum() << ") to (" + << at_2->GetAtomName() << " " << at_2->GetSeqNum() << ") " << ideal_dist << std::endl; } } if (atom_name_2 == " O ") { - std::string alt_conf_1 = at_1->altLoc; - std::string alt_conf_2 = at_2->altLoc; + std::string alt_conf_1 = at_1->altLoc(); + std::string alt_conf_2 = at_2->altLoc(); if (alt_conf_1 == alt_conf_2) { int index_1 = -1; @@ -712,8 +712,8 @@ coot::restraints_container_t::make_helix_pseudo_bond_restraints_from_res_vec() { double O_O_pseudo_bond_esd = 0.07; // guess add(BOND_RESTRAINT, index_1, index_2, fixed_flags, ideal_dist, O_O_pseudo_bond_esd, 1.2); std::cout << "Helix Bond restraint (" - << at_1->name << " " << at_1->GetSeqNum() << ") to (" - << at_2->name << " " << at_2->GetSeqNum() << ") " << ideal_dist << std::endl; + << at_1->GetAtomName() << " " << at_1->GetSeqNum() << ") to (" + << at_2->GetAtomName() << " " << at_2->GetSeqNum() << ") " << ideal_dist << std::endl; } } } @@ -771,7 +771,7 @@ coot::restraints_container_t::make_strand_pseudo_bond_restraints() { SelResidue[i]->GetAtomTable(res_1_atoms, n_res_1_atoms); if (res_1_atoms) { for (int iat1=0; iat1name); + std::string at_1_name(res_1_atoms[iat1]->GetAtomName()); // O Pseudo bonds and angles if (at_1_name == " O ") { mmdb::Residue *contact_res = SelResidue[i-1]; @@ -779,7 +779,7 @@ coot::restraints_container_t::make_strand_pseudo_bond_restraints() { contact_res->GetAtomTable(res_2_atoms, n_res_2_atoms); if (res_2_atoms) { for (int iat2=0; iat2name); + std::string at_2_name(res_2_atoms[iat2]->GetAtomName()); if (at_2_name == " O ") { std::vector fixed_flags = make_fixed_flags(index1, index2); res_1_atoms[iat1]->GetUDData(udd_atom_index_handle, index1); @@ -787,9 +787,9 @@ coot::restraints_container_t::make_strand_pseudo_bond_restraints() { add(BOND_RESTRAINT, index1, index2, fixed_flags, 4.64, pseudo_bond_esd, 1.2); std::cout << "Strand Bond restraint (" - << res_1_atoms[iat1]->name << " " + << res_1_atoms[iat1]->GetAtomName() << " " << res_1_atoms[iat1]->GetSeqNum() << ") to (" - << res_2_atoms[iat2]->name << " " + << res_2_atoms[iat2]->GetAtomName() << " " << res_2_atoms[iat2]->GetSeqNum() << ") 4.64" << std::endl; // now the pseudo angle @@ -798,7 +798,7 @@ coot::restraints_container_t::make_strand_pseudo_bond_restraints() { if (SelResidue[i]->GetSeqNum() == (contact_res_2->GetSeqNum() - 1)) { contact_res_2->GetAtomTable(res_3_atoms, n_res_3_atoms); for (int iat3=0; iat3name); + std::string at_3_name(res_3_atoms[iat3]->GetAtomName()); if (at_3_name == " O ") { std::vector fixed_flag = make_fixed_flags(index2, index1, index3); @@ -807,12 +807,12 @@ coot::restraints_container_t::make_strand_pseudo_bond_restraints() { add(ANGLE_RESTRAINT, index2, index1, index3, fixed_flag, 98.0, 0.5, false); std::cout << "Strand Angle restraint (" - << res_1_atoms[iat1]->name << " " + << res_1_atoms[iat1]->GetAtomName() << " " << res_1_atoms[iat1]->GetSeqNum() << ") to (" - << res_2_atoms[iat2]->name << " " + << res_2_atoms[iat2]->GetAtomName() << " " << res_2_atoms[iat2]->GetSeqNum() << ") to (" - << res_3_atoms[iat3]->name << " " + << res_3_atoms[iat3]->GetAtomName() << " " << res_3_atoms[iat3]->GetSeqNum() << ") 98.0 " << std::endl; break; @@ -834,14 +834,14 @@ coot::restraints_container_t::make_strand_pseudo_bond_restraints() { contact_res_2->GetAtomTable(res_2_atoms, n_res_2_atoms); if (res_2_atoms) { for (int iat2=0; iat2name); + std::string at_2_name(res_2_atoms[iat2]->GetAtomName()); if (at_2_name == " CA ") { if (i<(nSelResidues-1)) { mmdb::Residue *contact_res_3 = SelResidue[i+1]; if (SelResidue[i]->GetSeqNum() == (contact_res_3->GetSeqNum() - 1)) { contact_res_3->GetAtomTable(res_3_atoms, n_res_3_atoms); for (int iat3=0; iat3name); + std::string at_3_name(res_3_atoms[iat3]->GetAtomName()); if (at_3_name == " CA ") { std::vector fixed_flag = make_fixed_flags(index1, index2, index3); @@ -851,12 +851,12 @@ coot::restraints_container_t::make_strand_pseudo_bond_restraints() { add(ANGLE_RESTRAINT, index2, index1, index3, fixed_flag, 120.0, 0.5, false); std::cout << "Strand Angle restraint (" - << res_1_atoms[iat1]->name << " " + << res_1_atoms[iat1]->GetAtomName() << " " << res_1_atoms[iat1]->GetSeqNum() << ") to (" - << res_2_atoms[iat2]->name << " " + << res_2_atoms[iat2]->GetAtomName() << " " << res_2_atoms[iat2]->GetSeqNum() << ") to (" - << res_3_atoms[iat3]->name << " " + << res_3_atoms[iat3]->GetAtomName() << " " << res_3_atoms[iat3]->GetSeqNum() << ") 120.0 " << std::endl; break; @@ -1065,7 +1065,7 @@ coot::restraints_container_t::make_monomer_restraints_by_residue(int imol, mmdb: return local; } - std::string pdb_resname(residue_p->name); + std::string pdb_resname(residue_p->GetResName()); if (pdb_resname == "UNK") pdb_resname = "ALA"; if (false) @@ -1181,7 +1181,7 @@ coot::restraints_container_t::add_bonds(int idr, mmdb::PPAtom res_selection, for (unsigned int ib=0; ibname); + std::string pdb_atom_name1(res_selection[iat]->GetAtomName()); if (debug) std::cout << "comparing first (pdb) :" << pdb_atom_name1 @@ -1192,7 +1192,7 @@ coot::restraints_container_t::add_bonds(int idr, mmdb::PPAtom res_selection, if (pdb_atom_name1 == dict.bond_restraint[ib].atom_id_1_4c()) { for (int iat2=0; iat2name); + std::string pdb_atom_name2(res_selection[iat2]->GetAtomName()); if (debug) std::cout << "comparing second (pdb) :" << pdb_atom_name2 @@ -1203,8 +1203,8 @@ coot::restraints_container_t::add_bonds(int idr, mmdb::PPAtom res_selection, if (pdb_atom_name2 == dict.bond_restraint[ib].atom_id_2_4c()) { // check that the alt confs aren't different - std::string alt_1(res_selection[iat ]->altLoc); - std::string alt_2(res_selection[iat2]->altLoc); + std::string alt_1(res_selection[iat ]->altLoc()); + std::string alt_2(res_selection[iat2]->altLoc()); if (alt_1 == "" || alt_2 == "" || alt_1 == alt_2) { if (debug) { @@ -1244,19 +1244,19 @@ coot::restraints_container_t::add_bonds(int idr, mmdb::PPAtom res_selection, if (debug) { std::string altconf_1("\""); - altconf_1 += atom[index1]->altLoc; + altconf_1 += atom[index1]->altLoc(); altconf_1 += "\""; std::string altconf_2("\""); - altconf_2 += atom[index2]->altLoc; + altconf_2 += atom[index2]->altLoc(); altconf_2 += "\""; std::cout << "creating (monomer) bond restraint, idr " << idr << " with fixed flags " << fixed_flags[0] << " " << fixed_flags[1] << " " << atom[index1]->GetSeqNum() << " " - << "\"" << atom[index1]->name << "\" " + << "\"" << atom[index1]->GetAtomName() << "\" " << std::setw(3) << altconf_1 << " to " << atom[index2]->GetSeqNum() << " " - << "\"" << atom[index2]->name << "\" " + << "\"" << atom[index2]->GetAtomName() << "\" " << std::setw(3) << altconf_2 << " " << "bond restraint index " << n_bond_restr << "\n"; } @@ -1276,7 +1276,7 @@ coot::restraints_container_t::add_bonds(int idr, mmdb::PPAtom res_selection, if (is_hydrogen(atom[index1])) { mmdb::Atom *H_at = atom[index1]; mmdb::Atom *parent_at = atom[index2]; - std::string atom_name(parent_at->name); + std::string atom_name(parent_at->GetAtomName()); std::string te = dict.type_energy(atom_name); hb_t hbt = geom.get_h_bond_type(te); H_atom_parent_energy_type_atom_map[H_at] = hbt; @@ -1286,7 +1286,7 @@ coot::restraints_container_t::add_bonds(int idr, mmdb::PPAtom res_selection, if (is_hydrogen(atom[index2])) { mmdb::Atom *H_at = atom[index2]; mmdb::Atom *parent_at = atom[index1]; - std::string atom_name(parent_at->name); + std::string atom_name(parent_at->GetAtomName()); std::string te = dict.type_energy(atom_name); hb_t hbt = geom.get_h_bond_type(te); H_atom_parent_energy_type_atom_map[H_at] = hbt; @@ -1298,7 +1298,7 @@ coot::restraints_container_t::add_bonds(int idr, mmdb::PPAtom res_selection, // So kludge that in here if (dict.residue_info.comp_id == "HIS") { mmdb::Atom *parent_at = atom[index1]; - std::string parent_atom_name(parent_at->name); + std::string parent_atom_name(parent_at->GetAtomName()); if (parent_atom_name == "ND1 ") // PDBv3 fixme H_atom_parent_energy_type_atom_map[H_at] = HB_BOTH; if (parent_atom_name == "NE2 ") // PDBv3 fixme @@ -1306,7 +1306,7 @@ coot::restraints_container_t::add_bonds(int idr, mmdb::PPAtom res_selection, } if (dict.residue_info.comp_id == "TRP") { mmdb::Atom *parent_at = atom[index1]; - std::string parent_atom_name(parent_at->name); + std::string parent_atom_name(parent_at->GetAtomName()); if (parent_atom_name == "NE1 ") // PDBv3 fixme H_atom_parent_energy_type_atom_map[H_at] = HB_BOTH; } @@ -1344,7 +1344,7 @@ coot::restraints_container_t::add_angles(int idr, mmdb::PPAtom res_selection, std::vector string_atom_names(i_no_res_atoms); for (int iat=0; iatname; + string_atom_names[iat] = res_selection[iat]->GetAtomName(); // std::cout << "There are " << geom[idr].angle_restraint.size() // << " angle restraints for this residue type" << std::endl; @@ -1372,9 +1372,9 @@ coot::restraints_container_t::add_angles(int idr, mmdb::PPAtom res_selection, const std::string &pdb_atom_name3 = string_atom_names[iat3]; if (pdb_atom_name3 == geom[idr].second.angle_restraint[ib].atom_id_3_4c()) { - std::string alt_1(res_selection[iat ]->altLoc); - std::string alt_2(res_selection[iat2]->altLoc); - std::string alt_3(res_selection[iat3]->altLoc); + std::string alt_1(res_selection[iat ]->altLoc()); + std::string alt_2(res_selection[iat2]->altLoc()); + std::string alt_3(res_selection[iat3]->altLoc()); if (((alt_1 == alt_2) && (alt_1 == alt_3)) || ((alt_1 == "" ) && (alt_2 == alt_3)) || @@ -1441,22 +1441,22 @@ coot::restraints_container_t::add_torsion_internal(const coot::dict_torsion_rest // now find the atoms for (int iat=0; iatname); + std::string pdb_atom_name1(res_selection[iat]->GetAtomName()); if (pdb_atom_name1 == torsion_restraint.atom_id_1_4c()) { for (int iat2=0; iat2name); + std::string pdb_atom_name2(res_selection[iat2]->GetAtomName()); if (pdb_atom_name2 == torsion_restraint.atom_id_2_4c()) { for (int iat3=0; iat3name); + std::string pdb_atom_name3(res_selection[iat3]->GetAtomName()); if (pdb_atom_name3 == torsion_restraint.atom_id_3_4c()) { for (int iat4=0; iat4name); + std::string pdb_atom_name4(res_selection[iat4]->GetAtomName()); if (pdb_atom_name4 == torsion_restraint.atom_id_4_4c()) { // now we need the indices of @@ -1490,10 +1490,10 @@ coot::restraints_container_t::add_torsion_internal(const coot::dict_torsion_rest if (torsion_angle > 360) torsion_angle -= 360; - std::string alt_conf_1(res_selection[iat]->altLoc); - std::string alt_conf_2(res_selection[iat2]->altLoc); - std::string alt_conf_3(res_selection[iat3]->altLoc); - std::string alt_conf_4(res_selection[iat4]->altLoc); + std::string alt_conf_1(res_selection[iat]->altLoc()); + std::string alt_conf_2(res_selection[iat2]->altLoc()); + std::string alt_conf_3(res_selection[iat3]->altLoc()); + std::string alt_conf_4(res_selection[iat4]->altLoc()); bool alt_confs_match = false; if (alt_conf_1 == "" || alt_conf_1 == alt_conf_2) @@ -1574,7 +1574,7 @@ coot::restraints_container_t::add_chirals(int idr, mmdb::PPAtom res_selection, std::vector string_atom_names(i_no_res_atoms); for (int iat=0; iatname; + string_atom_names[iat] = res_selection[iat]->GetAtomName(); for (unsigned int ic=0; icaltLoc; - std::string alt_conf_1 = res_selection[iat1]->altLoc; - std::string alt_conf_2 = res_selection[iat2]->altLoc; - std::string alt_conf_3 = res_selection[iat3]->altLoc; + std::string alt_conf_c = res_selection[iatc]->altLoc(); + std::string alt_conf_1 = res_selection[iat1]->altLoc(); + std::string alt_conf_2 = res_selection[iat2]->altLoc(); + std::string alt_conf_3 = res_selection[iat3]->altLoc(); if (((alt_conf_1 == alt_conf_c) || (alt_conf_1 == "")) && ((alt_conf_2 == alt_conf_c) || (alt_conf_2 == "")) && @@ -1638,7 +1638,7 @@ coot::restraints_container_t::add_chirals(int idr, mmdb::PPAtom res_selection, if (false) // debug std::cout << " Adding chiral restraint for " - << res_selection[iatc]->name + << res_selection[iatc]->GetAtomName() << " " << res_selection[iatc]->GetSeqNum() << " " << res_selection[iatc]->GetChainID() << " with target volume " @@ -1663,7 +1663,7 @@ coot::restraints_container_t::add_chirals(int idr, mmdb::PPAtom res_selection, n_chiral_restr++; } else { std::cout << "WARNING:: Reject chiral restraint for " - << res_selection[iatc]->name + << res_selection[iatc]->GetAtomName() << " " << res_selection[iatc]->GetSeqNum() << " " << res_selection[iatc]->GetChainID() << " with target volume " @@ -1779,7 +1779,7 @@ coot::restraints_container_t::add_planes_multiatom_eigen(int idr, mmdb::PPAtom r if (debug) std::cout << "There are " << geom[idr].second.plane_restraint.size() - << " dictionary plane restraints for " << SelRes->seqNum << " type: " + << " dictionary plane restraints for " << SelRes->GetSeqNum() << " type: " << geom[idr].second.residue_info.comp_id << std::endl; int n_plane_restr = 0; @@ -1795,8 +1795,8 @@ coot::restraints_container_t::add_planes_multiatom_eigen(int idr, mmdb::PPAtom r for (unsigned int ip=0; ip > > idx_and_sigmas; for (int iat=0; iatname); - std::string alt_conf(res_selection[iat]->altLoc); + std::string pdb_atom_name(res_selection[iat]->GetAtomName()); + std::string alt_conf(res_selection[iat]->altLoc()); for (int irest_at=0; irest_at string_atom_names(i_no_res_atoms); for (int iat=0; iatname; + string_atom_names[iat] = res_selection[iat]->GetAtomName(); for (unsigned int ic=0; icaltLoc; - std::string alt_conf_2 = res_selection[iat2]->altLoc; - std::string alt_conf_3 = res_selection[iat3]->altLoc; - std::string alt_conf_4 = res_selection[iat4]->altLoc; + std::string alt_conf_1 = res_selection[iat1]->altLoc(); + std::string alt_conf_2 = res_selection[iat2]->altLoc(); + std::string alt_conf_3 = res_selection[iat3]->altLoc(); + std::string alt_conf_4 = res_selection[iat4]->altLoc(); if (((alt_conf_1 == alt_conf_4) || (alt_conf_1 == "")) && ((alt_conf_2 == alt_conf_4) || (alt_conf_2 == "")) && @@ -2029,12 +2029,12 @@ coot::restraints_container_t::add_rama(std::string link_type, rama_atoms[ir] = 0; for (int i=0; iname); + std::string atom_name(prev_sel[i]->GetAtomName()); if (atom_name == " C ") rama_atoms[0] = prev_sel[i]; } for (int i=0; iname); + std::string atom_name(this_sel[i]->GetAtomName()); if (atom_name == " N ") rama_atoms[1] = this_sel[i]; if (atom_name == " CA ") @@ -2043,7 +2043,7 @@ coot::restraints_container_t::add_rama(std::string link_type, rama_atoms[3] = this_sel[i]; } for (int i=0; iname); + std::string atom_name(post_sel[i]->GetAtomName()); if (atom_name == " N ") rama_atoms[4] = post_sel[i]; } @@ -2205,7 +2205,7 @@ coot::restraints_container_t::construct_non_bonded_contact_list_conventional() { bool matched_oxt = false; if (have_oxt_flag) { - if (std::string(res_selection_local[iat]->name) == " OXT") { // PDBv3 FIXME + if (std::string(res_selection_local[iat]->GetAtomName()) == " OXT") { // PDBv3 FIXME matched_oxt = true; } else { matched_oxt = false; @@ -2243,7 +2243,7 @@ coot::restraints_container_t::construct_non_bonded_contact_list_conventional() { // PDBv3 FIXME if (have_oxt_flag) - if (! strcmp(res_selection_local_inner[jat]->name, " OXT")) // matched + if (! strcmp(res_selection_local_inner[jat]->GetAtomName(), " OXT")) // matched matched_oxt = true; if (! matched_oxt) { @@ -2273,7 +2273,7 @@ coot::restraints_container_t::construct_non_bonded_contact_list_conventional() { std::cout << " conventional non-bonded list (unfiltered by distance):" << std::endl; std::cout << "--------------------------------------------------\n"; for (unsigned int i=0; iGetSeqNum() << " " << atom[i]->name << " : "; + std::cout << i << " " << atom[i]->GetSeqNum() << " " << atom[i]->GetAtomName() << " : "; for (unsigned int j=0; jname) == " OXT") { // PDBv3 FIXME + if (std::string(atom[i]->GetAtomName()) == " OXT") { // PDBv3 FIXME matched_oxt = true; } } @@ -2352,7 +2352,7 @@ coot::restraints_container_t::construct_non_bonded_contact_list_by_res_vec(const if (i != j) { if (have_oxt_flag) { - if (std::string(atom[j]->name) == " OXT") { // PDBv3 FIXME + if (std::string(atom[j]->GetAtomName()) == " OXT") { // PDBv3 FIXME matched_oxt = true; } } @@ -2387,16 +2387,16 @@ coot::restraints_container_t::construct_non_bonded_contact_list_by_res_vec(const // clipper::Coord_orth pt2(atom[j]->x, atom[j]->y, atom[j]->z); // double d = clipper::Coord_orth::length(pt1, pt2); - double xd(atom[i]->x - atom[j]->x); - double yd(atom[i]->y - atom[j]->y); - double zd(atom[i]->z - atom[j]->z); + double xd(atom[i]->x() - atom[j]->x()); + double yd(atom[i]->y() - atom[j]->y()); + double zd(atom[i]->z() - atom[j]->z()); double d_sqrd = xd*xd + yd*yd + zd*zd; if (d_sqrd < dist_crit_sqrd) { - mmdb::Residue *r1 = atom[i]->residue; - mmdb::Residue *r2 = atom[j]->residue; + mmdb::Residue *r1 = atom[i]->GetResidue(); + mmdb::Residue *r2 = atom[j]->GetResidue(); - std::string alt_conf_1 = atom[i]->altLoc; - std::string alt_conf_2 = atom[j]->altLoc; + std::string alt_conf_1 = atom[i]->altLoc(); + std::string alt_conf_2 = atom[j]->altLoc(); if ((alt_conf_1 == alt_conf_2) || (alt_conf_1.length() == 0) || @@ -2426,12 +2426,12 @@ coot::restraints_container_t::construct_non_bonded_contact_list_by_res_vec(const // for (int iat=0; iatresidue; + mmdb::Residue *bonded_atom_residue = atom[iat]->GetResidue(); for (int jat=0; jatresidue; + mmdb::Residue *other_atom_residue = atom[jat]->GetResidue(); if (bonded_atom_residue != other_atom_residue) { if (is_a_moving_residue_p(bonded_atom_residue) && @@ -2439,7 +2439,7 @@ coot::restraints_container_t::construct_non_bonded_contact_list_by_res_vec(const bool matched_oxt = false; if (have_oxt_flag) { - if (std::string(atom[jat]->name) == " OXT") { // PDBv3 FIXME + if (std::string(atom[jat]->GetAtomName()) == " OXT") { // PDBv3 FIXME matched_oxt = true; } else { matched_oxt = false; @@ -2465,8 +2465,8 @@ coot::restraints_container_t::construct_non_bonded_contact_list_by_res_vec(const if (bonded_atom_indices[iat].find(jat) != bonded_atom_indices[iat].end()) { // atom j is not bonded to atom i, is it close? (i.e. within dist_crit?) - clipper::Coord_orth pt1(atom[iat]->x, atom[iat]->y, atom[iat]->z); - clipper::Coord_orth pt2(atom[jat]->x, atom[jat]->y, atom[jat]->z); + clipper::Coord_orth pt1(atom[iat]->x(), atom[iat]->y(), atom[iat]->z()); + clipper::Coord_orth pt2(atom[jat]->x(), atom[jat]->y(), atom[jat]->z()); double d = clipper::Coord_orth::length(pt1, pt2); if (d < dist_crit) { if (false) @@ -2545,14 +2545,14 @@ coot::restraints_container_t::construct_nbc_for_moving_non_moving_bonded(unsigne // know that res_1 and res_2 are in the correct order for the given // link_type link. // - mmdb::Residue *res_1 = atom[iat]->residue; - mmdb::Residue *res_2 = atom[jat]->residue; + mmdb::Residue *res_1 = atom[iat]->GetResidue(); + mmdb::Residue *res_2 = atom[jat]->GetResidue(); dictionary_residue_link_restraints_t link = geom.link(link_type); // std::cout << "link: " << link.link_id << " " << link.link_bond_restraint.size() << std::endl; if (! link.empty()) { - std::string atom_name_1 = atom[iat]->name; - std::string atom_name_2 = atom[jat]->name; + std::string atom_name_1 = atom[iat]->GetAtomName(); + std::string atom_name_2 = atom[jat]->GetAtomName(); bool add_it = true; for (unsigned int i=0; ix, atom[iat]->y, atom[iat]->z); - clipper::Coord_orth pt2(atom[jat]->x, atom[jat]->y, atom[jat]->z); + clipper::Coord_orth pt1(atom[iat]->x(), atom[iat]->y(), atom[iat]->z()); + clipper::Coord_orth pt2(atom[jat]->x(), atom[jat]->y(), atom[jat]->z()); double d = sqrt((pt1-pt2).lengthsq()); std::cout << "moving-non-moving: adding filtered non-bonded atom indices: " @@ -2621,8 +2621,8 @@ coot::restraints_container_t::filter_non_bonded_by_distance(const std::vectorx, atom_1->y, atom_1->z), // clipper::Coord_orth(atom_2->x, atom_2->y, atom_2->z)); - dist2 = (clipper::Coord_orth(atom_1->x, atom_1->y, atom_1->z) - - clipper::Coord_orth(atom_2->x, atom_2->y, atom_2->z)).lengthsq(); + dist2 = (clipper::Coord_orth(atom_1->x(), atom_1->y(), atom_1->z()) - + clipper::Coord_orth(atom_2->x(), atom_2->y(), atom_2->z())).lengthsq(); if (dist2 < dist_lim2) { // std::cout << "accepting non-bonded contact between " << atom_1->GetSeqNum() diff --git a/ideal/mods.cc b/ideal/mods.cc index 52b0dab7c4..c38ebe8b35 100644 --- a/ideal/mods.cc +++ b/ideal/mods.cc @@ -108,16 +108,16 @@ coot::restraints_container_t::mod_bond_add(const coot::chem_mod_bond &mod_bond, int index_1 = -1, index_2 = -1; for (int iat_1=0; iat_1name); + std::string pdb_atom_name_1(residue_atoms[iat_1]->GetAtomName()); // std::cout << "comparing :" << pdb_atom_name_1 << ": with :" << mod_bond.atom_id_1 // << ":" << std::endl; if (pdb_atom_name_1 == mod_bond.atom_id_1) { for (int iat_2=0; iat_2name); + std::string pdb_atom_name_2(residue_atoms[iat_2]->GetAtomName()); if (pdb_atom_name_2 == mod_bond.atom_id_2) { // check that they have the same alt conf - std::string alt_1(residue_atoms[iat_1]->altLoc); - std::string alt_2(residue_atoms[iat_2]->altLoc); + std::string alt_1(residue_atoms[iat_1]->altLoc()); + std::string alt_2(residue_atoms[iat_2]->altLoc()); if (alt_1 == "" || alt_2 == "" || alt_1 == alt_2) { residue_atoms[iat_1]->GetUDData(udd_atom_index_handle, index_1); residue_atoms[iat_2]->GetUDData(udd_atom_index_handle, index_2); @@ -147,10 +147,10 @@ coot::restraints_container_t::mod_bond_change(const coot::chem_mod_bond &mod_bon { simple_restraint &rest = restraints_vec[i]; // rest may be modified if (rest.restraint_type == coot::BOND_RESTRAINT) { - if (atom[rest.atom_index_1]->residue == residue_p) { - if (atom[rest.atom_index_2]->residue == residue_p) { - std::string name_1 = atom[rest.atom_index_1]->name; - std::string name_2 = atom[rest.atom_index_2]->name; + if (atom[rest.atom_index_1]->GetResidue() == residue_p) { + if (atom[rest.atom_index_2]->GetResidue() == residue_p) { + std::string name_1 = atom[rest.atom_index_1]->GetAtomName(); + std::string name_2 = atom[rest.atom_index_2]->GetAtomName(); if (name_1 == mod_bond.atom_id_1) { if (name_2 == mod_bond.atom_id_2) { rest.target_value = mod_bond.new_value_dist; @@ -182,10 +182,10 @@ coot::restraints_container_t::mod_bond_delete(const coot::chem_mod_bond &mod_bon for (it=restraints_vec.begin(); it!=restraints_vec.end(); it++) { if (it->restraint_type == coot::BOND_RESTRAINT) { - if (atom[it->atom_index_1]->residue == residue_p) { - if (atom[it->atom_index_2]->residue == residue_p) { - std::string name_1 = atom[it->atom_index_1]->name; - std::string name_2 = atom[it->atom_index_2]->name; + if (atom[it->atom_index_1]->GetResidue() == residue_p) { + if (atom[it->atom_index_2]->GetResidue() == residue_p) { + std::string name_1 = atom[it->atom_index_1]->GetAtomName(); + std::string name_2 = atom[it->atom_index_2]->GetAtomName(); if (name_1 == mod_bond.atom_id_1) { if (name_2 == mod_bond.atom_id_2) { if (0) @@ -228,19 +228,19 @@ coot::restraints_container_t::mod_angle_add(const coot::chem_mod_angle &mod_angl int index_1 = -1, index_2 = -1, index_3 = -1; for (int iat_1=0; iat_1name); + std::string pdb_atom_name_1(residue_atoms[iat_1]->GetAtomName()); if (pdb_atom_name_1 == mod_angle.atom_id_1) { for (int iat_2=0; iat_2name); + std::string pdb_atom_name_2(residue_atoms[iat_2]->GetAtomName()); if (pdb_atom_name_2 == mod_angle.atom_id_2) { for (int iat_3=0; iat_3name); + std::string pdb_atom_name_3(residue_atoms[iat_3]->GetAtomName()); if (pdb_atom_name_3 == mod_angle.atom_id_3) { // check that they have the same alt conf - std::string alt_1(residue_atoms[iat_1]->altLoc); - std::string alt_2(residue_atoms[iat_2]->altLoc); - std::string alt_3(residue_atoms[iat_3]->altLoc); + std::string alt_1(residue_atoms[iat_1]->altLoc()); + std::string alt_2(residue_atoms[iat_2]->altLoc()); + std::string alt_3(residue_atoms[iat_3]->altLoc()); if (((alt_1 == alt_2) && (alt_1 == alt_3)) || ((alt_1 == "" ) && (alt_2 == alt_3)) || ((alt_2 == "" ) && (alt_1 == alt_3)) || @@ -284,11 +284,11 @@ coot::restraints_container_t::mod_angle_change(const coot::chem_mod_angle &mod_a { simple_restraint &rest = restraints_vec[i]; if (rest.restraint_type == coot::ANGLE_RESTRAINT) { - if (atom[restraints_vec[i].atom_index_1]->residue == residue_p) { - if (atom[restraints_vec[i].atom_index_2]->residue == residue_p) { - std::string name_1 = atom[rest.atom_index_1]->name; - std::string name_2 = atom[rest.atom_index_2]->name; - std::string name_3 = atom[rest.atom_index_3]->name; + if (atom[restraints_vec[i].atom_index_1]->GetResidue() == residue_p) { + if (atom[restraints_vec[i].atom_index_2]->GetResidue() == residue_p) { + std::string name_1 = atom[rest.atom_index_1]->GetAtomName(); + std::string name_2 = atom[rest.atom_index_2]->GetAtomName(); + std::string name_3 = atom[rest.atom_index_3]->GetAtomName(); if (name_1 == mod_angle.atom_id_1) { if (name_2 == mod_angle.atom_id_2) { if (name_3 == mod_angle.atom_id_3) { @@ -325,11 +325,11 @@ coot::restraints_container_t::mod_angle_delete(const coot::chem_mod_angle &mod_a for (it=restraints_vec.begin(); it!=restraints_vec.end(); it++) { if (it->restraint_type == coot::ANGLE_RESTRAINT) { - if (atom[it->atom_index_1]->residue == residue_p) { - if (atom[it->atom_index_2]->residue == residue_p) { - std::string name_1 = atom[it->atom_index_1]->name; - std::string name_2 = atom[it->atom_index_2]->name; - std::string name_3 = atom[it->atom_index_3]->name; + if (atom[it->atom_index_1]->GetResidue() == residue_p) { + if (atom[it->atom_index_2]->GetResidue() == residue_p) { + std::string name_1 = atom[it->atom_index_1]->GetAtomName(); + std::string name_2 = atom[it->atom_index_2]->GetAtomName(); + std::string name_3 = atom[it->atom_index_3]->GetAtomName(); if (name_1 == mod_angle.atom_id_1) { if (name_2 == mod_angle.atom_id_2) { if (name_2 == mod_angle.atom_id_3) { @@ -376,11 +376,11 @@ coot::restraints_container_t::mod_plane_add(const coot::chem_mod_plane &mod_plan for (unsigned int i=0; iname); + std::string atom_name(residue_atoms[iat]->GetAtomName()); if (atom_name == mod_plane.atom_id_esd[i].first) { int atom_index; residue_atoms[iat]->GetUDData(udd_atom_index_handle, atom_index); - std::string altconf = residue_atoms[iat]->altLoc; + std::string altconf = residue_atoms[iat]->altLoc(); pos[altconf].push_back(atom_index); } } @@ -422,7 +422,7 @@ coot::restraints_container_t::mod_plane_delete(const coot::chem_mod_plane &mod_p // do the atoms of the mod_plane match the atoms of the restraint? for (unsigned int iat=0; iatplane_atom_index.size(); iat++) { for (unsigned int iat_mod=0; iat_modplane_atom_index[iat].first]->name; + std::string atom_name = atom[it->plane_atom_index[iat].first]->GetAtomName(); if (atom_name == mod_plane.atom_id_esd[iat_mod].first) { if (atom[it->plane_atom_index[iat].first]->GetResidue() == residue_p) { n_found++; diff --git a/ideal/ng.cc b/ideal/ng.cc index 24afa8af49..942e3a7dd4 100644 --- a/ideal/ng.cc +++ b/ideal/ng.cc @@ -257,9 +257,9 @@ coot::restraints_container_t::make_rama_plot_restraints_ng(const std::mapindex; - int index_t = residue_this_p->index; - int index_n = residue_next_p->index; + int index_p = residue_prev_p->GetIndex(); + int index_t = residue_this_p->GetIndex(); + int index_n = residue_next_p->GetIndex(); if (false) std::cout << "residues " << residue_spec_t(residue_prev_p) << " " @@ -427,12 +427,12 @@ coot::restraints_container_t::make_flanking_atoms_restraints_ng(const coot::prot std::map >::const_iterator it; for (it=fixed_neighbours_set.begin(); it!=fixed_neighbours_set.end(); it++) { mmdb::Residue *residue_p = it->first; - std::cout << "\n\n...fixed-neighbour for residue " << residue_spec_t(residue_p) << " index " << residue_p->index << std::endl; + std::cout << "\n\n...fixed-neighbour for residue " << residue_spec_t(residue_p) << " index " << residue_p->GetIndex() << std::endl; const std::set &s = it->second; std::set::const_iterator its; for (its=s.begin(); its!=s.end(); its++) { mmdb::Residue *neighb = *its; - std::cout << " neighb: " << residue_spec_t(neighb) << " " << neighb << " index " << neighb->index << std::endl; + std::cout << " neighb: " << residue_spec_t(neighb) << " " << neighb << " index " << neighb->GetIndex() << std::endl; } } std::cout << "####### done make_flanking_atoms_restraints_ng() debugging fixed_neighbours_set() " << std::endl; @@ -493,7 +493,7 @@ coot::restraints_container_t::make_flanking_atoms_restraints_ng(const coot::prot if (std::find(itm->second.begin(), itm->second.end(), neighb) != itm->second.end()) continue; - int index_delta = neighb->index - residue_p->index; + int index_delta = neighb->GetIndex() - residue_p->GetIndex(); if (index_delta == -1 || index_delta == 1) { // std::cout << " fixed neigb: " << residue_spec_t(*its) << std::endl; @@ -731,7 +731,7 @@ coot::restraints_container_t::make_non_bonded_contact_restraints_workpackage_ng( if (at_1->isTer()) continue; const std::set &n_set = vcontacts[i]; - std::string alt_conf_1(at_1->altLoc); + std::string alt_conf_1(at_1->altLoc()); // std::cout << "base atom: " << atom_spec_t(at_1) << std::endl; // std::cout << "Here with i " << i << " which has " << n_set.size() << " neighbours " << std::endl; @@ -750,7 +750,7 @@ coot::restraints_container_t::make_non_bonded_contact_restraints_workpackage_ng( continue; mmdb::Atom *at_2 = atom[j]; - std::string alt_conf_2(at_2->altLoc); + std::string alt_conf_2(at_2->altLoc()); { bool at_1_is_fixed_flag = false; @@ -782,8 +782,8 @@ coot::restraints_container_t::make_non_bonded_contact_restraints_workpackage_ng( if (res_name_2 == "PRO") second_is_pro = true; // residues are sorted and j > i if (res_name_2 == "HYP") second_is_pro = true; - std::string element_1 = at_1->element; - std::string element_2 = at_2->element; + std::string element_1 = at_1->GetElementName(); + std::string element_2 = at_2->GetElementName(); const std::string &type_1 = energy_type_for_atom[i]; const std::string &type_2 = energy_type_for_atom[j]; @@ -794,11 +794,11 @@ coot::restraints_container_t::make_non_bonded_contact_restraints_workpackage_ng( double dist_min = 3.4; - bool in_same_residue_flag = (at_1->residue == at_2->residue); + bool in_same_residue_flag = (at_1->GetResidue() == at_2->GetResidue()); bool in_same_ring_flag = true; // part of this test is not needed. - if (at_2->residue != at_1->residue) { + if (at_2->GetResidue() != at_1->GetResidue()) { in_same_ring_flag = false; in_same_residue_flag = false; } @@ -807,7 +807,7 @@ coot::restraints_container_t::make_non_bonded_contact_restraints_workpackage_ng( std::string atom_name_2(at_2->GetAtomName()); if (in_same_ring_flag) - in_same_ring_flag = is_in_same_ring(imol, at_2->residue, residue_ring_map_cache, + in_same_ring_flag = is_in_same_ring(imol, at_2->GetResidue(), residue_ring_map_cache, atom_name_1, atom_name_2, geom); // this doesn't check 1-4 over a moving->non-moving peptide link (see comment above function) @@ -833,13 +833,13 @@ coot::restraints_container_t::make_non_bonded_contact_restraints_workpackage_ng( if (atom_name_1 == " C ") if (atom_name_2 == " C ") - if (at_2->residue->index - at_1->residue->index == 1) { + if (at_2->GetResidue()->GetIndex() - at_1->GetResidue()->GetIndex() == 1) { mc_atoms_tandem = true; mc_CC_atoms_tandem = true; } if (atom_name_1 == " N ") if (atom_name_2 == " N ") - if (at_2->residue->index - at_1->residue->index == -1) + if (at_2->GetResidue()->GetIndex() - at_1->GetResidue()->GetIndex() == -1) mc_atoms_tandem = true; // down-weight CA-CA in cis-peptide bonds if (atom_name_1 == " CA ") @@ -1235,26 +1235,26 @@ coot::restraints_container_t::make_non_bonded_contact_restraints_ng(int imol, double dist_min = 3.4; - bool in_same_residue_flag = (at_1->residue == at_2->residue); + bool in_same_residue_flag = (at_1->GetResidue() == at_2->GetResidue()); bool in_same_ring_flag = true; // part of this test is not needed. - if (at_2->residue != at_1->residue) { + if (at_2->GetResidue() != at_1->GetResidue()) { in_same_ring_flag = false; in_same_residue_flag = false; } std::string atom_name_1 = at_1->GetAtomName(); std::string atom_name_2 = at_2->GetAtomName(); - std::string element_1 = at_1->element; - std::string element_2 = at_2->element; + std::string element_1 = at_1->GetElementName(); + std::string element_2 = at_2->GetElementName(); if (in_same_ring_flag) { // in_same_ring_flag = restraints_map[at_2->residue].second.in_same_ring(atom_name_1, // atom_name_2); - in_same_ring_flag = is_in_same_ring(imol, at_2->residue, + in_same_ring_flag = is_in_same_ring(imol, at_2->GetResidue(), residue_ring_map_cache, atom_name_1, atom_name_2, geom); } @@ -1275,18 +1275,18 @@ coot::restraints_container_t::make_non_bonded_contact_restraints_ng(int imol, if (atom_name_1 == " C ") if (atom_name_2 == " C ") - if (at_2->residue->index - at_1->residue->index == 1) { + if (at_2->GetResidue()->GetIndex() - at_1->GetResidue()->GetIndex() == 1) { if (false) std::cout << "DEBUG:: in make_non_bonded_contact_restraints_ng() C to C neighbs " - << at_1->residue->index << " " << at_2->residue->index + << at_1->GetResidue()->GetIndex() << " " << at_2->GetResidue()->GetIndex() << std::endl; mc_atoms_tandem = true; } if (atom_name_1 == " N ") if (atom_name_2 == " N ") - if (at_2->residue->index - at_1->residue->index == -1) { + if (at_2->GetResidue()->GetIndex() - at_1->GetResidue()->GetIndex() == -1) { mc_atoms_tandem = true; - std::cout << "-------- Here 2 " << at_1->residue->index << " " << at_2->residue->index + std::cout << "-------- Here 2 " << at_1->GetResidue()->GetIndex() << " " << at_2->GetResidue()->GetIndex() << std::endl; } } @@ -1560,8 +1560,8 @@ coot::restraints_container_t::find_peptide_link_type_ng(mmdb::Residue *res_1, std::string t1; std::string t2; - std::string residue_type_1 = res_1->name; - std::string residue_type_2 = res_2->name; + std::string residue_type_1 = res_1->GetResName(); + std::string residue_type_2 = res_2->GetResName(); for (unsigned int idr=0; idrGetAtomName()); if (at_name_1 == " C ") { // PDBv3 FIXE - std::string alt_conf_1(at_1->altLoc); + std::string alt_conf_1(at_1->altLoc()); for (int iat_2=0; iat_2GetAtomName()); if (at_name_2 == " N ") { // PDBv3 FIXE - std::string alt_conf_2(at_2->altLoc); + std::string alt_conf_2(at_2->altLoc()); if (alt_conf_1 == alt_conf_2 || alt_conf_1.empty() || alt_conf_2.empty()) { bool is_fixed_first_residue = res_1_pair.first; @@ -1741,12 +1741,12 @@ coot::restraints_container_t::try_make_phosphodiester_link_ng(const coot::protei mmdb::Atom *at_1 = residue_1_atoms[iat_1]; std::string at_name_1(at_1->GetAtomName()); if (at_name_1 == " O3'") { // PDBv3 FIXME - std::string alt_conf_1(at_1->altLoc); + std::string alt_conf_1(at_1->altLoc()); for (int iat_2=0; iat_2GetAtomName()); if (at_name_2 == " P ") { // PDBv3 FIXE - std::string alt_conf_2(at_2->altLoc); + std::string alt_conf_2(at_2->altLoc()); if (alt_conf_1 == alt_conf_2 || alt_conf_1.empty() || alt_conf_2.empty()) { if (use_distance_cut_off) { @@ -1834,9 +1834,9 @@ coot::restraints_container_t::N_and_C_are_close_ng(mmdb::Residue *res_1, if (at_1) { if (at_2) { float dd = - (at_1->x - at_2->x) * (at_1->x - at_2->x) + - (at_1->y - at_2->y) * (at_1->y - at_2->y) + - (at_1->z - at_2->z) * (at_1->z - at_2->z); + (at_1->x() - at_2->x()) * (at_1->x() - at_2->x()) + + (at_1->y() - at_2->y()) * (at_1->y() - at_2->y()) + + (at_1->z() - at_2->z()) * (at_1->z() - at_2->z()); if (dd < d_crit * d_crit) status = true; } @@ -1869,9 +1869,9 @@ coot::restraints_container_t::O3prime_and_P_are_close_ng(mmdb::Residue *res_1, if (at_1) { if (at_2) { float dd = - (at_1->x - at_2->x) * (at_1->x - at_2->x) + - (at_1->y - at_2->y) * (at_1->y - at_2->y) + - (at_1->z - at_2->z) * (at_1->z - at_2->z); + (at_1->x() - at_2->x()) * (at_1->x() - at_2->x()) + + (at_1->y() - at_2->y()) * (at_1->y() - at_2->y()) + + (at_1->z() - at_2->z()) * (at_1->z() - at_2->z()); if (dd < d_crit * d_crit) status = true; } @@ -1932,11 +1932,11 @@ coot::restraints_container_t::make_polymer_links_ng(const coot::protein_geometry if (res_name_2 == "HOH") continue; if (res_1->chain == res_2->chain) { - int serial_delta = res_2->index - res_1->index; + int serial_delta = res_2->GetIndex() - res_1->GetIndex(); // *this* is the serial_delta we should be checking - int ref_index_1 = residues_vec[i1].second->index; - int ref_index_2 = residues_vec[i2].second->index; + int ref_index_1 = residues_vec[i1].second->GetIndex(); + int ref_index_2 = residues_vec[i2].second->GetIndex(); serial_delta = ref_index_2 - ref_index_1; @@ -2217,17 +2217,17 @@ coot::restraints_container_t::make_other_types_of_link(const coot::protein_geome for (std::size_t i=0; i &n_set = vcontacts[i]; mmdb::Atom *at_1 = atom[i]; - if (strcmp(at_1->element, " H") == 0) continue; + if (strcmp(at_1->GetElementName(), " H") == 0) continue; // if (! is_fully_linked_ng(at_1->residue, residue_link_count_map)) { if (true) { std::set::const_iterator it; for (it=n_set.begin(); it!=n_set.end(); ++it) { mmdb::Atom *at_2 = atom[*it]; - if (strcmp(at_2->element, " H") == 0) continue; + if (strcmp(at_2->GetElementName(), " H") == 0) continue; - mmdb::Residue *res_1 = at_1->residue; - mmdb::Residue *res_2 = at_2->residue; + mmdb::Residue *res_1 = at_1->GetResidue(); + mmdb::Residue *res_2 = at_2->GetResidue(); std::string res_name_1(res_1->GetResName()); std::string res_name_2(res_2->GetResName()); diff --git a/ideal/pepflip.cc b/ideal/pepflip.cc index e3fe98569f..3201bc5c33 100644 --- a/ideal/pepflip.cc +++ b/ideal/pepflip.cc @@ -106,8 +106,8 @@ coot::pepflip_standard(mmdb::Manager *mol, first_res->GetAtomTable(first_residue_atoms, n_first_residue_atoms); second_res->GetAtomTable(second_residue_atoms, n_second_residue_atoms); for (int iat=0; iatname); - std::string alt_conf_atom(first_residue_atoms[iat]->altLoc); + std::string atom_name(first_residue_atoms[iat]->GetAtomName()); + std::string alt_conf_atom(first_residue_atoms[iat]->altLoc()); if (alt_conf_atom == altconf || alt_conf_atom == "") { if (atom_name == " CA " ) { ca1 = first_residue_atoms[iat]; @@ -123,8 +123,8 @@ coot::pepflip_standard(mmdb::Manager *mol, } } for (int iat=0; iatname); - std::string alt_conf_atom(second_residue_atoms[iat]->altLoc); + std::string atom_name(second_residue_atoms[iat]->GetAtomName()); + std::string alt_conf_atom(second_residue_atoms[iat]->altLoc()); if (alt_conf_atom == altconf || alt_conf_atom == "") { if (atom_name == " CA " ) { ca2 = second_residue_atoms[iat]; @@ -157,14 +157,14 @@ coot::pepflip_standard(mmdb::Manager *mol, if (dist < dist_crit) { status = 1; std::vector cas(2); - cas[0] = clipper::Coord_orth(ca1->x, ca1->y, ca1->z); - cas[1] = clipper::Coord_orth(ca2->x, ca2->y, ca2->z); + cas[0] = clipper::Coord_orth(ca1->x(), ca1->y(), ca1->z()); + cas[1] = clipper::Coord_orth(ca2->x(), ca2->y(), ca2->z()); std::vector v = flip_internal(cas, flipping_atoms); for (unsigned int i=0; ix = v[i].x(); - flipping_atoms[i]->y = v[i].y(); - flipping_atoms[i]->z = v[i].z(); + flipping_atoms[i]->x() = v[i].x(); + flipping_atoms[i]->y() = v[i].y(); + flipping_atoms[i]->z() = v[i].z(); } } } @@ -196,8 +196,8 @@ coot::pepflip_internal_to_residue(mmdb::Manager *mol, residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); - std::string atom_alt_conf(at->altLoc); + std::string atom_name(at->GetAtomName()); + std::string atom_alt_conf(at->altLoc()); // PDBv3 FIXME if (atom_alt_conf == altconf) { if (atom_name == " CA ") @@ -209,13 +209,13 @@ coot::pepflip_internal_to_residue(mmdb::Manager *mol, } } if (c_at && o_at && ca_at) { - clipper::Coord_orth p1(ca_at->x, ca_at->y, ca_at->z); - clipper::Coord_orth p2(c_at->x, c_at->y, c_at->z); - clipper::Coord_orth p3(o_at->x, o_at->y, o_at->z); + clipper::Coord_orth p1(ca_at->x(), ca_at->y(), ca_at->z()); + clipper::Coord_orth p2(c_at->x(), c_at->y(), c_at->z()); + clipper::Coord_orth p3(o_at->x(), o_at->y(), o_at->z()); clipper::Coord_orth p3_new = util::rotate_around_vector(p2-p1, p3, p1, M_PI); - o_at->x = p3_new.x(); - o_at->y = p3_new.y(); - o_at->z = p3_new.z(); + o_at->x() = p3_new.x(); + o_at->y() = p3_new.y(); + o_at->z() = p3_new.z(); status = true; } else { std::cout << "not all internal atoms found " << std::endl; @@ -243,7 +243,7 @@ coot::flip_internal(const std::vector &ca_in, cas[1] -= trans; for (unsigned int i=0;ix, atoms[i]->y, atoms[i]->z); + atoms_orth[i] = clipper::Coord_orth(atoms[i]->x(), atoms[i]->y(), atoms[i]->z()); atoms_orth[i] -= trans; } diff --git a/ideal/pull-restraint.cc b/ideal/pull-restraint.cc index 3928a3c78b..14485b43b0 100644 --- a/ideal/pull-restraint.cc +++ b/ideal/pull-restraint.cc @@ -190,9 +190,9 @@ coot::restraints_container_t::pull_restraint_displace_neighbours(mmdb::Atom *pul mmdb::Atom *at = atom[iat]; if (fixed_atom_indices.find(iat) == fixed_atom_indices.end()) { // not fixed float d_squared = - (at->x - pull_atom->x) * (at->x - pull_atom->x) + - (at->y - pull_atom->y) * (at->y - pull_atom->y) + - (at->z - pull_atom->z) * (at->z - pull_atom->z); + (at->x() - pull_atom->x()) * (at->x() - pull_atom->x()) + + (at->y() - pull_atom->y()) * (at->y() - pull_atom->y()) + + (at->z() - pull_atom->z()) * (at->z() - pull_atom->z()); if (d_squared < r_squared) { float d = sqrt(d_squared); float ff = 1.0f - d/radius; @@ -200,9 +200,9 @@ coot::restraints_container_t::pull_restraint_displace_neighbours(mmdb::Atom *pul float sf = sqrt(ff); if (use_top_hat_function) sf = 1.0; - at->x += sf * f * delta.x(); - at->y += sf * f * delta.y(); - at->z += sf * f * delta.z(); + at->x() += sf * f * delta.x(); + at->y() += sf * f * delta.y(); + at->z() += sf * f * delta.z(); } } } @@ -358,7 +358,7 @@ coot::restraints_container_t::turn_off_when_close_target_position_restraint() { if (it->restraint_type == restraint_type_t(TARGET_POS_RESTRAINT)) { if (it->is_closed) { mmdb::Atom *at = atom[it->atom_index_1]; - clipper::Coord_orth pos(at->x, at->y, at->z); + clipper::Coord_orth pos(at->x(), at->y(), at->z()); double d = sqrt((pos - it->atom_pull_target_pos).lengthsq()); if (d < close_dist) { it->close(); @@ -405,7 +405,7 @@ coot::restraints_container_t::turn_off_atom_pull_restraints_when_close_to_target } else { mmdb::Atom *at = atom[it->atom_index_1]; if (atom_spec_t(at) != dragged_atom_spec) { - clipper::Coord_orth pos(at->x, at->y, at->z); + clipper::Coord_orth pos(at->x(), at->y(), at->z()); double d = sqrt((pos - it->atom_pull_target_pos).lengthsq()); if (d < close_dist) { it->close(); diff --git a/ideal/simple-restraint.cc b/ideal/simple-restraint.cc index 449fbfdd83..897531aa67 100644 --- a/ideal/simple-restraint.cc +++ b/ideal/simple-restraint.cc @@ -236,9 +236,9 @@ coot::restraints_container_t::restraints_container_t(atom_selection_container_t initial_position_params_vec.resize(3*n_atoms); for (int i=0; ix; - initial_position_params_vec[3*i+1] = atom[i]->y; - initial_position_params_vec[3*i+2] = atom[i]->z; + initial_position_params_vec[3*i ] = atom[i]->x(); + initial_position_params_vec[3*i+1] = atom[i]->y(); + initial_position_params_vec[3*i+2] = atom[i]->z(); // std::cout << " " << i << " " << coot::atom_spec_t(atom[i]) << "\n"; } } @@ -257,7 +257,7 @@ coot::restraints_container_t::restraints_container_t(mmdb::PResidue *SelResidues int resno; for (int i=0; iseqNum; + resno = SelResidues[i]->GetSeqNum(); if (resno < istart_res_l) istart_res_l = resno; if (resno > iend_res_l) @@ -328,10 +328,10 @@ coot::residue_sorter(const std::pair &r1, if (chain_id_1 > chain_id_2) { return false; } else { - if (r1.second->index < r2.second->index) { + if (r1.second->GetIndex() < r2.second->GetIndex()) { return true; } else { - if (r1.second->index > r2.second->index) { + if (r1.second->GetIndex() > r2.second->GetIndex()) { return false; } else { if (r1.second->GetSeqNum() < r2.second->GetSeqNum()) { @@ -398,7 +398,7 @@ coot::restraints_container_t::restraints_container_t(const std::vectorindex << std::endl; + << " has index " << residues_local[i].second->GetIndex() << std::endl; residues_vec = residues_local; init_from_residue_vec(residues_local, geom, mol_in, fixed_atom_specs); @@ -521,7 +521,7 @@ coot::restraints_container_t::init_from_mol(int istart_res_in, int iend_res_in, std::cout << "DEBUG:: Selecting residues in chain \"" << chain_id << "\" gives " << n_atoms << " atoms " << std::endl; for (int iat=0; iatname << " " << atom[iat]->GetSeqNum() + std::cout << " " << iat << " " << atom[iat]->GetAtomName() << " " << atom[iat]->GetSeqNum() << " " << atom[iat]->GetChainID() << std::endl; } } @@ -643,10 +643,10 @@ coot::restraints_container_t::set_z_occ_weights() { for (int i=0; iisTer()) { - std::string element = at->element; - double z = coot::util::atomic_number(at->element, atom_list); + std::string element = at->GetElementName(); + double z = coot::util::atomic_number(at->GetElementName(), atom_list); double weight = 1.0; - double occupancy = atom[i]->occupancy; + double occupancy = atom[i]->occupancy(); if (occupancy > 1.0) occupancy = 1.0; if (do_neutron_refinement) { int formal_charge = 0; @@ -658,7 +658,7 @@ coot::restraints_container_t::set_z_occ_weights() { // std::cout << "downweighting atom " << coot::atom_spec_t(atom[i]) << std::endl; weight = 0.2; } - std::string at_name = atom[i]->name; + std::string at_name = atom[i]->GetAtomName(); if (at_name == " O ") { weight = 0.4; } @@ -666,7 +666,7 @@ coot::restraints_container_t::set_z_occ_weights() { if (z < 0.0) { std::cout << "WARNING:: init_shared_post() atom " << i << " " << atom_spec_t(atom[i]) - << " Unknown element \"" << atom[i]->element << "\"" << std::endl; + << " Unknown element \"" << atom[i]->GetElementName() << "\"" << std::endl; z = 6.0; // as for carbon } atom_z_occ_weight[i] = weight * z * occupancy; @@ -688,9 +688,9 @@ coot::restraints_container_t::init_shared_post(const std::vector &f initial_position_params_vec.resize(3*n_atoms); for (int i=0; ix; - initial_position_params_vec[3*i+1] = atom[i]->y; - initial_position_params_vec[3*i+2] = atom[i]->z; + initial_position_params_vec[3*i ] = atom[i]->x(); + initial_position_params_vec[3*i+1] = atom[i]->y(); + initial_position_params_vec[3*i+2] = atom[i]->z(); } // Set the UDD have_bond_or_angle to initally all "not". They get @@ -733,8 +733,8 @@ coot::restraints_container_t::init_shared_post(const std::vector &f if (! from_residue_vector) { // convential way for (int i=0; iresidue->seqNum >= istart_res && - atom[i]->residue->seqNum <= iend_res) { + if (atom[i]->GetResidue()->GetSeqNum() >= istart_res && + atom[i]->GetResidue()->GetSeqNum() <= iend_res) { if (! is_hydrogen(atom[i])) use_map_gradient_for_atom[i] = true; } else { @@ -744,7 +744,7 @@ coot::restraints_container_t::init_shared_post(const std::vector &f } else { // blank out the non moving atoms (i.e. flanking residues) for (int i=0; iresidue; + mmdb::Residue *res_p = atom[i]->GetResidue(); if (is_a_moving_residue_p(res_p)) { if (! is_hydrogen(atom[i]) || do_hydrogen_atom_refinement) use_map_gradient_for_atom[i] = true; @@ -770,7 +770,7 @@ coot::restraints_container_t::init_shared_post(const std::vector &f if (verbose_geometry_reporting == VERBOSE) for (int i=0; iname << " " << atom[i]->residue->seqNum << " " + std::cout << atom[i]->GetAtomName() << " " << atom[i]->GetResidue()->GetSeqNum() << " " << use_map_gradient_for_atom[i] << std::endl; } @@ -876,7 +876,7 @@ coot::restraints_container_t::init_from_residue_vec(const std::vectorname << "\" \"" << at->altLoc << "\" " + << at->GetAtomName() << "\" \"" << at->altLoc() << "\" " << at->GetSeqNum() << " \"" << at->GetInsCode() << "\" \"" << at->GetChainID() << "\"" << std::endl; } @@ -1159,7 +1159,7 @@ coot::restraints_container_t::init_from_residue_vec(const std::vectorname << " " + std::cout << " " << std::setw(3) << iat << " " << atom[iat]->GetAtomName() << " " << atom[iat]->GetSeqNum() << " " << atom[iat]->GetChainID() << " " << atom[iat]->GetResName() << " fixed: " << fixed_flag << std::endl; } @@ -1215,9 +1215,9 @@ coot::restraints_container_t::debug_atoms() const { bool is_fixed = false; if (fixed_atom_indices.find(iat) != fixed_atom_indices.end()) is_fixed = true; std::cout << std::setw(3) << iat << " " << atom_spec_t(atom[iat]) << " " - << std::right << std::setw(10) << std::fixed << std::setprecision(3) << atom[iat]->x << " " - << std::right << std::setw(10) << std::fixed << std::setprecision(3) << atom[iat]->y << " " - << std::right << std::setw(10) << std::fixed << std::setprecision(3) << atom[iat]->z + << std::right << std::setw(10) << std::fixed << std::setprecision(3) << atom[iat]->x() << " " + << std::right << std::setw(10) << std::fixed << std::setprecision(3) << atom[iat]->y() << " " + << std::right << std::setw(10) << std::fixed << std::setprecision(3) << atom[iat]->z() << " fixed: " << is_fixed << std::endl; } } @@ -1724,9 +1724,9 @@ coot::refinement_results_for_rama_t::refinement_results_for_rama_t(mmdb::Atom *a atom_spec_CA = atom_spec_t(at_3); ball_pos_x = 0; ball_pos_y = 0; ball_pos_z = 0; if (at_3) { - ball_pos_x = at_3->x + 0.5; - ball_pos_y = at_3->y; - ball_pos_z = at_3->z; + ball_pos_x = at_3->x() + 0.5; + ball_pos_y = at_3->y(); + ball_pos_z = at_3->z(); } if (at_1 && at_2 && at_3 && at_4 && at_5) { clipper::Coord_orth p2 = co(at_2); @@ -1742,9 +1742,9 @@ coot::refinement_results_for_rama_t::refinement_results_for_rama_t(mmdb::Atom *a clipper::Coord_orth p2p24_mid_point(0.5 * (p4+p2)); clipper::Coord_orth mid_point_to_CA(p3 - p2p24_mid_point); clipper::Coord_orth delta = 0.2 * mid_point_to_CA + 0.4 * v4; - ball_pos_x = delta.x() + at_3->x; - ball_pos_y = delta.y() + at_3->y; - ball_pos_z = delta.z() + at_3->z; + ball_pos_x = delta.x() + at_3->x(); + ball_pos_y = delta.y() + at_3->y(); + ball_pos_z = delta.z() + at_3->z(); } } @@ -1893,7 +1893,7 @@ coot::restraints_container_t::add_details_to_refinement_results(coot::refinement double chiral_volume_distortion_limit = 6.0; // c.f. limiit in dynamic-valiation.cc make_chiral_volume_buttons() if (dist > chiral_volume_distortion_limit) { mmdb:: Atom *at = atom[restraint.atom_index_centre]; - clipper::Coord_orth pos(at->x, at->y, at->z); + clipper::Coord_orth pos(at->x(), at->y(), at->z()); refinement_results_for_chiral_t cb(atom_spec_t(at), pos, dist); chiral_baddies.push_back(cb); } @@ -1957,7 +1957,7 @@ coot::restraints_container_t::add_details_to_refinement_results(coot::refinement // if (dd > -200.0) { // GLY have naturally lower probabilities densities, hence higher -logPr - std::string rn(atom[restraint.atom_index_3]->residue->GetResName()); + std::string rn(atom[restraint.atom_index_3]->GetResidue()->GetResName()); if (rn == "GLY") { dd -= 50.0; // utter guess } @@ -1970,7 +1970,7 @@ coot::restraints_container_t::add_details_to_refinement_results(coot::refinement // --- non-bonded contacts --- - auto atom_to_coord_orth = [] (mmdb::Atom *at) { return clipper::Coord_orth(at->x, at->y, at->z); }; + auto atom_to_coord_orth = [] (mmdb::Atom *at) { return clipper::Coord_orth(at->x(), at->y(), at->z()); }; std::map::const_iterator it; unsigned int idx = 0; @@ -2781,9 +2781,9 @@ coot::restraints_container_t::mark_OXT(const coot::protein_geometry &geom) { std::string oxt(" OXT"); for (int i=0; iname) == oxt) { + if (std::string(atom[i]->GetAtomName()) == oxt) { - mmdb::Residue *residue = atom[i]->residue; + mmdb::Residue *residue = atom[i]->GetResidue(); mmdb::Atom *res_atom = NULL; std::string res_name = residue->GetResName(); @@ -2848,7 +2848,7 @@ coot::restraints_container_t::make_non_bonded_fixed_flags(int index1, int index2 } if (! set_0) { - mmdb::Residue *res = atom[index1]->residue; + mmdb::Residue *res = atom[index1]->GetResidue(); if (std::find(non_bonded_neighbour_residues.begin(), non_bonded_neighbour_residues.end(), res) != non_bonded_neighbour_residues.end()) @@ -2856,7 +2856,7 @@ coot::restraints_container_t::make_non_bonded_fixed_flags(int index1, int index2 // then that atom of that residue is fixed } if (! set_1) { - mmdb::Residue *res = atom[index2]->residue; + mmdb::Residue *res = atom[index2]->GetResidue(); if (std::find(non_bonded_neighbour_residues.begin(), non_bonded_neighbour_residues.end(), res) != non_bonded_neighbour_residues.end()) @@ -2913,7 +2913,7 @@ coot::restraints_container_t::peptide_C_and_N_are_in_order_p(mmdb::Residue *r1, bool debug = false; if (r1->chain == r2->chain) { - int serial_delta = r2->index - r1->index; + int serial_delta = r2->GetIndex() - r1->GetIndex(); if (debug) std::cout << " serial_delta " << serial_delta << std::endl; if ((serial_delta == -1) || (serial_delta == 1)) { @@ -3004,7 +3004,7 @@ coot::restraints_container_t::peptide_C_and_N_are_close_p(mmdb::Residue *r1, mmd r2->GetAtomTable(residue_atoms_2, n_residue_atoms_2); for (int iat=0; iatname); + std::string atom_name(residue_atoms_1[iat]->GetAtomName()); if (atom_name == C_atom_name) { at_c_1 = residue_atoms_1[iat]; } @@ -3014,7 +3014,7 @@ coot::restraints_container_t::peptide_C_and_N_are_close_p(mmdb::Residue *r1, mmd } for (int iat=0; iatname); + std::string atom_name(residue_atoms_2[iat]->GetAtomName()); if (atom_name == C_atom_name) { at_c_2 = residue_atoms_2[iat]; } @@ -3024,8 +3024,8 @@ coot::restraints_container_t::peptide_C_and_N_are_close_p(mmdb::Residue *r1, mmd } if (at_c_1 && at_n_2) { - clipper::Coord_orth c1(at_c_1->x, at_c_1->y, at_c_1->z); - clipper::Coord_orth n2(at_n_2->x, at_n_2->y, at_n_2->z); + clipper::Coord_orth c1(at_c_1->x(), at_c_1->y(), at_c_1->z()); + clipper::Coord_orth n2(at_n_2->x(), at_n_2->y(), at_n_2->z()); float d = clipper::Coord_orth::length(c1, n2); // std::cout << " C1->N2 dist " << d << std::endl; if (d < dist_crit) @@ -3033,8 +3033,8 @@ coot::restraints_container_t::peptide_C_and_N_are_close_p(mmdb::Residue *r1, mmd } if (at_n_1 && at_c_2) { - clipper::Coord_orth n1(at_n_1->x, at_n_1->y, at_n_1->z); - clipper::Coord_orth c2(at_c_2->x, at_c_2->y, at_c_2->z); + clipper::Coord_orth n1(at_n_1->x(), at_n_1->y(), at_n_1->z()); + clipper::Coord_orth c2(at_c_2->x(), at_c_2->y(), at_c_2->z()); float d = clipper::Coord_orth::length(n1, c2); // std::cout << " N1->C2 dist " << d << std::endl; if (d < dist_crit) @@ -3265,7 +3265,7 @@ coot::restraints_container_t::make_non_bonded_contact_restraints(int imol, const std::cout << " non-bonded list:" << std::endl; std::cout << "--------------------------------------------------\n"; for (unsigned int i=0; iGetSeqNum() << " " << atom[i]->name << " : "; + std::cout << i << " " << atom[i]->GetSeqNum() << " " << atom[i]->GetAtomName() << " : "; for (unsigned int j=0; jGetResName(); std::map >::const_iterator it; - it = restraints_map.find(at->residue); + it = restraints_map.find(at->GetResidue()); if (it == restraints_map.end()) { // have_restraints_for() is faster? std::pair p = geom.get_monomer_restraints(res_type, imol); // p.first is false if this is not a filled dictionary - restraints_map[at->residue] = p; + restraints_map[at->GetResidue()] = p; } } @@ -3323,7 +3323,7 @@ coot::restraints_container_t::make_non_bonded_contact_restraints(int imol, const // it is not clear to me what it is now]. This needs to // be investigated/fixed. // - if (at_2->residue == at_1->residue) + if (at_2->GetResidue() == at_1->GetResidue()) if (is_hydrogen(at_1)) if (is_hydrogen(at_2)) add_it = false; @@ -3353,7 +3353,7 @@ coot::restraints_container_t::make_non_bonded_contact_restraints(int imol, const int res_no_pro = res_no_1; int res_no_other = res_no_2; if (res_no_pro == (res_no_other + 1)) { - std::string atom_name = at_1->name; + std::string atom_name = at_1->GetAtomName(); if (atom_name == " CD ") { // PDBv3 FIXME add_it = false; } @@ -3363,7 +3363,7 @@ coot::restraints_container_t::make_non_bonded_contact_restraints(int imol, const int res_no_pro = res_no_2; int res_no_other = res_no_1; if (res_no_pro == (res_no_other + 1)) { - std::string atom_name = at_2->name; + std::string atom_name = at_2->GetAtomName(); if (atom_name == " CD ") { // PDBv3 FIXME add_it = false; } @@ -3374,8 +3374,8 @@ coot::restraints_container_t::make_non_bonded_contact_restraints(int imol, const // hack to remove C1-OD1 NBC on N-linked glycosylation // if (res_name_1 == "ASN" || res_name_2 == "NAG") { - std::string atom_name_1(at_1->name); - std::string atom_name_2(at_2->name); + std::string atom_name_1(at_1->GetAtomName()); + std::string atom_name_2(at_2->GetAtomName()); if (atom_name_1 == " OD1") if (atom_name_2 == " C1 ") add_it = false; @@ -3385,8 +3385,8 @@ coot::restraints_container_t::make_non_bonded_contact_restraints(int imol, const } if (res_name_1 == "NAG" || res_name_2 == "ASN") { - std::string atom_name_1(at_1->name); - std::string atom_name_2(at_2->name); + std::string atom_name_1(at_1->GetAtomName()); + std::string atom_name_2(at_2->GetAtomName()); if (atom_name_1 == " C1 ") if (atom_name_2 == " OD1") add_it = false; @@ -3405,7 +3405,7 @@ coot::restraints_container_t::make_non_bonded_contact_restraints(int imol, const bool in_same_ring_flag = true; bool in_same_residue_flag = true; - if (at_2->residue != at_1->residue) { + if (at_2->GetResidue() != at_1->GetResidue()) { in_same_ring_flag = false; in_same_residue_flag = false; } @@ -3417,7 +3417,7 @@ coot::restraints_container_t::make_non_bonded_contact_restraints(int imol, const // in_same_ring_flag = restraints_map[at_2->residue].second.in_same_ring(atom_name_1, // atom_name_2); - in_same_ring_flag = is_in_same_ring(imol, at_2->residue, + in_same_ring_flag = is_in_same_ring(imol, at_2->GetResidue(), residue_ring_map_cache, atom_name_1, atom_name_2, geom); } @@ -3562,8 +3562,8 @@ coot::restraints_container_t::make_non_bonded_contact_restraints(int imol, const } if (false) { // debug. - clipper::Coord_orth pt1(atom[i]->x, atom[i]->y, atom[i]->z); - clipper::Coord_orth pt2(at_2->x, at_2->y, at_2->z); + clipper::Coord_orth pt1(atom[i]->x(), atom[i]->y(), atom[i]->z()); + clipper::Coord_orth pt2(at_2->x(), at_2->y(), at_2->z()); double dd = sqrt((pt1-pt2).lengthsq()); std::pair nbc_dist = geom.get_nbc_dist(type_1, type_2, @@ -3997,7 +3997,7 @@ coot::restraints_container_t::check_for_O_C_1_5_relation(mmdb::Atom *at_1, mmdb: // PDBv3 FIXME. bool match = false; - if (at_2->residue != at_1->residue) { + if (at_2->GetResidue() != at_1->GetResidue()) { // std::cout << "debug check_for_O_C_1_5_relation " << atom_spec_t(at_1) << " " << atom_spec_t(at_2) << std::endl; @@ -4391,17 +4391,17 @@ coot::restraints_container_t::add_N_terminal_residue_bonds_and_angles_to_hydroge if (atom_name == " H1 ") { int ai; at->GetUDData(udd_atom_index_handle, ai); - h1s[at->altLoc] = ai; + h1s[at->altLoc()] = ai; } if (atom_name == " H2 ") { int ai; at->GetUDData(udd_atom_index_handle, ai); - h2s[at->altLoc] = ai; + h2s[at->altLoc()] = ai; } if (atom_name == " H3 ") { int ai; at->GetUDData(udd_atom_index_handle, ai); - h3s[at->altLoc] = ai; + h3s[at->altLoc()] = ai; } } } @@ -4514,7 +4514,7 @@ coot::restraints_container_t::get_atom_index_for_restraint_using_alt_conf(const mmdb::Atom *at = res_selection[i]; std::string n(at->GetAtomName()); if (n == atom_name) { - std::string a(at->altLoc); + std::string a(at->altLoc()); if (a.empty() || a == alt_conf) { at->GetUDData(udd_atom_index_handle, idx); } @@ -4779,9 +4779,9 @@ coot::restraints_container_t::setup_gsl_vector_variables() { for (int i=0; ix); - gsl_vector_set(x, idx+1, atom[i]->y); - gsl_vector_set(x, idx+2, atom[i]->z); + gsl_vector_set(x, idx, atom[i]->x()); + gsl_vector_set(x, idx+1, atom[i]->y()); + gsl_vector_set(x, idx+2, atom[i]->z()); } } @@ -4794,7 +4794,7 @@ coot::restraints_container_t::update_atoms(gsl_vector *s) { int idx; if (false) { - std::cout << "update_atom(0): from " << atom[0]->x << " " << atom[0]->y << " " << atom[0]->z + std::cout << "update_atom(0): from " << atom[0]->x() << " " << atom[0]->y() << " " << atom[0]->z() << std::endl; double xx = gsl_vector_get(s, 0); double yy = gsl_vector_get(s, 1); @@ -4807,9 +4807,9 @@ coot::restraints_container_t::update_atoms(gsl_vector *s) { } else { for (int i=0; ix = gsl_vector_get(s,idx); - atom[i]->y = gsl_vector_get(s,idx+1); - atom[i]->z = gsl_vector_get(s,idx+2); + atom[i]->x() = gsl_vector_get(s,idx); + atom[i]->y() = gsl_vector_get(s,idx+1); + atom[i]->z() = gsl_vector_get(s,idx+2); } } } @@ -4830,9 +4830,9 @@ coot::restraints_container_t::position_OXT() { oxt_reference_atom_pos[1], oxt_reference_atom_pos[2], 1.231, angl_o, tors_o + M_PI); - atom[oxt_index]->x = oxt_pos.x(); - atom[oxt_index]->y = oxt_pos.y(); - atom[oxt_index]->z = oxt_pos.z(); + atom[oxt_index]->x() = oxt_pos.x(); + atom[oxt_index]->y() = oxt_pos.y(); + atom[oxt_index]->z() = oxt_pos.z(); } } diff --git a/ideal/simple-restraint.hh b/ideal/simple-restraint.hh index d868ce8602..df36573492 100644 --- a/ideal/simple-restraint.hh +++ b/ideal/simple-restraint.hh @@ -2192,7 +2192,7 @@ namespace coot { const gsl_vector *v) const; bool is_hydrogen(mmdb::Atom *at_p) const { - std::string ele = at_p->element; + std::string ele = at_p->GetElementName(); if ((ele == "H") || (ele == " H")) return true; else @@ -2203,7 +2203,7 @@ namespace coot { std::string get_type_energy(int imol, mmdb::Atom *at, const protein_geometry &geom) const { std::string r; if (at) { - std::string atom_name = at->name; + std::string atom_name = at->GetAtomName(); const char *rn = at->GetResName(); if (rn) { std::string residue_name = rn; @@ -2293,9 +2293,9 @@ namespace coot { dist_crit_for_bonded_pairs = 3.0; for (int i=0; ix; - initial_position_params_vec[3*i+1] = asc_in.atom_selection[i]->y; - initial_position_params_vec[3*i+2] = asc_in.atom_selection[i]->z; + initial_position_params_vec[3*i ] = asc_in.atom_selection[i]->x(); + initial_position_params_vec[3*i+1] = asc_in.atom_selection[i]->y(); + initial_position_params_vec[3*i+2] = asc_in.atom_selection[i]->z(); } } diff --git a/ideal/torsion-bonds.cc b/ideal/torsion-bonds.cc index c119e02f26..71015fc58f 100644 --- a/ideal/torsion-bonds.cc +++ b/ideal/torsion-bonds.cc @@ -53,7 +53,7 @@ coot::torsionable_bonds(int imol, mmdb::Manager *mol, mmdb::PPAtom atom_selectio std::map > atoms_in_residue; // fill residues and atoms_in_residue for (int i=0; iresidue; + mmdb::Residue *r = atom_selection[i]->GetResidue(); if (std::find(residues.begin(), residues.end(), r) == residues.end()) residues.push_back(r); atoms_in_residue[r].push_back(i); @@ -209,7 +209,7 @@ coot::torsionable_quads(int imol, mmdb::Manager *mol, mmdb::PPAtom atom_selectio std::vector quads; std::vector residues; for (int i=0; iresidue; + mmdb::Residue *r = atom_selection[i]->GetResidue(); if (std::find(residues.begin(), residues.end(), r) == residues.end()) residues.push_back(r); } @@ -397,12 +397,12 @@ coot::torsionable_link_quads(int imol, // What are the neightbours of link_atom_1 (and link_atom_2)? // Try to find a non-hydrogen atom to which it is bonded. bool H_flag = false; - std::string atom_name_1 = link_atom_1->name; - std::string atom_name_2 = link_atom_2->name; + std::string atom_name_1 = link_atom_1->GetAtomName(); + std::string atom_name_2 = link_atom_2->GetAtomName(); std::vector n1; std::vector n2; - n1 = res_restraints[link_atom_1->residue].neighbours(atom_name_1, H_flag); - n2 = res_restraints[link_atom_2->residue].neighbours(atom_name_2, H_flag); + n1 = res_restraints[link_atom_1->GetResidue()].neighbours(atom_name_1, H_flag); + n2 = res_restraints[link_atom_2->GetResidue()].neighbours(atom_name_2, H_flag); if (n1.size() && n2.size()) { std::string neigbhour_1_name = n1[0]; std::string neigbhour_2_name = n2[0]; @@ -418,7 +418,7 @@ coot::torsionable_link_quads(int imol, // also we need psi, CB, CG, ND2, C1 (of NAG) // std::vector n3; - n3 = res_restraints[link_atom_2->residue].neighbours(atom_name_2, H_flag); + n3 = res_restraints[link_atom_2->GetResidue()].neighbours(atom_name_2, H_flag); if (n3.size()) { mmdb::Atom *n_at_3 = bpc[i].res_2->GetAtom(n3[0].c_str()); if (n_at_3) { @@ -487,7 +487,7 @@ coot::multi_residue_torsion_fit_map(int imol, mol->GetSelIndex(selhnd, atom_selection, n_selected_atoms); std::vector > atoms(n_selected_atoms); // for density fitting for (int iat=0; iatelement, atom_numbers); + int atomic_number = util::atomic_number(atom_selection[iat]->GetElementName(), atom_numbers); float z = atomic_number; if (atomic_number == -1) z = 6.0f; @@ -654,8 +654,8 @@ coot::multi_residue_torsion_fit_map(int imol, int n_atoms = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - at->tempFactor = this_score * 0.4; - at->tempFactor = self_clash_score; + at->tempFactor() = this_score * 0.4; + at->tempFactor() = self_clash_score; } } } @@ -759,19 +759,19 @@ coot::get_self_clash_score(mmdb::Manager *mol, if (pscontact[i].id1 < pscontact[i].id2) { mmdb::Atom *at_1 = atom_selection[pscontact[i].id1]; mmdb::Atom *at_2 = atom_selection[pscontact[i].id2]; - if (at_1->residue != at_2->residue) { - std::string e1 = at_1->element; - std::string e2 = at_2->element; + if (at_1->GetResidue() != at_2->GetResidue()) { + std::string e1 = at_1->GetElementName(); + std::string e2 = at_2->GetElementName(); if ((e1 != " H") && (e2 != " H")) { // PDB vs 3 FIXME // ignore bumps to O5 (e.g. O4(prev)-O5(new)) on newly added residue - std::string atom_name_2 = at_2->name; + std::string atom_name_2 = at_2->GetAtomName(); if (atom_name_2 != " O5 ") { double d_sqd = - (at_1->x-at_2->x) * (at_1->x-at_2->x) + - (at_1->y-at_2->y) * (at_1->y-at_2->y) + - (at_1->z-at_2->z) * (at_1->z-at_2->z); + (at_1->x()-at_2->x()) * (at_1->x()-at_2->x()) + + (at_1->y()-at_2->y()) * (at_1->y()-at_2->y()) + + (at_1->z()-at_2->z()) * (at_1->z()-at_2->z()); // are they either in a bond, angle or torsion of any of quads? // diff --git a/ideal/trans-peptide.cc b/ideal/trans-peptide.cc index 1b00d4b2a5..3f07708cb4 100644 --- a/ideal/trans-peptide.cc +++ b/ideal/trans-peptide.cc @@ -70,19 +70,19 @@ coot::restraints_container_t::add_link_trans_peptide(mmdb::Residue *first, fixed_flags[3] = is_fixed_second; for (int ifat=0; ifatname); + std::string pdb_atom_name_1(atom_1_sel[ifat]->GetAtomName()); if (pdb_atom_name_1 == " CA ") { for (int isat=0; isatname); + std::string pdb_atom_name_2(atom_2_sel[isat]->GetAtomName()); if (pdb_atom_name_2 == " C ") { for (int itat=0; itatname); + std::string pdb_atom_name_3(atom_3_sel[itat]->GetAtomName()); if (pdb_atom_name_3 == " N ") { for (int iffat=0; iffatname); + std::string pdb_atom_name_4(atom_4_sel[iffat]->GetAtomName()); if (pdb_atom_name_4 == " CA ") { @@ -94,13 +94,13 @@ coot::restraints_container_t::add_link_trans_peptide(mmdb::Residue *first, if (false) std::cout << "trans-peptide restraint.... " << " from atoms \n " - << atom_1_sel[ifat]->name << " " + << atom_1_sel[ifat]->GetAtomName() << " " << atom_1_sel[ifat]->GetSeqNum() << "\n " - << atom_2_sel[isat]->name << " " + << atom_2_sel[isat]->GetAtomName() << " " << atom_2_sel[isat]->GetSeqNum() << "\n " - << atom_3_sel[itat]->name << " " + << atom_3_sel[itat]->GetAtomName() << " " << atom_3_sel[itat]->GetSeqNum() << "\n " - << atom_4_sel[iffat]->name << " " + << atom_4_sel[iffat]->GetAtomName() << " " << atom_4_sel[iffat]->GetSeqNum() << "\n"; // if the angle is currently trans, the we should add a @@ -388,10 +388,10 @@ coot::restraints_container_t::add_trans_peptide_restraint(mmdb::Residue *first, for (unsigned int i=0; i<=n_rest; i++) { simple_restraint &restraint = restraints_vec[i]; if (restraint.restraint_type == coot::TRANS_PEPTIDE_RESTRAINT) { - mmdb::Residue *r_11 = atom[restraint.atom_index_1]->residue; - mmdb::Residue *r_12 = atom[restraint.atom_index_2]->residue; - mmdb::Residue *r_21 = atom[restraint.atom_index_3]->residue; - mmdb::Residue *r_22 = atom[restraint.atom_index_4]->residue; + mmdb::Residue *r_11 = atom[restraint.atom_index_1]->GetResidue(); + mmdb::Residue *r_12 = atom[restraint.atom_index_2]->GetResidue(); + mmdb::Residue *r_21 = atom[restraint.atom_index_3]->GetResidue(); + mmdb::Residue *r_22 = atom[restraint.atom_index_4]->GetResidue(); if (r_11 == first) { if (r_12 == first) { if (r_21 == second) { @@ -422,10 +422,10 @@ coot::restraints_container_t::remove_trans_peptide_restraint(mmdb::Residue *firs for (unsigned int i=0; i<=n_rest; i++) { simple_restraint &restraint = restraints_vec[i]; if (restraint.restraint_type == coot::TRANS_PEPTIDE_RESTRAINT) { - mmdb::Residue *r_11 = atom[restraint.atom_index_1]->residue; - mmdb::Residue *r_12 = atom[restraint.atom_index_2]->residue; - mmdb::Residue *r_21 = atom[restraint.atom_index_3]->residue; - mmdb::Residue *r_22 = atom[restraint.atom_index_4]->residue; + mmdb::Residue *r_11 = atom[restraint.atom_index_1]->GetResidue(); + mmdb::Residue *r_12 = atom[restraint.atom_index_2]->GetResidue(); + mmdb::Residue *r_21 = atom[restraint.atom_index_3]->GetResidue(); + mmdb::Residue *r_22 = atom[restraint.atom_index_4]->GetResidue(); if (r_11 == first) { if (r_12 == first) { if (r_21 == second) { diff --git a/lidia-core/bond-record-container-t.hh b/lidia-core/bond-record-container-t.hh index a6ba6b5941..088c04e936 100644 --- a/lidia-core/bond-record-container-t.hh +++ b/lidia-core/bond-record-container-t.hh @@ -99,7 +99,7 @@ namespace cod { bool db_add_level_4_types(sqlite3 *db); #endif // USE_SQLITE3 - clipper::Coord_orth co(mmdb::Atom *at) const { return clipper::Coord_orth(at->x, at->y, at->z); } + clipper::Coord_orth co(mmdb::Atom *at) const { return clipper::Coord_orth(at->x(), at->y(), at->z()); } public: bond_record_container_t() {} diff --git a/lidia-core/chemical-feature-clusters.hh b/lidia-core/chemical-feature-clusters.hh index fb42cc947b..01b4d0b065 100644 --- a/lidia-core/chemical-feature-clusters.hh +++ b/lidia-core/chemical-feature-clusters.hh @@ -111,7 +111,7 @@ namespace coot { unsigned int water_spec_idx; mmdb::Atom *atom_p; clipper::Coord_orth pos; - residue_spec_t residue_spec() const { return residue_spec_t(atom_p->residue) ; } + residue_spec_t residue_spec() const { return residue_spec_t(atom_p->GetResidue()) ; } }; private: diff --git a/lidia-core/get-residue.cc b/lidia-core/get-residue.cc index 82402fe98e..e28c8add29 100644 --- a/lidia-core/get-residue.cc +++ b/lidia-core/get-residue.cc @@ -68,5 +68,5 @@ coot::lidia_utils::get_residue(const coot::residue_spec_t &res_spec, mmdb::Manag clipper::Coord_orth coot::lidia_utils::co(mmdb::Atom *at) { - return clipper::Coord_orth(at->x, at->y, at->z); + return clipper::Coord_orth(at->x(), at->y(), at->z()); } diff --git a/lidia-core/lbg-molfile.cc b/lidia-core/lbg-molfile.cc index ff0b8756d7..3d4e70a3c5 100644 --- a/lidia-core/lbg-molfile.cc +++ b/lidia-core/lbg-molfile.cc @@ -290,12 +290,12 @@ lig_build::molfile_molecule_t::molfile_molecule_t(mmdb::Residue *residue_p, atoms.push_back(blank_atom); // blank atom for 0-index. // make the atoms for (int iat=0; iatx, - residue_atoms[iat]->y, - residue_atoms[iat]->z); + clipper::Coord_orth pos(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); molfile_atom_t atom(pos, - residue_atoms[iat]->element, - residue_atoms[iat]->name); + residue_atoms[iat]->GetElementName(), + residue_atoms[iat]->GetAtomName()); atoms.push_back(atom); } @@ -305,7 +305,7 @@ lig_build::molfile_molecule_t::molfile_molecule_t(mmdb::Residue *residue_p, std::map >::const_iterator it_2_atom_map; std::map atom_index_map; for (int iat=0; iatname].push_back(residue_atoms[iat]); + atom_map[residue_atoms[iat]->GetAtomName()].push_back(residue_atoms[iat]); atom_index_map[residue_atoms[iat]] = iat; } @@ -321,10 +321,10 @@ lig_build::molfile_molecule_t::molfile_molecule_t(mmdb::Residue *residue_p, const std::vector &v_1 = it_1_atom_map->second; const std::vector &v_2 = it_2_atom_map->second; for (unsigned int iat_1=0; iat_1altLoc; + std::string alt_conf_1 = v_1[iat_1]->altLoc(); if (alt_conf_1 == "") { for (unsigned int iat_2=0; iat_2altLoc; + std::string alt_conf_2 = v_2[iat_2]->altLoc(); if (alt_conf_2 == "") { // OK, so we have a bond, these are indices diff --git a/lidia-core/rdkit-interface.cc b/lidia-core/rdkit-interface.cc index 2856cd89e7..035770b5b9 100644 --- a/lidia-core/rdkit-interface.cc +++ b/lidia-core/rdkit-interface.cc @@ -99,7 +99,7 @@ coot::rdkit_mol(mmdb::Residue *residue_p, for (int iat=0; iatisTer()) { - std::string alt_conf = at->altLoc; + std::string alt_conf = at->altLoc(); if (std::find(v.begin(), v.end(), alt_conf) == v.end()) { v.push_back(alt_conf); } @@ -160,8 +160,8 @@ coot::rdkit_mol(mmdb::Residue *residue_p, for (int iat_1=0; iat_1Ter) { - std::string atom_name_1(at_1->name); - std::string atom_alt_conf(at_1->altLoc); + std::string atom_name_1(at_1->GetAtomName()); + std::string atom_alt_conf(at_1->altLoc()); if (debug) std::cout << "rdkit_mol() handling atom " << iat_1 << " of " << n_residue_atoms << " with mmdb::Residue atom name " << atom_name_1 @@ -174,7 +174,7 @@ coot::rdkit_mol(mmdb::Residue *residue_p, // atoms of the residue? for (int iat_2=0; iat_2name; + std::string atom_name_2 = at_2->GetAtomName(); if (atom_name_2 == restraints.bond_restraint[ib].atom_id_2_4c()) { found_a_bonded_atom = true; break; @@ -186,7 +186,7 @@ coot::rdkit_mol(mmdb::Residue *residue_p, // atoms of the residue? for (int iat_2=0; iat_2name; + std::string atom_name_2 = at_2->GetAtomName(); if (atom_name_2 == restraints.bond_restraint[ib].atom_id_1_4c()) { found_a_bonded_atom = true; break; @@ -236,7 +236,7 @@ coot::rdkit_mol(mmdb::Residue *residue_p, for (unsigned int iat=0; iatname); + std::string atom_name(at->GetAtomName()); if (debug) std::cout << " handling atom " << iat << " of " << n_residue_atoms << " bonded_atoms " << atom_name << " "; @@ -251,7 +251,7 @@ coot::rdkit_mol(mmdb::Residue *residue_p, RDKit::Atom *rdkit_at = new RDKit::Atom; try { std::string ele_capped = - coot::util::capitalise(coot::util::remove_leading_spaces(at->element)); + coot::util::capitalise(coot::util::remove_leading_spaces(at->GetElementName())); int atomic_number = tbl->getAtomicNumber(ele_capped); rdkit_at->setAtomicNum(atomic_number); // rdkit_at->setMass(tbl->getAtomicWeight(atomic_number)); @@ -268,7 +268,7 @@ coot::rdkit_mol(mmdb::Residue *residue_p, // set the valence from they type energy. Abstract? // - std::string type_energy = restraints.type_energy(at->name); + std::string type_energy = restraints.type_energy(at->GetAtomName()); if (type_energy != "") { if (type_energy == "NT") { bool charge_it = true; @@ -892,14 +892,14 @@ coot::rdkit_mol(mmdb::Residue *residue_p, // atom with a particular atom name). // for (int iat=0; iatname); - std::string atom_alt_conf(residue_atoms[iat]->altLoc); + std::string atom_name(residue_atoms[iat]->GetAtomName()); + std::string atom_alt_conf(residue_atoms[iat]->altLoc()); if (true) { // was alt-conf test std::map::const_iterator it = atom_index.find(atom_name); if (it != atom_index.end()) { - RDGeom::Point3D pos(residue_atoms[iat]->x, - residue_atoms[iat]->y, - residue_atoms[iat]->z); + RDGeom::Point3D pos(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); conf->setAtomPos(it->second, pos); if (debug) std::cout << "in construction of rdkit mol: making a conformer atom " @@ -979,7 +979,7 @@ coot::set_atom_chirality(RDKit::Atom *rdkit_at, // bool done_chiral = false; - std::string atom_name = at->name; + std::string atom_name = at->GetAtomName(); for (unsigned int ichi=0; ichiGetAtomTable(residue_atoms, n_residue_atoms); - std::string atom_name = atom_p->name; + std::string atom_name = atom_p->GetAtomName(); bool debug = false; // To make RDKit/SMILES chiral tags, we consider the order of the 3 @@ -1567,7 +1567,7 @@ coot::get_chiral_tag(mmdb::Residue *residue_p, bool atom_orders_match = false; for (int iat=0; iatname; + std::string atom_name_local = residue_atoms[iat]->GetAtomName(); if (atom_name_local == chiral_restraint.atom_id_1_4c()) { ni[1] = iat; n_neigbours_found++; @@ -1662,7 +1662,7 @@ coot::get_chiral_tag_v2(mmdb::Residue *residue_p, mmdb::PPAtom residue_atoms = 0; int n_residue_atoms; residue_p->GetAtomTable(residue_atoms, n_residue_atoms); - std::string atom_name = atom_p->name; + std::string atom_name = atom_p->GetAtomName(); std::cout << "Called get_chiral_tag_v2() whti atom name " << atom_name << std::endl; @@ -1680,7 +1680,7 @@ coot::get_chiral_tag_v2(mmdb::Residue *residue_p, mmdb::Atom *at = residue_atoms[iat]; if (! at->isTer()) { mmdb::Atom *chiral_atom = 0; - std::string atom_name_local(at->name); + std::string atom_name_local(at->GetAtomName()); if (atom_name_local == cr.atom_id_c_4c()) { chiral_atom = at; } @@ -1709,7 +1709,7 @@ coot::get_chiral_tag_v2(mmdb::Residue *residue_p, if (! other_atom.empty()) { for (int iat=0; iatname); + std::string atom_name_local(at->GetAtomName()); if (0) std::cout << iat << " comparing :" << atom_name_local << ": :" << other_atom << ":" << std::endl; @@ -2146,7 +2146,7 @@ coot::make_residue(const RDKit::ROMol &rdkm, int iconf, const std::string &res_n // if (mol.atoms.size()) { residue_p = new mmdb::Residue; - residue_p->seqNum = 1; + residue_p->GetSeqNum() = 1; residue_p->SetResName(res_name.c_str()); mmdb::Chain *chain_p = new mmdb::Chain; chain_p->SetChainID(""); @@ -2405,9 +2405,9 @@ coot::add_hydrogens_with_rdkit(mmdb::Residue *residue_p, residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatisTer()) { - std::string ele = residue_atoms[iat]->element; + std::string ele = residue_atoms[iat]->GetElementName(); if (ele == " H") - existing_H_names.push_back(residue_atoms[iat]->name); + existing_H_names.push_back(residue_atoms[iat]->GetAtomName()); } } @@ -2476,9 +2476,9 @@ coot::add_hydrogens_with_rdkit(mmdb::Residue *residue_p, if (res_atom) { std::cout << "setting heavy atom " << name << " to " << r_pos << std::endl; - res_atom->x = r_pos.x; - res_atom->y = r_pos.y; - res_atom->z = r_pos.z; + res_atom->x() = r_pos.x; + res_atom->y() = r_pos.y; + res_atom->z() = r_pos.z; } } @@ -2511,7 +2511,7 @@ coot::add_hydrogens_with_rdkit(mmdb::Residue *residue_p, at->SetCoordinates(r_pos.x, r_pos.y, r_pos.z, 1.0, 30.0); at->Het = 1; if (alt_conf != "") { - strncpy(at->altLoc, alt_conf.c_str(), alt_conf.length()+1); + strncpy(at->altLoc(), alt_conf.c_str(), alt_conf.length()+1); } residue_p->AddAtom(at); r = 1; @@ -3697,7 +3697,7 @@ void coot::update_coords(RDKit::RWMol *mol_p, int iconf, mmdb::Residue *residue_ residue_p->GetAtomTable(residue_atoms, n_atoms); RDKit::Conformer &conf = mol_p->getConformer(iconf); for (int iat=0; iatname); + std::string residue_atom_name(residue_atoms[iat]->GetAtomName()); mmdb::Atom *r_at = residue_atoms[iat]; for (int jat=0; jatgetProp("name", rdkit_atom_name); if (rdkit_atom_name == residue_atom_name) { - RDGeom::Point3D r_pos(r_at->x, r_at->y, r_at->z); + RDGeom::Point3D r_pos(r_at->x(), r_at->y(), r_at->z()); conf.setAtomPos(jat, r_pos); } } diff --git a/ligand/backrub-rotamer.cc b/ligand/backrub-rotamer.cc index b4223665b9..3fc3579747 100644 --- a/ligand/backrub-rotamer.cc +++ b/ligand/backrub-rotamer.cc @@ -208,9 +208,9 @@ coot::backrub::rotamer_residue_centre() const { orig_this_residue->GetAtomTable(residue_atoms, n_residue_atoms); float sum_x=0, sum_y=0, sum_z=0; for (int iat=0; iatx; - sum_y += residue_atoms[iat]->y; - sum_z += residue_atoms[iat]->z; + sum_x += residue_atoms[iat]->x(); + sum_y += residue_atoms[iat]->y(); + sum_z += residue_atoms[iat]->z(); } if (n_residue_atoms > 0) { float inv = 1.0/float(n_residue_atoms); @@ -231,9 +231,9 @@ coot::backrub::residue_radius(const clipper::Coord_orth &rc) { orig_this_residue->GetAtomTable(residue_atoms, n_residue_atoms); float longest_length = 0.0; for (int iat=0; iatx - rc.x(), - residue_atoms[iat]->y - rc.y(), - residue_atoms[iat]->z - rc.z()); + clipper::Coord_orth pt(residue_atoms[iat]->x() - rc.x(), + residue_atoms[iat]->y() - rc.y(), + residue_atoms[iat]->z() - rc.z()); float this_length_sq = pt.lengthsq(); if (this_length_sq > longest_length) { longest_length = this_length_sq; @@ -303,14 +303,14 @@ coot::backrub::setup_this_and_prev_next_ca_positions() { orig_this_residue->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); - std::string atom_alt_conf(residue_atoms[iat]->altLoc); + std::string atom_name(residue_atoms[iat]->GetAtomName()); + std::string atom_alt_conf(residue_atoms[iat]->altLoc()); if (atom_name == " CA " ) { if (atom_alt_conf == alt_conf) { found = 1; - ca_this = clipper::Coord_orth(residue_atoms[iat]->x, - residue_atoms[iat]->y, - residue_atoms[iat]->z); + ca_this = clipper::Coord_orth(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); } } } @@ -324,14 +324,14 @@ coot::backrub::setup_this_and_prev_next_ca_positions() { orig_prev_residue->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); - std::string atom_alt_conf(residue_atoms[iat]->altLoc); + std::string atom_name(residue_atoms[iat]->GetAtomName()); + std::string atom_alt_conf(residue_atoms[iat]->altLoc()); if (atom_name == " CA " ) { if (atom_alt_conf == alt_conf) { found = 1; - ca_prev = clipper::Coord_orth(residue_atoms[iat]->x, - residue_atoms[iat]->y, - residue_atoms[iat]->z); + ca_prev = clipper::Coord_orth(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); } } } @@ -347,14 +347,14 @@ coot::backrub::setup_this_and_prev_next_ca_positions() { residue_atoms = 0; orig_next_residue->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); - std::string atom_alt_conf(residue_atoms[iat]->altLoc); + std::string atom_name(residue_atoms[iat]->GetAtomName()); + std::string atom_alt_conf(residue_atoms[iat]->altLoc()); if (atom_name == " CA " ) { if (atom_alt_conf == alt_conf) { found = 1; - ca_next = clipper::Coord_orth(residue_atoms[iat]->x, - residue_atoms[iat]->y, - residue_atoms[iat]->z); + ca_next = clipper::Coord_orth(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); } } } @@ -419,12 +419,12 @@ coot::backrub::sample_individual_peptide(mmdb::Residue *r, double rotation_angle residue_front->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); - std::string atom_alt_conf(residue_atoms[iat]->altLoc); + std::string atom_name(residue_atoms[iat]->GetAtomName()); + std::string atom_alt_conf(residue_atoms[iat]->altLoc()); if (atom_name == " O " ) { - O_pos = clipper::Coord_orth(residue_atoms[iat]->x, - residue_atoms[iat]->y, - residue_atoms[iat]->z); + O_pos = clipper::Coord_orth(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); found_O_pos = 1; } } @@ -617,9 +617,9 @@ coot::get_clash_score(const coot::minimol::molecule &a_rotamer, float badness; for (int i=0; ix, - asc.atom_selection[i]->y, - asc.atom_selection[i]->z); + clipper::Coord_orth atom_sel_atom(asc.atom_selection[i]->x(), + asc.atom_selection[i]->y(), + asc.atom_selection[i]->z()); d = clipper::Coord_orth::length(atom_sel_atom, mean_residue_pos); if (d < (max_dev_residue_pos + dist_crit)) { for (unsigned int ifrag=0; ifragx, - atom_selection[i]->y, - atom_selection[i]->z); + clipper::Coord_orth atom_sel_atom_pos(atom_selection[i]->x(), + atom_selection[i]->y(), + atom_selection[i]->z()); int atom_sel_resno = atom_selection[i]->GetSeqNum(); std::string atom_sel_atom_chain(atom_selection[i]->GetChainID()); - std::string atom_sel_ele = atom_selection[i]->element; + std::string atom_sel_ele = atom_selection[i]->GetElementName(); bool count_it = 1; if (chain_id == atom_sel_atom_chain) { if (atom_sel_resno==resno_1 || atom_sel_resno==resno_2 || atom_sel_resno==resno_3) { @@ -783,12 +783,12 @@ coot::backrub_molecule(mmdb::Manager *mol, const clipper::Xmap *xmap_p, c if (false) std::cout << "--------------- replacing coords for atom " << atom_spec_t(at) << " " - << at_mol->x << " " << at_mol->y << " " << at_mol->z << " " - << at->x << " " << at->y << " " << at->z << " " + << at_mol->x() << " " << at_mol->y() << " " << at_mol->z() << " " + << at->x() << " " << at->y() << " " << at->z() << " " << std::endl; - at_mol->x = at->x; - at_mol->y = at->y; - at_mol->z = at->z; + at_mol->x() = at->x(); + at_mol->y() = at->y(); + at_mol->z() = at->z(); } } } @@ -802,7 +802,7 @@ coot::backrub_molecule(mmdb::Manager *mol, const clipper::Xmap *xmap_p, c for (const auto &baddie_spec : baddie_waters) { mmdb::Atom *at = util::get_atom(baddie_spec, mol); if (at) { - mmdb::Residue *residue = at->residue; + mmdb::Residue *residue = at->GetResidue(); delete at; residue->TrimAtomTable(); } diff --git a/ligand/base-pairing.cc b/ligand/base-pairing.cc index 643c29da08..3d86bfa9ea 100644 --- a/ligand/base-pairing.cc +++ b/ligand/base-pairing.cc @@ -243,22 +243,22 @@ coot::base_pair_match_matix(mmdb::Residue *res_ref, mmdb::Residue *res_mov) { mmdb::Atom *at_ref = NULL; mmdb::Atom *at_mov = NULL; for (int iref=0; irefname; + std::string ref_atom_name = ref_atoms[iref]->GetAtomName(); if (ref_atom_name == base_atom_names[i]) { at_ref = ref_atoms[iref]; break; } } for (int imov=0; imovname; + std::string mov_atom_name = mov_atoms[imov]->GetAtomName(); if (mov_atom_name == base_atom_names[i]) { at_mov = mov_atoms[imov]; break; } } if (at_ref && at_mov) { - ref_pts.push_back(clipper::Coord_orth(at_ref->x, at_ref->y, at_ref->z)); - mov_pts.push_back(clipper::Coord_orth(at_mov->x, at_mov->y, at_mov->z)); + ref_pts.push_back(clipper::Coord_orth(at_ref->x(), at_ref->y(), at_ref->z())); + mov_pts.push_back(clipper::Coord_orth(at_mov->x(), at_mov->y(), at_mov->z())); } } diff --git a/ligand/chi-angles.cc b/ligand/chi-angles.cc index 251e0c45ee..93ffcdee89 100644 --- a/ligand/chi-angles.cc +++ b/ligand/chi-angles.cc @@ -456,15 +456,15 @@ coot::chi_angles::change_by(int ichi, double diff, coot::protein_geometry* geom_ mmdb::Atom *cd = 0; if (nResidueAtoms > 2) { for (int i=0; iname) == " N ") + if (std::string(residue_atoms[i]->GetAtomName()) == " N ") n = residue_atoms[i]; - if (std::string(residue_atoms[i]->name) == " CA ") + if (std::string(residue_atoms[i]->GetAtomName()) == " CA ") ca = residue_atoms[i]; - if (std::string(residue_atoms[i]->name) == " CB ") + if (std::string(residue_atoms[i]->GetAtomName()) == " CB ") cb = residue_atoms[i]; - if (std::string(residue_atoms[i]->name) == " CG ") + if (std::string(residue_atoms[i]->GetAtomName()) == " CG ") cg = residue_atoms[i]; - if (std::string(residue_atoms[i]->name) == " CD ") + if (std::string(residue_atoms[i]->GetAtomName()) == " CD ") cd = residue_atoms[i]; } @@ -478,11 +478,11 @@ coot::chi_angles::change_by(int ichi, double diff, coot::protein_geometry* geom_ ordered_residue_atoms[4] = cd; int atom_count = 5; for (int i=0; iname) == " N " || - std::string(residue_atoms[i]->name) == " CA " || - std::string(residue_atoms[i]->name) == " CB " || - std::string(residue_atoms[i]->name) == " CG " || - std::string(residue_atoms[i]->name) == " CD " ) { + if (std::string(residue_atoms[i]->GetAtomName()) == " N " || + std::string(residue_atoms[i]->GetAtomName()) == " CA " || + std::string(residue_atoms[i]->GetAtomName()) == " CB " || + std::string(residue_atoms[i]->GetAtomName()) == " CG " || + std::string(residue_atoms[i]->GetAtomName()) == " CD " ) { } else { ordered_residue_atoms[atom_count] = residue_atoms[i]; atom_count++; @@ -661,14 +661,14 @@ coot::chi_angles::change_by(int imol, mmdb::PPAtom residue_atoms; int nResidueAtoms; residue->GetAtomTable(residue_atoms, nResidueAtoms); - std::string residue_name = residue->name; + std::string residue_name = residue->GetResName(); // filter out CONST torsions when making atom_name_pairs std::vector atom_name_pairs = get_torsion_bonds_atom_pairs(residue_name, imol, pg_p, include_hydrogen_torsions_flag); if (atom_name_pairs.size() == 0) { std::cout << " Sorry, can't find atom rotatable bonds for residue type "; - std::cout << residue->name << "\n"; + std::cout << residue->GetResName() << "\n"; } else { if (nResidueAtoms == 0) { std::cout << " something broken in atom residue selection in "; @@ -704,9 +704,9 @@ coot::chi_angles::change_by_internal(int ichi, // std::vector< ::Cartesian > coords; for(int i=0; ix, - residue_atoms_in[i]->y, - residue_atoms_in[i]->z); + ::Cartesian c(residue_atoms_in[i]->x(), + residue_atoms_in[i]->y(), + residue_atoms_in[i]->z()); coords.push_back(c); } mmdb::PPAtom residue_atoms = residue_atoms_in; @@ -745,7 +745,7 @@ coot::chi_angles::change_by_internal(int ichi, // atom spec to find // the base atom for(int i=0; iname) { + if (tree_base_atom.atom_name == residue_atoms[i]->GetAtomName()) { base_index = i; // std::cout << "DEBUG:: Using tree based on atom: " // << tree_base_atom.atom_name << " index: " << base_index << std::endl; @@ -804,17 +804,17 @@ coot::chi_angles::change_by_internal(int ichi, for (int iat=0; iatx << ", " - << residue_atoms[iat]->y << ", " - << residue_atoms[iat]->z << ") to (" + << residue_atoms[iat]->x() << ", " + << residue_atoms[iat]->y() << ", " + << residue_atoms[iat]->z() << ") to (" << coords_rotatated[iat].get_x() << ", " << coords_rotatated[iat].get_y() << ", " << coords_rotatated[iat].get_z() << ")" << std::endl; } - residue_atoms[iat]->x = coords_rotatated[iat].get_x(); - residue_atoms[iat]->y = coords_rotatated[iat].get_y(); - residue_atoms[iat]->z = coords_rotatated[iat].get_z(); + residue_atoms[iat]->x() = coords_rotatated[iat].get_x(); + residue_atoms[iat]->y() = coords_rotatated[iat].get_y(); + residue_atoms[iat]->z() = coords_rotatated[iat].get_z(); } } } else { @@ -919,14 +919,14 @@ coot::chi_angles::get_atom_index_pairs(const std::vector & for (unsigned int ipair=0; ipairname; + std::string atomname = atoms[i]->GetAtomName(); if (atomname == atom_name_pairs[ipair].atom1) { i_store_index = i; } } if (i_store_index > -1) { // i.e. we found the first atom for(int i2=0; i2name; + std::string atomname = atoms[i2]->GetAtomName(); if (atomname == atom_name_pairs[ipair].atom2) { index_pairs.push_back(coot::atom_index_pair(i_store_index, i2)); } @@ -955,7 +955,7 @@ coot::chi_angles::get_atom_index_quads(const std::vector & int index_3 = -1; int index_4 = -1; for (int iat=0; iatname; + std::string atomname = atoms[iat]->GetAtomName(); if (atomname == atom_name_quads[iquad].atom_name(0)) index_1 = iat; if (atomname == atom_name_quads[iquad].atom_name(1)) diff --git a/ligand/dipole.cc b/ligand/dipole.cc index 397e151aab..df54d0165e 100644 --- a/ligand/dipole.cc +++ b/ligand/dipole.cc @@ -71,9 +71,9 @@ coot::dipole::init(std::vectorGetAtomTable(SelAtoms, nSelAtoms); for (int i_res_at=0; i_res_atx; - sum_y += SelAtoms[i_res_at]->y; - sum_z += SelAtoms[i_res_at]->z; + sum_x += SelAtoms[i_res_at]->x(); + sum_y += SelAtoms[i_res_at]->y(); + sum_z += SelAtoms[i_res_at]->z(); n_points++; } } @@ -106,9 +106,9 @@ coot::dipole::init(std::vector > charged_ats = charged_atoms(dict_res_pairs); std::vector > charged_points(charged_ats.size()); for (unsigned int i=0; ix, - charged_ats[i].first->y, - charged_ats[i].first->z); + clipper::Coord_orth p(charged_ats[i].first->x(), + charged_ats[i].first->y(), + charged_ats[i].first->z()); charged_points[i] = std::pair(charged_ats[i].second, p); } @@ -149,7 +149,7 @@ coot::dipole::fill_charged_atoms(mmdb::Residue *residue_p, std::vector > v = charged_atoms(residue_p, rest); for (unsigned int i=0; icharge = v[i].second; + v[i].first->charge() = v[i].second; } } @@ -166,7 +166,7 @@ coot::dipole::charged_atoms(mmdb::Residue *residue_p, for (int i_res_at=0; i_res_atname; + std::string atom_name = at->GetAtomName(); for (int j=0; jseqNum = 1 + iseq ; + res->GetSeqNum() = 1 + iseq ; clipper::RTop_orth o = n_turns(iseq, seq.length(), form_flag); coot::util::transform_atoms(res, o); int success = mutate_res(res, seq[iseq], is_dna_flag); @@ -127,7 +127,7 @@ coot::ideal_rna::make_molecule() { // antisense residue mmdb::Residue *res = coot::util::deep_copy_this_residue(antisense_ref); - res->seqNum = seq.length() - iseq; + res->GetSeqNum() = seq.length() - iseq; // antisense_chain_p->AddResidue(res); "backwards in pdb" clipper::RTop_orth o = n_turns(iseq, seq.length(), form_flag); coot::util::transform_atoms(res, o); @@ -177,7 +177,7 @@ coot::ideal_rna::fix_up_residue_and_atom_names(mmdb::Residue *residue_p, bool is residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname; + std::string atom_name = at->GetAtomName(); if (atom_name.length() > 3) { if (atom_name[3] == '*') { atom_name[3] = '\''; @@ -193,7 +193,7 @@ coot::ideal_rna::fix_up_residue_and_atom_names(mmdb::Residue *residue_p, bool is if (new_name == "DT") { for (int iat=0; iatname; + std::string atom_name = at->GetAtomName(); if (atom_name == " C5M") { at->SetAtomName(" C7 "); } @@ -448,7 +448,7 @@ coot::ideal_rna::delete_o2_prime(mmdb::Residue *res) const { if (res) { res->GetAtomTable(residue_atoms, natoms); for (int i=0; iname); + std::string atname(residue_atoms[i]->GetAtomName()); if (atname == " O2*") { res->DeleteAtom(i); deleted=1; @@ -486,7 +486,7 @@ coot::ideal_rna::add_o2_prime(mmdb::Residue *res) const { mmdb::Atom *c3p = NULL; res->GetAtomTable(residue_atoms, natoms); for (int i=0; iname); + std::string atname(residue_atoms[i]->GetAtomName()); if (atname == " C1'" || atname == " C1*") c1p = residue_atoms[i]; if (atname == " C2'" || atname == " C2*") @@ -497,9 +497,9 @@ coot::ideal_rna::add_o2_prime(mmdb::Residue *res) const { if (c1p && c2p && c3p) { // add o std::vector ref_pts; - ref_pts.push_back(clipper::Coord_orth(c1p->x, c1p->y, c1p->z)); - ref_pts.push_back(clipper::Coord_orth(c2p->x, c2p->y, c2p->z)); - ref_pts.push_back(clipper::Coord_orth(c3p->x, c3p->y, c3p->z)); + ref_pts.push_back(clipper::Coord_orth(c1p->x(), c1p->y(), c1p->z())); + ref_pts.push_back(clipper::Coord_orth(c2p->x(), c2p->y(), c2p->z())); + ref_pts.push_back(clipper::Coord_orth(c3p->x(), c3p->y(), c3p->z())); clipper::RTop_orth rtop(mov_pts, ref_pts); clipper::Coord_orth pos = o2p.transform(rtop); diff --git a/ligand/libres-tracer.cc b/ligand/libres-tracer.cc index d033ec628d..390a1dd302 100644 --- a/ligand/libres-tracer.cc +++ b/ligand/libres-tracer.cc @@ -168,7 +168,7 @@ spin_score(unsigned int idx_1, unsigned int idx_2, mmdb::Atom **atom_selection, auto index_to_pos = [atom_selection] (unsigned int idx) { mmdb::Atom *at = atom_selection[idx]; - return clipper::Coord_orth(at->x, at->y, at->z); + return clipper::Coord_orth(at->x(), at->y(), at->z()); }; float inv_rmsd = 1.0f/map_rmsd; @@ -463,8 +463,8 @@ spin_score(unsigned int idx_1, unsigned int idx_2, mmdb::Atom **atom_selection, bool using_test_model = false; // for testing if (using_test_model) { - std::string atom_name_1(at_1->name); - std::string atom_name_2(at_2->name); + std::string atom_name_1(at_1->GetAtomName()); + std::string atom_name_2(at_2->GetAtomName()); if (atom_name_1 == " CA ") { if (atom_name_2 == " CA ") { if ((at_1->GetSeqNum() + 1) == at_2->GetSeqNum()) @@ -563,7 +563,7 @@ make_spin_scored_pairs(const std::vector > auto index_to_pos = [atom_selection] (unsigned int idx) { mmdb::Atom *at = atom_selection[idx]; - return clipper::Coord_orth(at->x, at->y, at->z); + return clipper::Coord_orth(at->x(), at->y(), at->z()); }; auto index_to_name = [atom_selection] (unsigned int idx) { mmdb::Atom *at = atom_selection[idx]; @@ -737,8 +737,8 @@ find_chains_that_overlap_other_chains(mmdb::Manager *mol, float big_overlap_frac res_no_delta_stats_t() : sum(0), sum_sq(0), count(0) {} void add(mmdb::Atom *at_1, mmdb::Atom *at_2) { // It is usually the case that the residue numbers are the same - int res_no_1 = at_1->residue->GetSeqNum(); - int res_no_2 = at_2->residue->GetSeqNum(); + int res_no_1 = at_1->GetResidue()->GetSeqNum(); + int res_no_2 = at_2->GetResidue()->GetSeqNum(); int d = abs(res_no_2-res_no_1); // std::cout << "debug:: add() " << res_no_1 << " " << res_no_2 << " d " << d << std::endl; sum += d; @@ -1325,7 +1325,7 @@ make_fragments(std::vector > &score auto index_to_pos = [atom_selection] (unsigned int idx) { mmdb::Atom *at = atom_selection[idx]; - return clipper::Coord_orth(at->x, at->y, at->z); + return clipper::Coord_orth(at->x(), at->y(), at->z()); }; auto distance_check_min = [atom_selection] (int atom_index_1, int atom_index_2, double dist_min) { @@ -1867,7 +1867,7 @@ make_fragments(std::vector > &score auto index_to_pos = [atom_selection] (unsigned int idx) { mmdb::Atom *at = atom_selection[idx]; - return clipper::Coord_orth(at->x, at->y, at->z); + return clipper::Coord_orth(at->x(), at->y(), at->z()); }; std::ofstream f("debug-trace.points"); if (f) { @@ -2066,7 +2066,7 @@ make_fragments(std::vector > &score auto index_to_pos = [atom_selection] (int idx) { mmdb::Atom *at = atom_selection[idx]; - return clipper::Coord_orth(at->x, at->y, at->z); + return clipper::Coord_orth(at->x(), at->y(), at->z()); }; unsigned int n_top_traces = 800; @@ -2373,9 +2373,9 @@ globularize(mmdb::Manager *mol, const clipper::Xmap &xmap, const clipper: } } if (updated) { - at->x = pos_best.x(); - at->y = pos_best.y(); - at->z = pos_best.z(); + at->x() = pos_best.x(); + at->y() = pos_best.y(); + at->z() = pos_best.z(); } } } @@ -2583,9 +2583,9 @@ bring_together_consecutive_C_and_N_by_symmetry_transformation(mmdb::Manager *mol clipper::Coord_orth p(cfs.coord_orth(cell)); if (false) std::cout << "Moving (symm) " << coot::atom_spec_t(at_res) << " from " - << at_res->x << " " << at_res->y << " " << at_res->z << " to " + << at_res->x() << " " << at_res->y() << " " << at_res->z() << " to " << p.x() << " " << p.y() << " " << p.z() << std::endl; - at_res->x = p.x(); at_res->y = p.y(); at_res->z = p.z(); + at_res->x() = p.x(); at_res->y() = p.y(); at_res->z() = p.z(); } } } @@ -2720,7 +2720,7 @@ find_connected_fragments(const coot::minimol::molecule &flood_mol, for (int i=0; iisTer()) { - f << i << " " << at->x << " " << at->y << " " << at->z << "\n"; + f << i << " " << at->x() << " " << at->y() << " " << at->z() << "\n"; } } f.close(); @@ -3019,7 +3019,7 @@ apply_sequence_to_fragments(mmdb::Manager *mol_in, const clipper::Xmap &x n_res = chain_p->GetNumberOfResidues(); for (int ires=0; iresGetResidue(ires); - residue_p->seqNum = seq_pos + ires + 1; + residue_p->GetSeqNum() = seq_pos + ires + 1; // std::cout << "new seqnum for residue with index " << ires << " " << residue_p->seqNum << std::endl; } mol_in->FinishStructEdit(); @@ -3566,9 +3566,9 @@ void res_tracer_proc(const clipper::Xmap &xmap, float xmap_rmsd, const co std::string atom_name_to(at_to->GetAtomName()); if (atom_name_to == atom_name_from) { std::cout << "moving atom " << coot::atom_spec_t(at_to) << std::endl; - at_to->x = at->x; - at_to->y = at->y; - at_to->z = at->z; + at_to->x() = at->x(); + at_to->y() = at->y(); + at_to->z() = at->z(); break; } } @@ -4080,9 +4080,9 @@ void res_tracer_proc(const clipper::Xmap &xmap, float xmap_rmsd, const co float d_spun = score_atom_positions(atom_positions, pos_CA_this, pos_CA_next, xmap); if (d_spun > d_current) { - at_C_this->x = pos_C_this.x(); at_C_this->y = pos_C_this.y(); at_C_this->z = pos_C_this.z(); - at_O_this->x = pos_O_this.x(); at_O_this->y = pos_O_this.y(); at_O_this->z = pos_O_this.z(); - at_N_next->x = pos_N_next.x(); at_N_next->y = pos_N_next.y(); at_N_next->z = pos_N_next.z(); + at_C_this->x() = pos_C_this.x(); at_C_this->y() = pos_C_this.y(); at_C_this->z() = pos_C_this.z(); + at_O_this->x() = pos_O_this.x(); at_O_this->y() = pos_O_this.y(); at_O_this->z() = pos_O_this.z(); + at_N_next->x() = pos_N_next.x(); at_N_next->y() = pos_N_next.y(); at_N_next->z() = pos_N_next.z(); } } } @@ -4456,11 +4456,11 @@ void res_tracer_learn(const clipper::Xmap &xmap, float weight, float xmap for (int i=0; iisTer()) { - float dx = ref_mol_at->x - at->x; + float dx = ref_mol_at->x() - at->x(); if (fabsf(dx) < dist_crit) { - float dy = ref_mol_at->y - at->y; + float dy = ref_mol_at->y() - at->y(); if (fabsf(dy) < dist_crit) { - float dz = ref_mol_at->z - at->z; + float dz = ref_mol_at->z() - at->z(); if (fabsf(dz) < dist_crit) { float dd = dx * dx + dy * dy + dz * dz; float d = sqrtf(dd); diff --git a/ligand/ligand-extras.cc b/ligand/ligand-extras.cc index d96d62dd2b..f777e8f74b 100644 --- a/ligand/ligand-extras.cc +++ b/ligand/ligand-extras.cc @@ -196,7 +196,7 @@ coot::ligand::mean_and_variance_where_the_atoms_are(mmdb::Manager *mol) const { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - std::string ele = at->element; + std::string ele = at->GetElementName(); if (ele != " H") n_molecule_atoms++; } @@ -219,11 +219,11 @@ coot::ligand::mean_and_variance_where_the_atoms_are(mmdb::Manager *mol) const { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - std::string ele = at->element; + std::string ele = at->GetElementName(); if (ele != " H") { float f = coot::util::random() * rmi; if (f < crit_val) { - clipper::Coord_orth c(at->x, at->y, at->z); + clipper::Coord_orth c(at->x(), at->y(), at->z()); test_points.push_back(c); } } @@ -244,9 +244,9 @@ coot::ligand::mean_and_variance_where_the_atoms_are(mmdb::Manager *mol) const { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - std::string ele = at->element; + std::string ele = at->GetElementName(); if (ele != " H") { - clipper::Coord_orth c(at->x, at->y, at->z); + clipper::Coord_orth c(at->x(), at->y(), at->z()); test_points.push_back(c); } } diff --git a/ligand/ligand.cc b/ligand/ligand.cc index cf7d15d59a..13c14e9c65 100644 --- a/ligand/ligand.cc +++ b/ligand/ligand.cc @@ -340,9 +340,9 @@ coot::ligand::mask_map(mmdb::Manager *mol, short int mask_waters_flag) { // std::cout << "masking...."; for(int i=0; ix, atoms[i]->y, atoms[i]->z); + clipper::Coord_orth co(atoms[i]->x(), atoms[i]->y(), atoms[i]->z()); - std::string res_name (atoms[i]->residue->name); + std::string res_name (atoms[i]->GetResidue()->GetResName()); if (mask_waters_flag) { mask_around_coord(co, atom_radius); // mask xmap_masked } else { @@ -375,9 +375,9 @@ coot::ligand::mask_map(mmdb::Manager *mol, if (invert_flag == 0) { for (int i=0; ix, - atom_selection[i]->y, - atom_selection[i]->z); + clipper::Coord_orth co(atom_selection[i]->x(), + atom_selection[i]->y(), + atom_selection[i]->z()); mask_around_coord(co, map_atom_mask_radius); // mask xmap_cluster } diff --git a/ligand/molecular-replacement.cc b/ligand/molecular-replacement.cc index 903b6eaea3..1b1ad41870 100644 --- a/ligand/molecular-replacement.cc +++ b/ligand/molecular-replacement.cc @@ -213,9 +213,9 @@ coot::molecular_replacement_search(const clipper::Xmap &xmap_obs, << std::endl; for (int i=0; ix += shift.x(); - sel_atoms[i]->y += shift.y(); - sel_atoms[i]->z += shift.z(); + sel_atoms[i]->x() += shift.x(); + sel_atoms[i]->y() += shift.y(); + sel_atoms[i]->z() += shift.z(); } clipper::Xmap model_map = coot::util::calc_atom_map(mol, SelHnd, cell_model, spacegroup, gs_model); @@ -406,16 +406,16 @@ coot::molecular_replacement_search(const clipper::Xmap &xmap_obs, mol_rot->GetSelIndex(sel_rot, atoms_rot, na_rot); for (int i=0; ix -= mol_centre.second.x(); - atoms_rot[i]->y -= mol_centre.second.y(); - atoms_rot[i]->z -= mol_centre.second.z(); + atoms_rot[i]->x() -= mol_centre.second.x(); + atoms_rot[i]->y() -= mol_centre.second.y(); + atoms_rot[i]->z() -= mol_centre.second.z(); } for (int i=0; ix, atoms_rot[i]->y, atoms_rot[i]->z); + glm::vec3 pos(atoms_rot[i]->x(), atoms_rot[i]->y(), atoms_rot[i]->z()); glm::vec3 rotated = rot_mat * pos; - atoms_rot[i]->x = rotated.x; - atoms_rot[i]->y = rotated.y; - atoms_rot[i]->z = rotated.z; + atoms_rot[i]->x() = rotated.x; + atoms_rot[i]->y() = rotated.y; + atoms_rot[i]->z() = rotated.z; } // Compute atom map on the local box cell/grid (optimisation 1) @@ -473,9 +473,9 @@ coot::molecular_replacement_search(const clipper::Xmap &xmap_obs, mol_placed->GetSelIndex(sel_placed, atoms_placed, na_placed); for (int i=0; ix += trans_pos.x(); - atoms_placed[i]->y += trans_pos.y(); - atoms_placed[i]->z += trans_pos.z(); + atoms_placed[i]->x() += trans_pos.x(); + atoms_placed[i]->y() += trans_pos.y(); + atoms_placed[i]->z() += trans_pos.z(); } mol_placed->DeleteSelection(sel_placed); @@ -576,11 +576,11 @@ coot::molecular_replacement_search(const clipper::Xmap &xmap_obs, for (int j=0; jisTer()) { std::string name(res_atoms[j]->GetAtomName()); - std::string altloc(res_atoms[j]->altLoc); + std::string altloc(res_atoms[j]->altLoc()); if (name == moved_at.name && altloc == moved_at.altLoc) { - res_atoms[j]->x = moved_at.pos.x(); - res_atoms[j]->y = moved_at.pos.y(); - res_atoms[j]->z = moved_at.pos.z(); + res_atoms[j]->x() = moved_at.pos.x(); + res_atoms[j]->y() = moved_at.pos.y(); + res_atoms[j]->z() = moved_at.pos.z(); } } } diff --git a/ligand/monomer-utils.cc b/ligand/monomer-utils.cc index 56e728c6b2..a0354ee9d0 100644 --- a/ligand/monomer-utils.cc +++ b/ligand/monomer-utils.cc @@ -112,14 +112,14 @@ coot::monomer_utils::get_atom_index_pairs(const std::vectorname; + std::string atomname = atoms[i]->GetAtomName(); if (atomname == atom_name_pairs_in[ipair].atom1) { i_store_index = i; } } if (i_store_index > -1) { // i.e. we found the first atom for(int i2=0; i2name; + std::string atomname = atoms[i2]->GetAtomName(); if (atomname == atom_name_pairs_in[ipair].atom2) { index_pairs.push_back(coot::atom_index_pair(i_store_index, i2)); } @@ -147,16 +147,16 @@ coot::monomer_utils::get_atom_index_quads(const std::vectorname; + std::string atom_name = atoms[i1]->GetAtomName(); if (atom_name == atom_name_quads_in[iquad].atom_name(0)) { for (int i2=0; i2name; + std::string atom_name = atoms[i2]->GetAtomName(); if (atom_name == atom_name_quads_in[iquad].atom_name(1)) { for (int i3=0; i3name; + std::string atom_name = atoms[i3]->GetAtomName(); if (atom_name == atom_name_quads_in[iquad].atom_name(2)) { for (int i4=0; i4name; + std::string atom_name = atoms[i4]->GetAtomName(); if (atom_name == atom_name_quads_in[iquad].atom_name(3)) { v.push_back(coot::atom_index_quad(i1, i2, i3, i4)); } @@ -237,5 +237,5 @@ coot::monomer_utils::get_quads(const std::vector &atom_nam clipper::Coord_orth coot::monomer_utils::atom_to_co(mmdb::Atom *at) const { - return clipper::Coord_orth(at->x, at->y, at->z); + return clipper::Coord_orth(at->x(), at->y(), at->z()); } diff --git a/ligand/new-residue-by-3-phi-psi.cc b/ligand/new-residue-by-3-phi-psi.cc index ded6f84149..385470ec01 100644 --- a/ligand/new-residue-by-3-phi-psi.cc +++ b/ligand/new-residue-by-3-phi-psi.cc @@ -114,7 +114,7 @@ coot::new_residue_by_3_phi_psi::get_connecting_residue_atoms() const { residue_p->GetAtomTable(residue_atoms, nResidueAtoms); for (int i=0; iname); + std::string atom_name(at->GetAtomName()); if (atom_name == " N ") N_at = at; if (atom_name == " C ") C_at = at; if (atom_name == " CA ") CA_at = at; diff --git a/ligand/primitive-chi-angles.cc b/ligand/primitive-chi-angles.cc index fbd4451db8..07db01449c 100644 --- a/ligand/primitive-chi-angles.cc +++ b/ligand/primitive-chi-angles.cc @@ -44,7 +44,7 @@ coot::primitive_chi_angles::get_chi_angles() { bool residue_has_alt_confs = 0; for (int i=0; ialtLoc); + std::string alt_conf(residue_atoms[i]->altLoc()); if (alt_conf != "") { residue_has_alt_confs = 1; break; @@ -275,16 +275,16 @@ coot::primitive_chi_angles::get_atom_index_quads(const std::vectorname; + std::string atom_name = atoms[i1]->GetAtomName(); if (atom_name == atom_name_quads_in[iquad].atom_name(0)) { for (int i2=0; i2name; + std::string atom_name = atoms[i2]->GetAtomName(); if (atom_name == atom_name_quads_in[iquad].atom_name(1)) { for (int i3=0; i3name; + std::string atom_name = atoms[i3]->GetAtomName(); if (atom_name == atom_name_quads_in[iquad].atom_name(2)) { for (int i4=0; i4name; + std::string atom_name = atoms[i4]->GetAtomName(); if (atom_name == atom_name_quads_in[iquad].atom_name(3)) { v.push_back(coot::atom_index_quad(i1, i2, i3, i4)); } @@ -357,20 +357,20 @@ coot::primitive_chi_angles::get_quads_using_altconfs(const std::vector v; for (unsigned int iquad=0; iquadname; - std::string alt_conf_1 = atoms[i1]->altLoc; + std::string atom_name = atoms[i1]->GetAtomName(); + std::string alt_conf_1 = atoms[i1]->altLoc(); if (atom_name == atom_name_quads[iquad].atom_name(0)) { for (int i2=0; i2name; - std::string alt_conf_2 = atoms[i2]->altLoc; + std::string atom_name = atoms[i2]->GetAtomName(); + std::string alt_conf_2 = atoms[i2]->altLoc(); if (atom_name == atom_name_quads[iquad].atom_name(1)) { for (int i3=0; i3name; - std::string alt_conf_3 = atoms[i3]->altLoc; + std::string atom_name = atoms[i3]->GetAtomName(); + std::string alt_conf_3 = atoms[i3]->altLoc(); if (atom_name == atom_name_quads[iquad].atom_name(2)) { for (int i4=0; i4name; - std::string alt_conf_4 = atoms[i4]->altLoc; + std::string atom_name = atoms[i4]->GetAtomName(); + std::string alt_conf_4 = atoms[i4]->altLoc(); if (atom_name == atom_name_quads[iquad].atom_name(3)) { if (alt_conf_4 == residue_alt_confs[i_alt_conf] || alt_conf_4 == "") { if (alt_conf_3 == residue_alt_confs[i_alt_conf] || alt_conf_3 == "") { @@ -418,5 +418,5 @@ coot::primitive_chi_angles::get_quads_using_altconfs(const std::vectorx, at->y, at->z); + return clipper::Coord_orth(at->x(), at->y(), at->z()); } diff --git a/ligand/rama-rsr-extend-fragments.cc b/ligand/rama-rsr-extend-fragments.cc index eaf7774793..1f6fceaf08 100644 --- a/ligand/rama-rsr-extend-fragments.cc +++ b/ligand/rama-rsr-extend-fragments.cc @@ -474,14 +474,14 @@ rama_rsr_extend_fragments(mmdb::Manager *mol, const clipper::Xmap &xmap, double dd = (at_2_pos - at_1_pos).lengthsq(); double d = std::sqrt(dd); std::cout << "moving atom " << coot::atom_spec_t(atom_o) << " from " - << std::setw(9) << atom_o->x << " " << std::setw(9) << atom_o->y << " " << std::setw(9) << atom_o->z << " to " - << std::setw(9) << atom_r->x << " " << std::setw(9) << atom_r->y << " " << std::setw(9) << atom_r->z + << std::setw(9) << atom_o->x() << " " << std::setw(9) << atom_o->y() << " " << std::setw(9) << atom_o->z() << " to " + << std::setw(9) << atom_r->x() << " " << std::setw(9) << atom_r->y() << " " << std::setw(9) << atom_r->z() << " d " << std::setw(9) << d << "\n"; } - atom_o->x = atom_r->x; - atom_o->y = atom_r->y; - atom_o->z = atom_r->z; + atom_o->x() = atom_r->x(); + atom_o->y() = atom_r->y(); + atom_o->z() = atom_r->z(); } } } diff --git a/ligand/residue_by_phi_psi.cc b/ligand/residue_by_phi_psi.cc index 7ff2c51550..0d7c873a8d 100644 --- a/ligand/residue_by_phi_psi.cc +++ b/ligand/residue_by_phi_psi.cc @@ -667,7 +667,7 @@ coot::residue_by_phi_psi::get_connecting_residue_atoms() const { residue_p->GetAtomTable(residue_atoms, nResidueAtoms); for (int i=0; iname); + std::string atom_name(at->GetAtomName()); if (atom_name == " N ") N_at = at; if (atom_name == " C ") C_at = at; if (atom_name == " CA ") CA_at = at; diff --git a/ligand/rotamer.cc b/ligand/rotamer.cc index d72388bf5c..eaa60694cb 100644 --- a/ligand/rotamer.cc +++ b/ligand/rotamer.cc @@ -502,7 +502,7 @@ coot::rotamer::rotamer_atom_names_to_indices(const std::vector 0) { for (int iat=0; iatname); + atom_indices[iat] = std::string(residue_atoms[iat]->GetAtomName()); } int ithis_atom; @@ -530,9 +530,9 @@ coot::rotamer::rotamer_atom_names_to_indices(const std::vectorresidue->name << " " - << residue_atoms[0]->residue->GetSeqNum() << " " - << residue_atoms[0]->residue->GetChainID() << std::endl; + << residue_atoms[0]->GetResidue()->GetResName() << " " + << residue_atoms[0]->GetResidue()->GetSeqNum() << " " + << residue_atoms[0]->GetResidue()->GetChainID() << std::endl; } } return r; @@ -554,7 +554,7 @@ coot::rotamer::chi_torsion(const std::vector &chi_angle_atoms_indices, for (unsigned int ich_at=0; ich_atx, at->y, at->z)); + a.push_back(clipper::Coord_orth(at->x(), at->y(), at->z())); } double ctorsion = clipper::Coord_orth::torsion(a[0], a[1], a[2], a[3]); @@ -721,9 +721,9 @@ coot::rotamer::GetResidue_old(int i_rot) const { // smn_Cartesian c(residue_atoms[i]->x, // residue_atoms[i]->y, // residue_atoms[i]->z); - ::Cartesian d(ordered_atoms[i]->x, - ordered_atoms[i]->y, - ordered_atoms[i]->z); + ::Cartesian d(ordered_atoms[i]->x(), + ordered_atoms[i]->y(), + ordered_atoms[i]->z()); // std::cout << residue_atoms[i]->name << " " << c // << ordered_atoms[i]->name << " " << d << std::endl; // std::cout << ordered_atoms[i]->name << " " << d << std::endl; @@ -736,9 +736,9 @@ coot::rotamer::GetResidue_old(int i_rot) const { std::vector< ::Cartesian > coords; for(int i=0; ix, - ordered_atoms[i]->y, - ordered_atoms[i]->z); + ::Cartesian c(ordered_atoms[i]->x(), + ordered_atoms[i]->y(), + ordered_atoms[i]->z()); coords.push_back(c); } @@ -908,9 +908,9 @@ coot::rotamer::GetResidue_old(int i_rot) const { std::cout << "disaster in atom selection, trees, dunbrack\n"; } else { for (int iat=0; iatx = coords_rotated[iat].get_x(); - ordered_residue_atoms_ppcatom[iat]->y = coords_rotated[iat].get_y(); - ordered_residue_atoms_ppcatom[iat]->z = coords_rotated[iat].get_z(); + ordered_residue_atoms_ppcatom[iat]->x() = coords_rotated[iat].get_x(); + ordered_residue_atoms_ppcatom[iat]->y() = coords_rotated[iat].get_y(); + ordered_residue_atoms_ppcatom[iat]->z() = coords_rotated[iat].get_z(); } } delete [] ordered_residue_atoms_ppcatom; diff --git a/ligand/side-chain-densities.cc b/ligand/side-chain-densities.cc index 5606da7838..6316a38a76 100644 --- a/ligand/side-chain-densities.cc +++ b/ligand/side-chain-densities.cc @@ -951,7 +951,7 @@ coot::side_chain_densities::sample_map(mmdb::Residue *residue_this_p, if (! at->isTer()) { clipper::Coord_orth pos = co(at); residue_atom_positions.push_back(pos); - std::string atom_name(at->name); + std::string atom_name(at->GetAtomName()); if (atom_name == " N " || atom_name == " C " || atom_name == " O " || atom_name == " H " || atom_name == " CA ") { double r = 2.8; @@ -969,7 +969,7 @@ coot::side_chain_densities::sample_map(mmdb::Residue *residue_this_p, for (int i=0; iGetAtom(i); if (! at->isTer()) { - std::string atom_name(at->name); + std::string atom_name(at->GetAtomName()); if (atom_name == " N ") { clipper::Coord_orth pos = co(at); std::pair p(3.0, pos); @@ -1411,8 +1411,8 @@ coot::side_chain_densities::get_residue_axes_type_GLY(mmdb::Residue *this_residu int n_atoms = this_residue->GetNumberOfAtoms(); for (int i=0; iGetAtom(i); - std::string atom_name = at->name; - std::string alt_loc = at->altLoc; + std::string atom_name = at->GetAtomName(); + std::string alt_loc = at->altLoc(); if (! at->isTer()) { if (alt_loc.empty()) { if (atom_name == " CA ") CA_at = at; @@ -1490,8 +1490,8 @@ coot::side_chain_densities::get_residue_axes(mmdb::Residue *residue_p) const { int n_atoms = residue_p->GetNumberOfAtoms(); for (int i=0; iGetAtom(i); - std::string atom_name = at->name; - std::string alt_loc = at->altLoc; + std::string atom_name = at->GetAtomName(); + std::string alt_loc = at->altLoc(); if (! at->isTer()) { if (alt_loc.empty()) { if (atom_name == " CA ") CA_at = at; diff --git a/ligand/side-chain.cc b/ligand/side-chain.cc index 12dfa5b257..faff7bc367 100644 --- a/ligand/side-chain.cc +++ b/ligand/side-chain.cc @@ -141,20 +141,20 @@ coot::do_180_degree_side_chain_flip(const coot::residue_spec_t &spec, // for (int iatc=0; iatcaltLoc; + std::string atom_copy_altconf = residue_atoms_copy[iatc]->altLoc(); if (atom_copy_altconf == alt_conf) { // we need to find this atom in residue - std::string atom_copy_name = residue_atoms_copy[iatc]->name; + std::string atom_copy_name = residue_atoms_copy[iatc]->GetAtomName(); for (int iato=0; iatoaltLoc; - std::string orig_atom_name = residue_atoms[iato]->name; + std::string orig_atom_altconf = residue_atoms[iato]->altLoc(); + std::string orig_atom_name = residue_atoms[iato]->GetAtomName(); if (orig_atom_name == atom_copy_name) { if (atom_copy_altconf == orig_atom_altconf) { // std::cout << "DEBUG:: copying coords from " // << residue_atoms_copy[iatc] << std::endl; - residue_atoms[iato]->x = residue_atoms_copy[iatc]->x; - residue_atoms[iato]->y = residue_atoms_copy[iatc]->y; - residue_atoms[iato]->z = residue_atoms_copy[iatc]->z; + residue_atoms[iato]->x() = residue_atoms_copy[iatc]->x(); + residue_atoms[iato]->y() = residue_atoms_copy[iatc]->y(); + residue_atoms[iato]->z() = residue_atoms_copy[iatc]->z(); } } } diff --git a/ligand/torsion-general.cc b/ligand/torsion-general.cc index 4dc773294a..0025491559 100644 --- a/ligand/torsion-general.cc +++ b/ligand/torsion-general.cc @@ -73,9 +73,9 @@ coot::torsion_general::GetTree_0_based() const { residue_p->GetAtomTable(residue_atoms, n_residue_atoms); std::vector< ::Cartesian > coords; for(int i=0; ix, - residue_atoms[i]->y, - residue_atoms[i]->z); + ::Cartesian c(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); coords.push_back(c); } int base_index = 0; @@ -95,9 +95,9 @@ coot::torsion_general::GetTree() const { residue_p->GetAtomTable(residue_atoms, n_residue_atoms); std::vector< ::Cartesian > coords; for(int i=0; ix, - residue_atoms[i]->y, - residue_atoms[i]->z); + ::Cartesian c(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); coords.push_back(c); } int base_index = clicked_atom_indices[0]; @@ -124,9 +124,9 @@ coot::torsion_general::change_by(double diff, Tree *tree) { residue_p->GetAtomTable(residue_atoms, n_residue_atoms); std::vector< ::Cartesian > coords; for(int i=0; ix, - residue_atoms[i]->y, - residue_atoms[i]->z); + ::Cartesian c(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); coords.push_back(c); } @@ -163,22 +163,22 @@ coot::torsion_general::change_by(double diff, Tree *tree) { for (int iat=0; iatx - coords_rotatated[iat].get_x(); - float dy = residue_atoms[iat]->x - coords_rotatated[iat].get_x(); - float dz = residue_atoms[iat]->x - coords_rotatated[iat].get_x(); + float dx = residue_atoms[iat]->x() - coords_rotatated[iat].get_x(); + float dy = residue_atoms[iat]->x() - coords_rotatated[iat].get_x(); + float dz = residue_atoms[iat]->x() - coords_rotatated[iat].get_x(); float dd = dx * dx + dy * dy + dz * dz; float d = sqrt(dd); - std::cout << residue_atoms[iat]->name << "debug:: change_by(): " - << residue_atoms[iat]->x << " " - << residue_atoms[iat]->y << " " - << residue_atoms[iat]->z << " to " + std::cout << residue_atoms[iat]->GetAtomName() << "debug:: change_by(): " + << residue_atoms[iat]->x() << " " + << residue_atoms[iat]->y() << " " + << residue_atoms[iat]->z() << " to " << coords_rotatated[iat] << " moved by " << d << std::endl; } - residue_atoms[iat]->x = coords_rotatated[iat].get_x(); - residue_atoms[iat]->y = coords_rotatated[iat].get_y(); - residue_atoms[iat]->z = coords_rotatated[iat].get_z(); + residue_atoms[iat]->x() = coords_rotatated[iat].get_x(); + residue_atoms[iat]->y() = coords_rotatated[iat].get_y(); + residue_atoms[iat]->z() = coords_rotatated[iat].get_z(); } r = 0; // return good status } @@ -188,9 +188,9 @@ coot::torsion_general::change_by(double diff, Tree *tree) { } if (debug) { for(int i=0; ix, - residue_atoms[i]->y, - residue_atoms[i]->z); + ::Cartesian c(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); } } } else { @@ -262,7 +262,7 @@ coot::torsion_general::get_contact_indices() const { // we keep a mapping from local indexing to residue indexing. // for (int i=0; ielement); + std::string element(residue_atoms[i]->GetElementName()); if (element == " H" || element == " D") { n_H_residue_atoms++; } else { @@ -276,7 +276,7 @@ coot::torsion_general::get_contact_indices() const { int iH=0; int inH=0; for (int i=0; ielement); + std::string element(residue_atoms[i]->GetElementName()); if (element == " H" || element == " D") { H_residue_atoms[iH] = residue_atoms[i]; H_atom_orig_indcies[iH]=i; diff --git a/mini-mol/atom-quads.cc b/mini-mol/atom-quads.cc index 320f1b91d1..cae6453f2a 100644 --- a/mini-mol/atom-quads.cc +++ b/mini-mol/atom-quads.cc @@ -150,7 +150,7 @@ coot::atom_quad::setup_chiral_quad(mmdb::Residue *residue_with_O, mmdb::Residue int n_residue_atoms; residue_with_O->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); + std::string atom_name(residue_atoms[iat]->GetAtomName()); if (atom_name == O_name) { // the O atom name comes from the residue_with_O if (!quad.atom_1) { @@ -164,7 +164,7 @@ coot::atom_quad::setup_chiral_quad(mmdb::Residue *residue_with_O, mmdb::Residue residue_with_chiral_centre->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); + std::string atom_name(at->GetAtomName()); if (atom_name == atom_4_name) { if (! quad.atom_4) quad.atom_4 = at; // chiral centre atom @@ -244,18 +244,18 @@ coot::atom_index_quad::torsion(mmdb::PPAtom atom_selection, int n_selected_atoms std::string mess = "bad atom indexing in atom_index_quad::torsion()"; throw std::runtime_error(mess); } - clipper::Coord_orth pt_1(atom_selection[index1]->x, - atom_selection[index1]->y, - atom_selection[index1]->z); - clipper::Coord_orth pt_2(atom_selection[index2]->x, - atom_selection[index2]->y, - atom_selection[index2]->z); - clipper::Coord_orth pt_3(atom_selection[index3]->x, - atom_selection[index3]->y, - atom_selection[index3]->z); - clipper::Coord_orth pt_4(atom_selection[index4]->x, - atom_selection[index4]->y, - atom_selection[index4]->z); + clipper::Coord_orth pt_1(atom_selection[index1]->x(), + atom_selection[index1]->y(), + atom_selection[index1]->z()); + clipper::Coord_orth pt_2(atom_selection[index2]->x(), + atom_selection[index2]->y(), + atom_selection[index2]->z()); + clipper::Coord_orth pt_3(atom_selection[index3]->x(), + atom_selection[index3]->y(), + atom_selection[index3]->z()); + clipper::Coord_orth pt_4(atom_selection[index4]->x(), + atom_selection[index4]->y(), + atom_selection[index4]->z()); angle = clipper::Util::rad2d(clipper::Coord_orth::torsion(pt_1, pt_2, pt_3, pt_4)); } @@ -268,9 +268,9 @@ double coot::atom_quad::angle_2() const { // angle 1-2-3 in degrees if (atom_1 && atom_2 && atom_3) { - clipper::Coord_orth pt_1(atom_1->x, atom_1->y, atom_1->z); - clipper::Coord_orth pt_2(atom_2->x, atom_2->y, atom_2->z); - clipper::Coord_orth pt_3(atom_3->x, atom_3->y, atom_3->z); + clipper::Coord_orth pt_1(atom_1->x(), atom_1->y(), atom_1->z()); + clipper::Coord_orth pt_2(atom_2->x(), atom_2->y(), atom_2->z()); + clipper::Coord_orth pt_3(atom_3->x(), atom_3->y(), atom_3->z()); double angle = clipper::Util::rad2d(clipper::Coord_orth::angle(pt_1, pt_2, pt_3)); return angle; } else { @@ -283,9 +283,9 @@ double coot::atom_quad::angle_3() const { // angle 2-3-4 in degrees if (atom_2 && atom_3 && atom_4) { - clipper::Coord_orth pt_2(atom_2->x, atom_2->y, atom_2->z); - clipper::Coord_orth pt_3(atom_3->x, atom_3->y, atom_3->z); - clipper::Coord_orth pt_4(atom_4->x, atom_4->y, atom_4->z); + clipper::Coord_orth pt_2(atom_2->x(), atom_2->y(), atom_2->z()); + clipper::Coord_orth pt_3(atom_3->x(), atom_3->y(), atom_3->z()); + clipper::Coord_orth pt_4(atom_4->x(), atom_4->y(), atom_4->z()); double angle = clipper::Util::rad2d(clipper::Coord_orth::angle(pt_2, pt_3, pt_4)); return angle; } else { @@ -297,10 +297,10 @@ coot::atom_name_quad coot::atom_quad::get_atom_name_quad() const { if (atom_1 && atom_2 && atom_3 && atom_4) { - return coot::atom_name_quad(atom_1->name, - atom_2->name, - atom_3->name, - atom_4->name); + return coot::atom_name_quad(atom_1->GetAtomName(), + atom_2->GetAtomName(), + atom_3->GetAtomName(), + atom_4->GetAtomName()); } else { throw std::runtime_error("atom_quad::atom_name_quad() Null atom(s)"); } @@ -318,10 +318,10 @@ coot::atom_name_quad::torsion(mmdb::Residue *residue) const { mmdb::Atom *at_3 = residue->GetAtom(atom_name_[3].c_str()); if (at_0 && at_1 && at_2 && at_3) { - clipper::Coord_orth pt_0(at_0->x, at_0->y, at_0->z); - clipper::Coord_orth pt_1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth pt_2(at_2->x, at_2->y, at_2->z); - clipper::Coord_orth pt_3(at_3->x, at_3->y, at_3->z); + clipper::Coord_orth pt_0(at_0->x(), at_0->y(), at_0->z()); + clipper::Coord_orth pt_1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth pt_2(at_2->x(), at_2->y(), at_2->z()); + clipper::Coord_orth pt_3(at_3->x(), at_3->y(), at_3->z()); double angle = clipper::Util::rad2d(clipper::Coord_orth::torsion(pt_0, pt_1, pt_2, pt_3)); return angle; } @@ -334,10 +334,10 @@ double coot::atom_quad::torsion() const { if (atom_1 && atom_2 && atom_3 && atom_4) { - clipper::Coord_orth pt_1(atom_1->x, atom_1->y, atom_1->z); - clipper::Coord_orth pt_2(atom_2->x, atom_2->y, atom_2->z); - clipper::Coord_orth pt_3(atom_3->x, atom_3->y, atom_3->z); - clipper::Coord_orth pt_4(atom_4->x, atom_4->y, atom_4->z); + clipper::Coord_orth pt_1(atom_1->x(), atom_1->y(), atom_1->z()); + clipper::Coord_orth pt_2(atom_2->x(), atom_2->y(), atom_2->z()); + clipper::Coord_orth pt_3(atom_3->x(), atom_3->y(), atom_3->z()); + clipper::Coord_orth pt_4(atom_4->x(), atom_4->y(), atom_4->z()); double angle = clipper::Util::rad2d(clipper::Coord_orth::torsion(pt_1, pt_2, pt_3, pt_4)); return angle; } else { @@ -354,10 +354,10 @@ coot::atom_quad::chiral_volume() const { throw std::runtime_error("Null atoms in quad for chiral volume"); } else { - clipper::Coord_orth centre(atom_4->x, atom_4->y, atom_4->z); - clipper::Coord_orth at_1(atom_1->x, atom_1->y, atom_1->z); - clipper::Coord_orth at_2(atom_2->x, atom_2->y, atom_2->z); - clipper::Coord_orth at_3(atom_3->x, atom_3->y, atom_3->z); + clipper::Coord_orth centre(atom_4->x(), atom_4->y(), atom_4->z()); + clipper::Coord_orth at_1(atom_1->x(), atom_1->y(), atom_1->z()); + clipper::Coord_orth at_2(atom_2->x(), atom_2->y(), atom_2->z()); + clipper::Coord_orth at_3(atom_3->x(), atom_3->y(), atom_3->z()); clipper::Coord_orth a = at_1 - centre; clipper::Coord_orth b = at_2 - centre; diff --git a/mini-mol/mini-mol.cc b/mini-mol/mini-mol.cc index 3af4733a31..9620adf6f5 100644 --- a/mini-mol/mini-mol.cc +++ b/mini-mol/mini-mol.cc @@ -124,7 +124,7 @@ coot::minimol::molecule::molecule(mmdb::PPAtom atom_selection, for (int iat=0; iatresidue; + mmdb::Residue *residue_p = at->GetResidue(); mmdb::Chain *chain_p = at->GetChain(); int resno = residue_p->GetSeqNum(); std::string res_name = residue_p->GetResName(); @@ -161,7 +161,7 @@ coot::minimol::molecule::molecule(mmdb::PPAtom atom_selection, coot::minimol::residue res(resno); res.name = res_name; coot::minimol::atom minimol_atom(at); - minimol_atom.pos = clipper::Coord_orth(atoms[iat].x, atoms[iat].y, atoms[iat].z); + minimol_atom.pos = clipper::Coord_orth(atoms[iat].x(), atoms[iat].y(), atoms[iat].z()); res.addatom(minimol_atom); try { fragments[ifrag_for_atom].addresidue(res,1); @@ -171,7 +171,7 @@ coot::minimol::molecule::molecule(mmdb::PPAtom atom_selection, } } else { coot::minimol::atom minimol_atom(at); - minimol_atom.pos = clipper::Coord_orth(atoms[iat].x, atoms[iat].y, atoms[iat].z); + minimol_atom.pos = clipper::Coord_orth(atoms[iat].x(), atoms[iat].y(), atoms[iat].z()); fragments[ifrag_for_atom][resno].addatom(minimol_atom); } } @@ -215,7 +215,7 @@ coot::minimol::molecule::min_resno_in_chain(mmdb::Chain *chain_p) const { int resno; for (int ires=0; iresGetResidue(ires); - resno = residue_p->seqNum; + resno = residue_p->GetSeqNum(); if (resno < min_resno) { min_resno = resno; found_residues = 1; @@ -289,20 +289,20 @@ coot::minimol::molecule::setup(mmdb::Manager *mol, bool udd_atom_index_to_user_d mmdb::Atom *at; for (int ires=0; iresGetResidue(ires); - coot::minimol::residue r(residue_p->seqNum); + coot::minimol::residue r(residue_p->GetSeqNum()); int n_atoms = residue_p->GetNumberOfAtoms(); - r.name = residue_p->name; + r.name = residue_p->GetResName(); for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - clipper::Coord_orth p(at->x, at->y, at->z); - coot::minimol::atom mat(std::string(at->name), - std::string(at->element), + clipper::Coord_orth p(at->x(), at->y(), at->z()); + coot::minimol::atom mat(std::string(at->GetAtomName()), + std::string(at->GetElementName()), p, - std::string(at->altLoc), - at->occupancy, - at->tempFactor); + std::string(at->altLoc()), + at->occupancy(), + at->tempFactor()); if (do_atom_index_transfer) { int atom_udd_atom_index = -1; if (at->GetUDData(udd_atom_index_handle, atom_udd_atom_index) == mmdb::UDDATA_Ok) { @@ -585,22 +585,22 @@ coot::minimol::molecule::fragment_for_chain(const std::string &chain_id) { // coot::minimol::residue::residue(mmdb::Residue* residue_p) { - seqnum = residue_p->seqNum; + seqnum = residue_p->GetSeqNum(); ins_code = residue_p->GetInsCode(); - name = residue_p->name; + name = residue_p->GetResName(); int nResidueAtoms; mmdb::PPAtom residue_atoms; residue_p->GetAtomTable(residue_atoms, nResidueAtoms); for (int i=0; iisTer()) - addatom(std::string(residue_atoms[i]->name), - std::string(residue_atoms[i]->element), - residue_atoms[i]->x, - residue_atoms[i]->y, - residue_atoms[i]->z, - std::string(residue_atoms[i]->altLoc), - residue_atoms[i]->occupancy, - residue_atoms[i]->tempFactor); + addatom(std::string(residue_atoms[i]->GetAtomName()), + std::string(residue_atoms[i]->GetElementName()), + residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z(), + std::string(residue_atoms[i]->altLoc()), + residue_atoms[i]->occupancy(), + residue_atoms[i]->tempFactor()); } } @@ -608,14 +608,14 @@ coot::minimol::residue::residue(mmdb::Residue* residue_p) { coot::minimol::residue::residue(mmdb::Residue *residue_p, const std::vector &keep_only_these_atoms) { - seqnum = residue_p->seqNum; + seqnum = residue_p->GetSeqNum(); ins_code = residue_p->GetInsCode(); - name = residue_p->name; + name = residue_p->GetResName(); int nResidueAtoms; mmdb::PPAtom residue_atoms; residue_p->GetAtomTable(residue_atoms, nResidueAtoms); for (int i=0; iname; + std::string atom_name = residue_atoms[i]->GetAtomName(); bool add_it = 0; for (unsigned int ikeep=0; ikeepelement), - residue_atoms[i]->x, - residue_atoms[i]->y, - residue_atoms[i]->z, - std::string(residue_atoms[i]->altLoc), - residue_atoms[i]->occupancy, - residue_atoms[i]->tempFactor); + std::string(residue_atoms[i]->GetElementName()), + residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z(), + std::string(residue_atoms[i]->altLoc()), + residue_atoms[i]->occupancy(), + residue_atoms[i]->tempFactor()); } } } @@ -661,8 +661,8 @@ coot::minimol::residue::make_residue() const { // cif bits if (atoms[iat].name.length() < 20) strcpy(atom_p->label_atom_id, atoms[iat].name.c_str()); - strncpy(atom_p->element, atoms[iat].element.c_str(),3); - strncpy(atom_p->altLoc, atoms[iat].altLoc.c_str(), 2); + atom_p->SetElementName(atoms[iat].element.c_str()); + strncpy(atom_p->altLoc(), atoms[iat].altLoc.c_str(), 2); int i_add = residue_p->AddAtom(atom_p); if (i_add < 0) std::cout << "addatom addition error" << std::endl; @@ -683,7 +683,7 @@ coot::minimol::residue::update_positions_from(mmdb::Residue *residue_p) { residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatx, at->y, at->z); + clipper::Coord_orth p(at->x(), at->y(), at->z()); atoms[iat].pos = p; } } @@ -1003,12 +1003,12 @@ coot::minimol::atom::atom(std::string atom_name, } coot::minimol::atom::atom(mmdb::Atom *at) { - name = at->name; - element = at->element; - pos = clipper::Coord_orth(at->x, at->y, at->z); - altLoc = at->altLoc; - occupancy = at->occupancy; - temperature_factor = at->tempFactor; + name = at->GetAtomName(); + element = at->GetElementName(); + pos = clipper::Coord_orth(at->x(), at->y(), at->z()); + altLoc = at->altLoc(); + occupancy = at->occupancy(); + temperature_factor = at->tempFactor(); int_user_data = -1; } @@ -1085,8 +1085,8 @@ coot::minimol::molecule::pcmmdbmanager() const { (*this)[ifrag][ires][iatom].occupancy, (*this)[ifrag][ires][iatom].temperature_factor); atom_p->SetAtomName(this_atom.name.c_str()); - strncpy(atom_p->element,(*this)[ifrag][ires][iatom].element.c_str(),3); - strncpy(atom_p->altLoc, (*this)[ifrag][ires][iatom].altLoc.c_str(), 2); + atom_p->SetElementName((*this)[ifrag][ires][iatom].element.c_str()); + strncpy(atom_p->altLoc(), (*this)[ifrag][ires][iatom].altLoc.c_str(), 2); if (udd_atom_index_handle >= 0) if (this_atom.int_user_data >= 0) atom_p->PutUDData(udd_atom_index_handle, this_atom.int_user_data); diff --git a/mmdb-shim/build-shimlib.sh b/mmdb-shim/build-shimlib.sh new file mode 100755 index 0000000000..fcb2655e8b --- /dev/null +++ b/mmdb-shim/build-shimlib.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# Build the shim's compiled units (io.cc + contacts.cc) into a static lib that +# the real Coot build links against. Header-only parts come via -Iinclude. +# -> mmdb-shim/lib/libmmdbshim.a +set -euo pipefail +HERE="$(cd "$(dirname "$0")" && pwd)" +GEMMI="${GEMMI_INC:-$(brew --prefix gemmi)/include}" +CXX="${CXX:-/usr/bin/clang++}" +mkdir -p "$HERE/lib" "$HERE/obj" + +for u in io contacts; do + "$CXX" -std=c++17 -O2 -fPIC -DCOOT_USE_MMDB_SHIM -I"$HERE/include" -I"$GEMMI" \ + -c "$HERE/src/$u.cc" -o "$HERE/obj/$u.o" +done +ar rcs "$HERE/lib/libmmdbshim.a" "$HERE/obj/io.o" "$HERE/obj/contacts.o" +echo "built $HERE/lib/libmmdbshim.a" +echo +echo "To wire into the autotools build (before ./configure), e.g.:" +echo " export CPPFLAGS=\"-I$HERE/include -DCOOT_USE_MMDB_SHIM \$CPPFLAGS\"" +echo " export LDFLAGS=\"-L$HERE/lib -L\$(brew --prefix gemmi)/lib \$LDFLAGS\"" +echo " export LIBS=\"-lmmdbshim -lgemmi_cpp \$LIBS\"" +echo " # (apply the field rewrite on a branch first; note clipper/ssm still" +echo " # see the shim headers in THIS version — expected, per project notes)" diff --git a/mmdb-shim/build.sh b/mmdb-shim/build.sh new file mode 100755 index 0000000000..4fbeea8170 --- /dev/null +++ b/mmdb-shim/build.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# Build + run the mmdb-shim tests. +# macro ON -> gemmi-backed shim (mmdb-shim/include/mmdb2 + _shim_impl.hh) +# macro OFF -> falls through to real MMDB via #include_next (coexistence check) +set -euo pipefail +HERE="$(cd "$(dirname "$0")" && pwd)" +GEMMI="${GEMMI_INC:-$(brew --prefix gemmi)/include}" +MMDB="${MMDB_INC:-/opt/homebrew/Cellar/mmdb2/2.0.22/include}" +CXX=/usr/bin/clang++ +STD="-std=c++17 -O0 -g -Wall" + +echo "=== core unit test ===" +$CXX $STD -I"$GEMMI" "$HERE/core/test_core.cc" -o "$HERE/core/test_core" && "$HERE/core/test_core" | tail -1 + +echo "=== shim test (COOT_USE_MMDB_SHIM) ===" +$CXX $STD -DCOOT_USE_MMDB_SHIM -I"$HERE/include" -I"$GEMMI" \ + "$HERE/test/test_shim.cc" -o "$HERE/test/test_shim" && "$HERE/test/test_shim" | tail -1 + +echo "=== UDData engine test ===" +$CXX $STD -DCOOT_USE_MMDB_SHIM -I"$HERE/include" -I"$GEMMI" \ + "$HERE/test/test_udd.cc" -o "$HERE/test/test_udd" && "$HERE/test/test_udd" | tail -1 + +echo "=== selection engine test ===" +$CXX $STD -DCOOT_USE_MMDB_SHIM -I"$HERE/include" -I"$GEMMI" \ + "$HERE/test/test_sel.cc" -o "$HERE/test/test_sel" && "$HERE/test/test_sel" | tail -1 + +echo "=== contacts test (SelectSphere + SeekContacts via gemmi NeighborSearch) ===" +$CXX $STD -DCOOT_USE_MMDB_SHIM -I"$HERE/include" -I"$GEMMI" \ + "$HERE/src/contacts.cc" "$HERE/test/test_contacts.cc" \ + -L"$(brew --prefix gemmi)/lib" -lgemmi_cpp -lz -o "$HERE/test/test_contacts" \ + && "$HERE/test/test_contacts" | tail -1 + +echo "=== I/O round-trip test (gemmi read/write; links libgemmi_cpp) ===" +PDB="${PDB:-$HERE/../1hr2_final.pdb}" +$CXX $STD -DCOOT_USE_MMDB_SHIM -I"$HERE/include" -I"$GEMMI" \ + "$HERE/src/io.cc" "$HERE/test/test_io.cc" \ + -L"$(brew --prefix gemmi)/lib" -lgemmi_cpp -lz -o "$HERE/test/test_io" \ + && "$HERE/test/test_io" "$PDB" | tail -1 + +echo "=== leaf integration test (real Coot mmdb idioms vs gemmi ground truth) ===" +$CXX $STD -DCOOT_USE_MMDB_SHIM -I"$HERE/include" -I"$GEMMI" \ + "$HERE/src/io.cc" "$HERE/test/test_leaf.cc" \ + -L"$(brew --prefix gemmi)/lib" -lgemmi_cpp -lz -o "$HERE/test/test_leaf" \ + && "$HERE/test/test_leaf" | tail -1 + +if [ -x "$HERE/../mmdb-recon/ast/build2/mmdb_tool" ]; then + echo "=== field-access rewriter test (synthetic) ===" + bash "$HERE/test/rewrite/run_rewrite_test.sh" | tail -1 +fi + +echo "=== coexistence: macro OFF must compile against real MMDB ===" +printf '#include \nint main(){mmdb::Manager*m=new mmdb::Manager();int n=m->GetNumberOfModels();delete m;return n;}\n' > /tmp/mmdb_fallback.cc +$CXX $STD -I"$HERE/include" -I"$MMDB" -c /tmp/mmdb_fallback.cc -o /tmp/mmdb_fallback.o \ + && echo " ok: fallback compiles against real MMDB" diff --git a/mmdb-shim/core/bench_edits b/mmdb-shim/core/bench_edits new file mode 100755 index 0000000000000000000000000000000000000000..8df9814dd50a3366b6918f7fa6a34970bfaaa48f GIT binary patch literal 61992 zcmeHw3w#tsws&<;9zBx~9(e*vhM;Z|6iI-PXfT}@B&dKPK2}{PPnaPuOeQ=;WD-yU z5!{h@RkGJa*j+Ob?&Z3mvdc;USEJ~z0bjf8VnFXYA?{U>$23cr?|-^`!elbxq3-wn z?(dt)uTy=ht4>v&I(6#QsZ-s5I`@wY!HjVXKOWa8T%tc?kF)U<#YW@G!DTSaOP`f} ze|FwniXHfqGY^a!1QDKC6kssqXWy4U@UfiVGBA#*Fsj1n3Q!*#4Cc~hW)(o-iLU{P z3E$7vG6<%2_5b`_n3WiVp~hTWRMY?16JON*3cj6c3WDA72`WC&Q2rSV#Z{Fx7c1zA z?*kRzc{M%3e(Jrqz+hNdTx=*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y6fRz|9hl#a^$wr zkDpF1&VENSe3bCpZQ716w4*nDQ@^C~%iuE)>DSB(KY8H&80WpwH~;=fw6$aOJnM^< z&wtpEw{POPagS_m`u$UnJoJ9c$0Nszd`Hyc?I|raY57}sGzPtt@E^zj(2!Qx*jL(7 zk+QbB`TYKGPCfU#uFd~mxI8Sx|F)v7dxpOg^{3e2uXcn-{m(l;`F+;uH-2{grvaVc zKAbatOzVmbjlYWAx%966bzd#Ivz;4}b!+vf>A(BjKWBTx-LFlLy)pQ}a}lE_-}>S^ z=dOLA{nu;0I`Pi-Roh;SbMNzaKDzVKM;`yn?;CU0-S|@CqWcnW z{VHkixu-hCvbF*qS|iBK|fx@zako^ui;tt7fkLCV t9S^?0=<6{@9{4L4nke}fE*+Ns_hlnv_D@@I{P|J0j^7*n)I5Lg{{TahP(%O# literal 0 HcmV?d00001 diff --git a/mmdb-shim/core/test_core b/mmdb-shim/core/test_core new file mode 100755 index 0000000000000000000000000000000000000000..456921635e240289e23fd95b9c324233c8c6a86c GIT binary patch literal 579000 zcmeEv34B$>_5a+w1l|io0b@~Fk{FdBDlWBuOGkD8jUzTn!cGx_ZLUO;Bn zH{t@fKHht3E*0}KrAg21tG{^O>~xY{U;NS%S>L%4Hw*90`ogL{@KFA1YPx9V%%%&j zoq56MuWq_}#(8#q4OhGM%^T(B=e=2HIdP3O(dNSmfBlV8_YY9yKbvgcZ6etzbd zkV@JNy)v-U)s`2Mm31KVS zMP9qTe!p~2JahYp3;Y9l^H>k@!TiT|_r)KdNxo0|WSF(4X#qVmCr#RCzkNW|CFe;x zr<(c2XCwld`9F8v?5i)hVxPlQ5#$zP5B!myyFVWiBY-Uv)jj#kf8-sXw{(WZP6{iS zp6}m>vmS5nnd7wgL`7^<^KPr3=p4U1K67L&ey2!%CL|Un?`%kkL|N?9-xUkNtI8yv z@qQMb#cNAa$=btGqDI6H)X&xZH}SmD5x3WfF|in~S$5O3(hgb2w8J~X72>L85pfFd z<4d=T#cva-JJ{ZBXm7r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impl.hh new file mode 100644 index 0000000000..85d33e97e1 --- /dev/null +++ b/mmdb-shim/include/mmdb2/_mmcif_impl.hh @@ -0,0 +1,601 @@ +// -*- mode: c++; -*- +// +// mmdb-shim: mmdb::mmcif::* implemented as a thin veneer over gemmi::cif. +// See coot-shim-prefer-gemmi memory: NEVER hand-write CIF parsing — gemmi does +// the real work; this only presents the MMDB-shaped API Coot's geometry/ uses. +// +// Copyright 2026 by Medical Research Council Laboratory of Molecular Biology +// +// Included at the end of _shim_impl.hh (so pstr/cpstr/realtype already exist). +#ifndef COOT_MMDB_SHIM_MMCIF_IMPL_HH +#define COOT_MMDB_SHIM_MMCIF_IMPL_HH + +#include +#include // gemmi::cif::read_file +#include // gemmi::cif::write_cif_to_stream + +#include +#include +#include +#include +#include +#include + +namespace mmdb { +namespace mmcif { + +// ---- return codes (mirror mmdb_mmcif_.h) -------------------------------- +enum { + CIFRC_Loop = 2, + CIFRC_Structure = 1, + CIFRC_Ok = 0, + CIFRC_StructureNoTag = -1, + CIFRC_LoopNoTag = -2, + CIFRC_NoCategory = -3, + CIFRC_WrongFormat = -4, + CIFRC_NoTag = -5, + CIFRC_NotAStructure = -6, + CIFRC_NotALoop = -7, + CIFRC_WrongIndex = -8, + CIFRC_NoField = -9, + CIFRC_Created = -12, + CIFRC_CantOpenFile = -13, + CIFRC_NoDataLine = -14, + CIFRC_NoData = -15 +}; + +// ---- file flags ---------------------------------------------------------- +enum { + CIFFL_PrintWarnings = 0x00000001, + CIFFL_StopOnWarnings = 0x00000002, + CIFFL_SuggestCategories = 0x00000004, + CIFFL_SuggestTags = 0x00000008 +}; + +enum MMCIF_ITEM { + MMCIF_None = 0, MMCIF_Struct = 1, MMCIF_Loop = 2, + MMCIF_Data = 3, MMCIF_Category = 4 +}; + +class Loop; +class Struct; +class Category; +class Data; +class File; +typedef Loop *PLoop; +typedef Struct *PStruct; +typedef Category *PCategory; +typedef Data *PData; +typedef File *PFile; + +namespace detail { + // MMDB category names have no trailing dot; gemmi wants "_cat." — normalise + // to WITH-dot internally so full tag = cat + subtag. + inline std::string with_dot(const char *cat) { + std::string s(cat ? cat : ""); + if (s.empty() || s.back() != '.') s += '.'; + return s; + } + inline std::string strip_dot(const std::string &s) { + if (!s.empty() && s.back() == '.') return s.substr(0, s.size() - 1); + return s; + } +} + +// ========================================================================= +// Category — just a named handle (Coot uses GetCategoryName / GetCategoryID) +// ========================================================================= +class Category { + public: + std::string cat; // WITH trailing dot + MMCIF_ITEM kind = MMCIF_Category; + std::deque sret; + Category() {} + pstr GetCategoryName() { + sret.push_back(detail::strip_dot(cat)); + return (pstr) sret.back().c_str(); + } + MMCIF_ITEM GetCategoryID() { return kind; } +}; + +// ========================================================================= +// Loop +// ========================================================================= +class Loop { + public: + Data *owner = nullptr; // null for a bare `new Loop` + std::string cat; // WITH trailing dot + gemmi::cif::Loop *direct = nullptr; // FindLoop binds the gemmi loop directly + bool write_mode = false; + // write buffer (row-major); sub-tags only (no category prefix) + std::vector wtags; + std::vector> wrows; + // storage for borrowed pstr returns (Coot never frees these) + std::deque sret; + + Loop() {} + + gemmi::cif::Loop *gloop() const; // read loop, or nullptr (defined after Data) + + int GetLoopLength(); + int GetNofTags(); + pstr GetTag(int tagNo); + pstr GetField(int rowNo, int tagNo); + + pstr GetString (cpstr TName, int nrow, int &RC); + int GetReal (realtype &R, cpstr TName, int nrow, bool Remove = false); + int GetInteger (int &I, cpstr TName, int nrow, bool Remove = false); + + void AddLoopTag (cpstr T, bool Remove = true) { (void) Remove; wcol(T, true); } + void PutString (cpstr S, cpstr T, int nrow) { wput(T, nrow, S ? S : "."); } + void PutInteger (int I, cpstr T, int nrow) { wput(T, nrow, std::to_string(I)); } + void PutReal (realtype R, cpstr T, int nrow, int prec = 8) { + char b[64]; std::snprintf(b, sizeof b, "%.*f", prec, (double) R); wput(T, nrow, b); + } + void PutReal (realtype R, cpstr T, int nrow, cpstr /*format*/) { PutReal(R, T, nrow, 8); } + + // write helpers + int wcol(cpstr T, bool create); + void wput(cpstr T, int nrow, const std::string &val); + void flush(gemmi::cif::Block &b); +}; + +inline int Loop::wcol(cpstr T, bool create) { + for (size_t i = 0; i < wtags.size(); ++i) + if (wtags[i] == T) return (int) i; + if (!create) return -1; + wtags.push_back(T); + for (auto &row : wrows) row.resize(wtags.size()); + return (int) wtags.size() - 1; +} + +inline void Loop::wput(cpstr T, int nrow, const std::string &val) { + write_mode = true; + int col = wcol(T, true); + if (nrow < 0) nrow = 0; + while ((int) wrows.size() <= nrow) wrows.emplace_back(wtags.size()); + wrows[nrow][col] = val; +} + +inline void Loop::flush(gemmi::cif::Block &b) { + if (wtags.empty()) return; + gemmi::cif::Loop &gl = b.init_mmcif_loop(cat, wtags); // tags become cat+subtag + gl.values.clear(); + gl.values.reserve(wrows.size() * wtags.size()); + for (auto &row : wrows) + for (size_t c = 0; c < wtags.size(); ++c) { + const std::string &v = c < row.size() ? row[c] : std::string(); + gl.values.push_back(v.empty() ? "." : gemmi::cif::quote(v)); + } +} + +inline int Loop::GetLoopLength() { + gemmi::cif::Loop *g = gloop(); + return g ? (int) g->length() : (int) wrows.size(); +} +inline int Loop::GetNofTags() { + gemmi::cif::Loop *g = gloop(); + return g ? (int) g->width() : (int) wtags.size(); +} + +// ========================================================================= +// Struct (single-value category = a set of tag/value pairs) +// ========================================================================= +class Struct { + public: + Data *owner = nullptr; + std::string cat; // WITH trailing dot + bool write_mode = false; + std::vector> wpairs; + std::deque sret; + + Struct() {} + + pstr GetCategoryName() { + sret.push_back(detail::strip_dot(cat)); + return (pstr) sret.back().c_str(); + } + + int GetNofTags(); + pstr GetTag(int tagNo); + pstr GetField(int tagNo); + pstr GetString (cpstr TName, int &RC); + int GetReal (realtype &R, cpstr TName, bool Remove = false); + int GetInteger (int &I, cpstr TName, bool Remove = false); + + void PutString (cpstr S, cpstr TName, bool /*Concatenate*/ = false) { + write_mode = true; wpairs.emplace_back(TName, S ? S : "."); + } + void PutReal (realtype R, cpstr TName, int prec = 8) { + char b[64]; std::snprintf(b, sizeof b, "%.*f", prec, (double) R); + write_mode = true; wpairs.emplace_back(TName, b); + } + void PutReal (realtype R, cpstr TName, cpstr /*format*/) { PutReal(R, TName, 8); } + void PutInteger (int I, cpstr TName) { + write_mode = true; wpairs.emplace_back(TName, std::to_string(I)); + } + + std::vector collect_tags(); // read: sub-tags present in block + void flush(gemmi::cif::Block &b); +}; + +// ========================================================================= +// Data (a data_ block) +// ========================================================================= +class Data { + public: + gemmi::cif::Document *doc = nullptr; // resolve block by INDEX (blocks vector reallocs) + size_t idx = 0; + std::unique_ptr owned_doc; // for a standalone `new Data()` + + std::deque loops; + std::deque structs; + std::deque cats_pool; + std::unordered_map loop_by_cat; + std::unordered_map struct_by_cat; + std::vector cat_names; // WITH dot + bool cats_built = false; + std::deque sret; + + Data() {} + + gemmi::cif::Block &blk() { return doc->blocks[idx]; } + + // standalone read (Coot: `Data d; d.ReadMMCIFData(fname)`) — own a Document and + // point at its first block. Used for small-molecule CIFs. + int SetFlag(int /*flag*/) { return 0; } // parse flags are gemmi-internal — no-op + int ReadMMCIFData(cpstr fname) { + try { owned_doc.reset(new gemmi::cif::Document(gemmi::cif::read_file(fname ? fname : ""))); } + catch (const std::exception &) { return CIFRC_CantOpenFile; } + if (owned_doc->blocks.empty()) return CIFRC_NoDataLine; + doc = owned_doc.get(); idx = 0; cats_built = false; + return CIFRC_Ok; + } + // find the loop containing tags[0] (a null-terminated tag array; core-CIF flat + // tags). Binds the gemmi loop directly (cat="" so GetString uses full tags). + // Coot passes both `pstr[]` and `const char*[]`, so accept cpstr. + PLoop FindLoop(cpstr *tags) { + if (!tags || !tags[0]) return nullptr; + gemmi::cif::Loop *gl = blk().find_loop(tags[0]).get_loop(); + if (!gl) return nullptr; + loops.emplace_back(); + Loop &l = loops.back(); + l.owner = this; l.cat = ""; l.direct = gl; + return &l; + } + PLoop FindLoop(pstr *tags) { return FindLoop((cpstr *) tags); } + + void build_cats() { + if (cats_built) return; + cat_names = blk().get_mmcif_category_names(); // returns WITH trailing dot + cats_built = true; + } + + pstr GetDataName() { + sret.push_back(blk().name); + return (pstr) sret.back().c_str(); + } + void GetDataName(pstr &dname, bool /*Remove*/ = false) { + sret.push_back(blk().name); + dname = (pstr) sret.back().c_str(); + } + void PutDataName(cpstr dname) { blk().name = dname ? dname : ""; } + + int GetNumberOfCategories() { build_cats(); return (int) cat_names.size(); } + + PCategory GetCategory(int categoryNo) { + build_cats(); + if (categoryNo < 0 || (size_t) categoryNo >= cat_names.size()) return nullptr; + cats_pool.emplace_back(); + Category &c = cats_pool.back(); + c.cat = cat_names[categoryNo]; + gemmi::cif::Table t = blk().find_mmcif_category(c.cat); + c.kind = t.get_loop() ? MMCIF_Loop : MMCIF_Struct; + return &c; + } + + PLoop GetLoop(cpstr CName) { + std::string key = detail::with_dot(CName); + auto it = loop_by_cat.find(key); + if (it != loop_by_cat.end()) return it->second; + if (!blk().find_mmcif_category(key).get_loop()) return nullptr; // absent or a struct + loops.emplace_back(); + Loop &l = loops.back(); + l.owner = this; l.cat = key; l.write_mode = false; + loop_by_cat[key] = &l; + return &l; + } + + PStruct GetStructure(cpstr CName) { + std::string key = detail::with_dot(CName); + auto it = struct_by_cat.find(key); + if (it != struct_by_cat.end()) return it->second; + if (!blk().has_mmcif_category(key)) return nullptr; + if (blk().find_mmcif_category(key).get_loop()) return nullptr; // it's a loop + structs.emplace_back(); + Struct &s = structs.back(); + s.owner = this; s.cat = key; s.write_mode = false; + struct_by_cat[key] = &s; + return &s; + } + + int GetLoopLength(cpstr CName) { + PLoop l = GetLoop(CName); + return l ? l->GetLoopLength() : CIFRC_NoCategory; + } + + // full mmCIF tag from (CName, TName): if CName is empty, TName is already the + // full tag (small-molecule CIFs pass "" + "_cell_length_a"). + std::string full_tag(cpstr CName, cpstr TName) { + std::string t = TName ? TName : ""; + return (CName && CName[0]) ? detail::with_dot(CName) + t : t; + } + // struct-style direct access (Data::GetString(CName, TName, RC) etc.) + pstr GetString(cpstr CName, cpstr TName, int &RC) { + const std::string *v = blk().find_value(full_tag(CName, TName)); + if (!v) { RC = CIFRC_NoTag; return nullptr; } + RC = CIFRC_Ok; + if (gemmi::cif::is_null(*v)) return nullptr; + sret.push_back(gemmi::cif::as_string(*v)); + return (pstr) sret.back().c_str(); + } + // pstr& form: sets S to the value, returns a CIFRC code (Coot: ierr += ...) + int GetString(pstr &S, cpstr CName, cpstr TName, bool /*Remove*/ = false) { + int rc = 0; + S = GetString(CName, TName, rc); + return rc; + } + int GetReal(realtype &R, cpstr CName, cpstr TName, bool /*Remove*/ = false) { + R = 0; + const std::string *v = blk().find_value(full_tag(CName, TName)); + if (!v) return CIFRC_NoTag; + if (gemmi::cif::is_null(*v)) return CIFRC_NoData; + try { R = std::stod(gemmi::cif::as_string(*v)); } catch (...) { return CIFRC_WrongFormat; } + return CIFRC_Ok; + } + int GetInteger(int &I, cpstr CName, cpstr TName, bool /*Remove*/ = false) { + I = 0; + const std::string *v = blk().find_value(full_tag(CName, TName)); + if (!v) return CIFRC_NoTag; + if (gemmi::cif::is_null(*v)) return CIFRC_NoData; + try { I = std::stoi(gemmi::cif::as_string(*v)); } catch (...) { return CIFRC_WrongFormat; } + return CIFRC_Ok; + } + + int AddLoop(cpstr CName, PLoop &cifLoop) { + std::string key = detail::with_dot(CName); + auto it = loop_by_cat.find(key); + if (it != loop_by_cat.end()) { cifLoop = it->second; return CIFRC_Ok; } + loops.emplace_back(); + Loop &l = loops.back(); + l.owner = this; l.cat = key; l.write_mode = true; + loop_by_cat[key] = &l; + cifLoop = &l; + return CIFRC_Created; + } + int AddStructure(cpstr CName, PStruct &cifStruct) { + std::string key = detail::with_dot(CName); + auto it = struct_by_cat.find(key); + if (it != struct_by_cat.end()) { cifStruct = it->second; return CIFRC_Ok; } + structs.emplace_back(); + Struct &s = structs.back(); + s.owner = this; s.cat = key; s.write_mode = true; + struct_by_cat[key] = &s; + cifStruct = &s; + return CIFRC_Created; + } + + void flush() { + for (auto &l : loops) if (l.write_mode) l.flush(blk()); + for (auto &s : structs) if (s.write_mode) s.flush(blk()); + } +}; + +// ---- Loop methods that need a complete Data ----------------------------- +inline gemmi::cif::Loop *Loop::gloop() const { + if (direct) return direct; // FindLoop-bound (core CIF) + if (write_mode || !owner) return nullptr; + return owner->blk().find_mmcif_category(cat).get_loop(); +} + +inline pstr Loop::GetString(cpstr TName, int nrow, int &RC) { + gemmi::cif::Loop *g = gloop(); + if (!g) { RC = CIFRC_NotALoop; return nullptr; } + int col = g->find_tag(cat + TName); + if (col < 0) { RC = CIFRC_NoTag; return nullptr; } + if (nrow < 0 || (size_t) nrow >= g->length()) { RC = CIFRC_WrongIndex; return nullptr; } + const std::string &raw = g->val(nrow, col); + RC = CIFRC_Ok; + if (gemmi::cif::is_null(raw)) return nullptr; + sret.push_back(gemmi::cif::as_string(raw)); + return (pstr) sret.back().c_str(); +} +inline int Loop::GetReal(realtype &R, cpstr TName, int nrow, bool /*Remove*/) { + R = 0; + gemmi::cif::Loop *g = gloop(); + if (!g) return CIFRC_NotALoop; + int col = g->find_tag(cat + TName); + if (col < 0) return CIFRC_NoTag; + if (nrow < 0 || (size_t) nrow >= g->length()) return CIFRC_WrongIndex; + const std::string &raw = g->val(nrow, col); + if (gemmi::cif::is_null(raw)) return CIFRC_NoData; + try { R = std::stod(gemmi::cif::as_string(raw)); } catch (...) { return CIFRC_WrongFormat; } + return CIFRC_Ok; +} +inline int Loop::GetInteger(int &I, cpstr TName, int nrow, bool /*Remove*/) { + I = 0; + gemmi::cif::Loop *g = gloop(); + if (!g) return CIFRC_NotALoop; + int col = g->find_tag(cat + TName); + if (col < 0) return CIFRC_NoTag; + if (nrow < 0 || (size_t) nrow >= g->length()) return CIFRC_WrongIndex; + const std::string &raw = g->val(nrow, col); + if (gemmi::cif::is_null(raw)) return CIFRC_NoData; + try { I = std::stoi(gemmi::cif::as_string(raw)); } catch (...) { return CIFRC_WrongFormat; } + return CIFRC_Ok; +} +inline pstr Loop::GetTag(int tagNo) { + gemmi::cif::Loop *g = gloop(); + if (!g) { if (tagNo < 0 || (size_t) tagNo >= wtags.size()) return nullptr; + sret.push_back(wtags[tagNo]); return (pstr) sret.back().c_str(); } + if (tagNo < 0 || (size_t) tagNo >= g->tags.size()) return nullptr; + std::string t = g->tags[tagNo]; + if (t.size() > cat.size() && t.compare(0, cat.size(), cat) == 0) t = t.substr(cat.size()); + sret.push_back(t); + return (pstr) sret.back().c_str(); +} +inline pstr Loop::GetField(int rowNo, int tagNo) { + gemmi::cif::Loop *g = gloop(); + if (!g) return nullptr; + if (tagNo < 0 || (size_t) tagNo >= g->width()) return nullptr; + if (rowNo < 0 || (size_t) rowNo >= g->length()) return nullptr; + const std::string &raw = g->val(rowNo, tagNo); + if (gemmi::cif::is_null(raw)) return nullptr; + sret.push_back(gemmi::cif::as_string(raw)); + return (pstr) sret.back().c_str(); +} + +// ---- Struct methods that need a complete Data --------------------------- +inline std::vector Struct::collect_tags() { + std::vector out; + if (!owner) return out; + for (const gemmi::cif::Item &it : owner->blk().items) + if (it.type == gemmi::cif::ItemType::Pair && + it.pair[0].compare(0, cat.size(), cat) == 0) + out.push_back(it.pair[0].substr(cat.size())); + return out; +} +inline int Struct::GetNofTags() { return (int) collect_tags().size(); } +inline pstr Struct::GetTag(int tagNo) { + std::vector t = collect_tags(); + if (tagNo < 0 || (size_t) tagNo >= t.size()) return nullptr; + sret.push_back(t[tagNo]); + return (pstr) sret.back().c_str(); +} +inline pstr Struct::GetField(int tagNo) { + std::vector t = collect_tags(); + if (tagNo < 0 || (size_t) tagNo >= t.size()) return nullptr; + int rc = 0; + return GetString(t[tagNo].c_str(), rc); +} +inline pstr Struct::GetString(cpstr TName, int &RC) { + if (!owner) { RC = CIFRC_NoTag; return nullptr; } + const std::string *v = owner->blk().find_value(cat + TName); + if (!v) { RC = CIFRC_NoTag; return nullptr; } + RC = CIFRC_Ok; + if (gemmi::cif::is_null(*v)) return nullptr; + sret.push_back(gemmi::cif::as_string(*v)); + return (pstr) sret.back().c_str(); +} +inline int Struct::GetReal(realtype &R, cpstr TName, bool /*Remove*/) { + R = 0; + if (!owner) return CIFRC_NoTag; + const std::string *v = owner->blk().find_value(cat + TName); + if (!v) return CIFRC_NoTag; + if (gemmi::cif::is_null(*v)) return CIFRC_NoData; + try { R = std::stod(gemmi::cif::as_string(*v)); } catch (...) { return CIFRC_WrongFormat; } + return CIFRC_Ok; +} +inline int Struct::GetInteger(int &I, cpstr TName, bool /*Remove*/) { + I = 0; + if (!owner) return CIFRC_NoTag; + const std::string *v = owner->blk().find_value(cat + TName); + if (!v) return CIFRC_NoTag; + if (gemmi::cif::is_null(*v)) return CIFRC_NoData; + try { I = std::stoi(gemmi::cif::as_string(*v)); } catch (...) { return CIFRC_WrongFormat; } + return CIFRC_Ok; +} +inline void Struct::flush(gemmi::cif::Block &b) { + for (auto &tv : wpairs) + b.set_pair(cat + tv.first, gemmi::cif::quote(tv.second)); +} + +// ========================================================================= +// File (a whole CIF document) +// ========================================================================= +class File { + public: + gemmi::cif::Document doc; + std::deque datas; + std::deque sret; + + File() {} + + void rebuild() { + datas.clear(); + for (size_t i = 0; i < doc.blocks.size(); ++i) { + datas.emplace_back(); + datas.back().doc = &doc; + datas.back().idx = i; + } + } + + int ReadMMCIFFile(cpstr FName, int /*flags*/ = 0) { + try { doc = gemmi::cif::read_file(FName ? FName : ""); } + catch (const std::exception &) { return CIFRC_CantOpenFile; } + rebuild(); + return CIFRC_Ok; + } + + int WriteMMCIFFile(cpstr FName, int /*flags*/ = 0) { + for (auto &d : datas) d.flush(); + std::ofstream os(FName ? FName : ""); + if (!os) return CIFRC_CantOpenFile; + gemmi::cif::write_cif_to_stream(os, doc, gemmi::cif::WriteOptions()); + return 0; + } + + int GetNofData() { return (int) datas.size(); } + int GetNumberOfData() { return (int) datas.size(); } + + PData GetCIFData(int dataNo) { + if (dataNo < 0 || (size_t) dataNo >= datas.size()) return nullptr; + return &datas[dataNo]; + } + PData GetCIFData(cpstr name) { + std::string n(name ? name : ""); + for (auto &d : datas) + if (d.blk().name == n) return &d; + return nullptr; + } + + int AddCIFData(cpstr name) { + std::string n(name ? name : ""); + if (doc.find_block(n)) return CIFRC_Ok; + doc.add_new_block(n); + // index-based Data wrappers survive blocks-vector reallocation, so just + // append one for the new block (do NOT rebuild — that would drop buffered + // write state of earlier Data objects). + datas.emplace_back(); + datas.back().doc = &doc; + datas.back().idx = doc.blocks.size() - 1; + return CIFRC_Created; + } +}; + +// ---- free helpers -------------------------------------------------------- +inline pstr GetCIFMessage(pstr buffer, int rc) { + const char *m = "unknown mmCIF return code"; + switch (rc) { + case CIFRC_Ok: m = "no errors"; break; + case CIFRC_NoCategory: m = "category not found"; break; + case CIFRC_NoTag: m = "tag not found"; break; + case CIFRC_NoField: m = "field not found"; break; + case CIFRC_WrongFormat: m = "wrong value format"; break; + case CIFRC_WrongIndex: m = "row index out of range"; break; + case CIFRC_NotALoop: m = "category is not a loop"; break; + case CIFRC_NotAStructure: m = "category is not a structure"; break; + case CIFRC_NoData: m = "no data"; break; + case CIFRC_CantOpenFile: m = "cannot open file"; break; + case CIFRC_NoDataLine: m = "no data_ line"; break; + case CIFRC_Created: m = "category created"; break; + default: break; + } + std::strcpy(buffer, m); + return buffer; +} + +} // namespace mmcif +} // namespace mmdb + +#endif // COOT_MMDB_SHIM_MMCIF_IMPL_HH diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh index af359ee143..4f64061ce0 100644 --- a/mmdb-shim/include/mmdb2/_shim_impl.hh +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -11,8 +11,13 @@ #pragma once #include +#include +#include // space-group / symmetry operators +#include +#include #include +#include #include #include #include @@ -36,6 +41,30 @@ typedef char ChainID[10]; typedef char Element[10]; typedef char AltLoc[20]; typedef char SegID[10]; +typedef char LinkRID[20]; // Refmac link ID +typedef unsigned char byte; // mmdb_mattype.h +typedef int *ivector; // mmdb_mattype.h 1-based vectors/matrices +typedef realtype *rvector; +typedef ivector *imatrix; +typedef rvector *rmatrix; +typedef char maxMMDBName[40]; + +// WhatIsSet mask flags (mmdb_atom.h ASET_FLAG) +enum ASET_FLAG { + ASET_Coordinates = 0x00000001, ASET_Occupancy = 0x00000002, + ASET_tempFactor = 0x00000004, ASET_CoordSigma = 0x00000010, + ASET_OccSigma = 0x00000020, ASET_tFacSigma = 0x00000040, + ASET_Charge = 0x00000080, ASET_Anis_tFac = 0x00000100, + ASET_Anis_tFSigma = 0x00001000, ASET_All = 0x000FFFFF +}; + +// vector/matrix types (mmdb_defs.h) — plain fixed-size arrays of realtype +typedef realtype vect3[3]; +typedef realtype vect4[4]; +typedef vect3 mat33[3]; // realtype[3][3] +typedef vect4 mat44[4]; // realtype[4][4] +typedef mat44 *pmat44; +typedef mat44 &rmat44; enum ERROR_CODE { Error_NoError = 0, @@ -55,7 +84,25 @@ enum SELECTION_TYPE { STYPE_INVALID = -1, STYPE_UNDEFINED = 0, STYPE_ATOM = 1, enum SELECTION_KEY { SKEY_NEW = 0, SKEY_OR = 1, SKEY_AND = 2, SKEY_XOR = 3, SKEY_CLR = 4, SKEY_XAND = 100 }; inline const long int MinInt4 = -2147483647; +inline const long int MaxInt4 = 2147483647; inline const int ANY_RES = -2147483647; // real MMDB: extern const == MinInt4 +inline const double Pi = 3.14159265358979323846; + +// PDB/CIF read flags (mmdb_io_file.h). Values are arbitrary distinct bits — the +// shim's SetFlag is a no-op, so only distinctness matters for Coot's bit ops. +enum MMDB_READ_FLAG { + MMDBF_AutoSerials = 0x00000001, + MMDBF_IgnoreDuplSeqNum = 0x00000002, + MMDBF_IgnoreBlankLines = 0x00000004, + MMDBF_IgnoreRemarks = 0x00000008, + MMDBF_IgnoreHash = 0x00000010, + MMDBF_IgnoreNonCoorPDBErrors = 0x00000020, + MMDBF_PrintCIFWarnings = 0x00000040, + MMDBF_All = 0x0000FFFF +}; +enum MMDB_FCM { MMDBFCM_None = 0, MMDBFCM_All = 1, MMDBFCM_Coord = 2, + MMDBFCM_Cryst = 4, MMDBFCM_SC = 8 }; +typedef int COPY_MASK; // Coot uses `COPY_MASK cm = MMDBFCM_All` + bit arithmetic // Per-object UDData slots + selection membership bits. Each registered UDData // handle maps to a (type,kind,slot); the object stores contiguous vectors @@ -80,14 +127,19 @@ typedef Atom *PAtom; typedef Atom **PPAtom; typedef Residue *PResidue; typedef Residue **PPResidue; typedef Chain *PChain; typedef Chain **PPChain; typedef Model *PModel; typedef Model **PPModel; +typedef Manager *PManager; typedef Manager **PPManager; struct Contact { int id1, id2; long group; realtype dist; }; typedef Contact *PContact; +// base for records held in MMDB containers (Title compound/author, LINK, …) +class ContainerClass { public: virtual ~ContainerClass() {} }; +typedef ContainerClass *PContainerClass; + // LINK record. Public data members mirror real MMDB (Coot reads them directly). // Not gemmi-backed yet — Model::GetNumberOfLinks currently returns 0 (TODO: map // gemmi Structure connections), so these are declared for compilation. -class Link { +class Link : public ContainerClass { public: AtomName atName1{}, atName2{}; AltLoc aloc1{}, aloc2{}; @@ -95,28 +147,217 @@ public: ChainID chainID1{}, chainID2{}; InsCode insCode1{}, insCode2{}; int seqNum1 = 0, seqNum2 = 0; + int s1 = 1, i1 = 0, j1 = 0, k1 = 0; // symmetry id of 1st atom + int s2 = 1, i2 = 0, j2 = 0, k2 = 0; // symmetry id of 2nd atom realtype dist = 0; + void Copy(PContainerClass o) { if (auto *l = dynamic_cast(o)) *this = *l; } }; typedef Link *PLink; typedef Link **PPLink; +// Refmac LINK record (mmdb_model.h LinkR). Public members mirror real MMDB; +// Model::GetNumberOfLinkRs returns 0 for now (TODO: map gemmi connections). +class LinkR { +public: + LinkRID linkRID{}; + AtomName atName1{}, atName2{}; + AltLoc aloc1{}, aloc2{}; + ResName resName1{}, resName2{}; + ChainID chainID1{}, chainID2{}; + int seqNum1 = 0, seqNum2 = 0; + InsCode insCode1{}, insCode2{}; + realtype dist = 0; +}; +typedef LinkR *PLinkR; typedef LinkR **PPLinkR; + +// CIS-peptide record (mmdb_model.h CisPep). Public members mirror real MMDB; +// Model::GetNumberOfCisPeps returns 0 for now (TODO: map gemmi cispeps). +class CisPep { +public: + int serNum = 0; + ResName pep1{}; + ChainID chainID1{}; + int seqNum1 = 0; + InsCode icode1{}; + ResName pep2{}; + ChainID chainID2{}; + int seqNum2 = 0; + InsCode icode2{}; + int modNum = 0; + realtype measure = 0; +}; +typedef CisPep *PCisPep; + +// Container of LINK records (mmdb_model.h LinkContainer). Minimal: Coot only +// declares `empty_links_container()` returning one by value; never dereferenced. +class LinkContainer { +public: + std::vector data; + int Length() { return (int)data.size(); } + PContainerClass GetContainerClass(int i) { return (i >= 0 && i < (int)data.size()) ? data[i] : nullptr; } +}; +typedef LinkContainer *PLinkContainer; + +// PDB title records (mmdb_title.h). Coot subclasses Manager & Title to reach the +// COMPND/AUTHOR line containers. Not gemmi-backed yet (title/header records are +// dropped on round-trip) — just enough surface to compile & run. TODO: map to +// gemmi Structure meta (raw_remarks / metadata). +class Compound : public ContainerClass { public: char Line[256] = {0}; }; +typedef Compound *PCompound; +class TitleContainer { +public: + std::vector data; + int Length() { return (int)data.size(); } + PContainerClass GetContainerClass(int i) { + return (i >= 0 && i < (int)data.size()) ? data[i] : nullptr; + } +}; +class Title { +public: + TitleContainer compound, author; // public so Coot's access_title can reach them +}; + +// Crystal/symmetry record (mmdb_cryst.h). Minimal — used by Coot as a pointer +// type; symmetry math goes through Manager::GetTMatrix (gemmi TODO). +class Cryst { public: + virtual ~Cryst() {} + // symmetry not carried on the bare Cryst (Manager owns gemmi cell/SG) — identity/0. + int GetTMatrix(mat44 &T, int Nop, int a, int b, int c) { + for (int i=0;i<4;i++) for (int j=0;j<4;j++) T[i][j]=(i==j)?1.0:0.0; + return (Nop==0 && a==0 && b==0 && c==0) ? 0 : 1; + } + int GetNumberOfSymOps() { return 0; } + pstr GetSymOp(int) { return nullptr; } +}; +typedef Cryst *PCryst; + +// initialise a 4x4 matrix to identity (mmdb_mattype.h Mat4Init) +inline void Mat4Init(mat44 &A) { + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 4; ++j) A[i][j] = (i == j) ? 1.0 : 0.0; +} + +// mmdb::math graph-matching subsystem — forward decls only for now (headers use +// Graph/GraphMatch/Edge by pointer/reference). Full gemmi-backed impl is a +// separate task; see coot/mmdb-graph-matching-for-gemmi.md. +namespace math { + class Graph; class GraphMatch; class Vertex; class Edge; class Alignment; + typedef Graph *PGraph; + typedef GraphMatch *PGraphMatch; + typedef Vertex *PVertex; typedef Vertex **PPVertex; + typedef Edge *PEdge; typedef Edge **PPEdge; +} + +struct AtomBond { PAtom atom = nullptr; int order = 0; }; +typedef AtomBond *PAtomBond; typedef AtomBond **PPAtomBond; + +struct AtomStat { // selection coordinate statistics (mmdb_atom.h) + int nAtoms = 0; + realtype xmin = 0, ymin = 0, zmin = 0, xmax = 0, ymax = 0, zmax = 0; + realtype xm = 0, ym = 0, zm = 0; // coordinate means (centroid) + realtype GetMaxSize() { + realtype dx = xmax - xmin, dy = ymax - ymin, dz = zmax - zmin; + return dx > dy ? (dx > dz ? dx : dz) : (dy > dz ? dy : dz); + } +}; +typedef AtomStat &RAtomStat; + +// secondary-structure element codes (mmdb_tables.h) +enum SSE_CODE { SSE_None = 0, SSE_Strand = 1, SSE_Bulge = 2, SSE_3Turn = 3, + SSE_4Turn = 4, SSE_5Turn = 5, SSE_Helix = 6 }; + +// PDBCleanup flags (mmdb_root.h) — bit flags OR'd into PDBCleanup(word) +// misc return-code / sort-key enums (mmdb_cryst.h / mmdb_selmngr.h / mmdb_tables.h) +enum { SYMOP_Ok = 0, SYMOP_NoLibFile = -1, SYMOP_UnknownSpaceGroup = -2 }; +enum { SSERC_Ok = 0, SSERC_noResidues = 1 }; +enum { SORT_CHAIN_ChainID_Asc = 0, SORT_CHAIN_ChainID_Desc = 1 }; +enum { CNSORT_OFF = 0, CNSORT_1INC = 1, CNSORT_1DEC = 2, CNSORT_2INC = 3, CNSORT_2DEC = 4 }; + +enum PDB_CLEAN_FLAG { + PDBCLEAN_ATNAME = 0x00000001, + PDBCLEAN_TER = 0x00000002, + PDBCLEAN_CHAIN = 0x00000004, + PDBCLEAN_CHAIN_STRONG = 0x00000008, + PDBCLEAN_ALTCODE = 0x00000010, + PDBCLEAN_ALTCODE_STRONG = 0x00000020, + PDBCLEAN_SERIAL = 0x00000040, + PDBCLEAN_SEQNUM = 0x00000080, + PDBCLEAN_INDEX = 0x00000800, + PDBCLEAN_ELEMENT = 0x00001000, + PDBCLEAN_ELEMENT_STRONG = 0x00002000 +}; + +// SS records — minimal public-member structs. Model::GetNumberOf{Helices,Sheets} +// return 0 for now (TODO: map gemmi Structure helices/sheets), so these aren't +// dereferenced; fields present for compilation. +class Helix { public: + ChainID initChainID{}, endChainID{}; int initSeqNum = 0, endSeqNum = 0, serNum = 0, helixClass = 0, length = 0; + ResName initResName{}, endResName{}; InsCode initICode{}, endICode{}; char helixID[20]{}, comment[80]{}; +}; +class Strand { public: + ChainID initChainID{}, endChainID{}; int initSeqNum = 0, endSeqNum = 0, strandNo = 0, sense = 0; + ResName initResName{}, endResName{}; InsCode initICode{}, endICode{}; char sheetID[20]{}; +}; +class Sheet { public: int nStrands = 0; Strand **strand = nullptr; char sheetID[20]{}; }; +class Sheets { public: int nSheets = 0; Sheet **sheet = nullptr; }; // container (SS TODO) +typedef Helix *PHelix; typedef Strand *PStrand; typedef Sheet *PSheet; typedef Sheets *PSheets; +// container of helices (Model.helices); Coot's access_model subclass fills it. +class Helices { public: std::vector data; void AddData(PHelix h) { if (h) data.push_back(h); } int nHelices = 0; }; + +// container of symmetry operators (mmdb_symop.h SymOps). Coot fills it from a +// space group; ops are xyz-triplet strings. +class SymOps { + std::vector ops; + std::deque buf; +public: + int AddSymOp(cpstr xyz) { ops.push_back(xyz ? xyz : ""); return 0; } + int GetNofSymOps() { return (int)ops.size(); } + pstr GetSymOp(int n) { + if (n < 0 || n >= (int)ops.size()) return nullptr; + buf.push_back(ops[n]); return (pstr) buf.back().c_str(); + } + void FreeMemory() { ops.clear(); } +}; + [[noreturn]] inline void unimpl(const char *w) { throw std::logic_error(std::string("mmdb-shim: unimplemented: ") + w); } +// ---- free functions (mmdb_tables.h / mmdb_mattype.h) ---- +inline void InitMatType() {} // real MMDB inits static matrix-type tables; no-op here +inline cpstr GetErrorDescription(ERROR_CODE ec) { + switch (ec) { + case Error_NoError: return "no error"; + case Error_CantOpenFile: return "cannot open file"; + default: return "MMDB error"; + } +} +inline realtype getVdWaalsRadius(cpstr element) { + return gemmi::Element(element ? element : "X").vdw_r(); +} + // UDData helpers (defined after Manager); each class forwards with its UDR type. int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int v); int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype v); int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, cpstr v); int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int &v); int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype &v); +int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, pstr &v); // =========================================================================== class Atom : public UDStore { public: Manager *mgr = nullptr; - Residue *res = nullptr; // parent + Residue *res = nullptr; // parent; null => detached (use _local) int ai = 0; // cached index within parent residue's atoms bool alive = true; + gemmi::Atom _local; // backing store while detached (see g() resolvers) + int Het = 0; // heteroatom flag (MMDB public field; Coot sets it) + int Ter = 0; // chain-terminator flag (gemmi has none -> always 0) + word WhatIsSet = 0; // ASET_* mask; ASET_Anis_tFac set on load if aniso present + AtomName label_atom_id{}; // mmcif label_atom_id (shim-owned; Coot sets on build) + + Atom() = default; + explicit Atom(Residue *r); // construct + add to residue (out-of-line) gemmi::Atom &g() const; // resolve to live gemmi (defined after Manager) @@ -125,33 +366,82 @@ public: // `->field()` rewrite covers both reads and writes. (occ/b_iso/charge are // narrower than realtype in gemmi, so those refs are float/schar-typed — the // rare take-address-of-realtype sites surface at Coot build time.) - realtype &x() { return g().pos.x; } - realtype &y() { return g().pos.y; } - realtype &z() { return g().pos.z; } - float &occupancy() { return g().occ; } - float &tempFactor() { return g().b_iso; } - char &altLoc() { return g().altloc; } - signed char &charge() { return g().charge; } - int &serNum() { return g().serial; } + // non-const (writable ref) + const (by value) overloads, so reads work on a + // `const mmdb::Atom` and writes work through `->x() = v` on a non-const one. + realtype &x() { return g().pos.x; } realtype x() const { return g().pos.x; } + realtype &y() { return g().pos.y; } realtype y() const { return g().pos.y; } + realtype &z() { return g().pos.z; } realtype z() const { return g().pos.z; } + float &occupancy() { return g().occ; } float occupancy() const { return g().occ; } + float &tempFactor() { return g().b_iso; } float tempFactor() const { return g().b_iso; } + signed char &charge() { return g().charge; } signed char charge() const { return g().charge; } + int &serNum() { return g().serial; } int serNum() const { return g().serial; } + // altLoc is a char[] (C-string) in MMDB; gemmi stores a single char. Return a + // buffer-backed C-string ("" when unset) so strcmp/strcpy-style code works. + // The non-const overload returns a WRITABLE buffer so `strncpy(at->altLoc(),..)` + // compiles; the buffer's first char is pushed back into gemmi by Residue::AddAtom + // (the buffer is refreshed from gemmi on entry, so reads stay correct). + pstr altLoc() { _altloc_buf[0] = g().altloc; _altloc_buf[1] = '\0'; return _altloc_buf; } + const char *altLoc() const { _altloc_buf[0] = g().altloc; _altloc_buf[1] = '\0'; return _altloc_buf; } void set_occupancy(realtype v) { g().occ = (float)v; } void set_tempFactor(realtype v) { g().b_iso = (float)v; } void set_altLoc(char c) { g().altloc = c; } + void SetCharge(realtype ch) { g().charge = (signed char) ch; } + bool isMetal() const { return gemmi::Element(g().element).is_metal(); } + // anisotropic B tensor — gemmi's SMat33 aniso. Reference-returning so the + // rewritten `->u11` covers both reads (bonds display) and writes (SHELX import). + // NOTE: writing here does not set ASET_Anis_tFac in WhatIsSet (TODO if needed). + float &u11() { return g().aniso.u11; } + float &u22() { return g().aniso.u22; } + float &u33() { return g().aniso.u33; } + float &u12() { return g().aniso.u12; } + float &u13() { return g().aniso.u13; } + float &u23() { return g().aniso.u23; } + // bonds — not modelled yet (gemmi connections); report none. + int GetNBonds() { return 0; } + void GetBonds(PAtomBond &atomBond, int &n) { atomBond = nullptr; n = 0; } + int AddBond(PAtom /*a*/, int /*order*/, int /*nAdd*/ = 1) { return 0; } + SegID segID{}; // shim-owned (gemmi has no segID); MMDB public char[] field // --- method surface (hot subset; rest stubbed) --- - pstr GetAtomName(); // aligned name, MMDB semantics + pstr GetAtomName() const; // aligned name, MMDB semantics (const: called on const Atom) void SetAtomName(const AtomName aName); pstr GetElementName(); void SetElementName(const Element elName); - cpstr GetChainID(); + pstr GetChainID(); int GetSeqNum(); pstr GetInsCode(); pstr GetResName(); - Residue *GetResidue() { return res; } + Residue *&GetResidue() { return res; } // ref: rewritten `->residue` is assignable + void SetResidue(Residue *r) { res = r; } + Chain *GetChain(); // out-of-line (needs complete Residue/Chain) + Model *GetModel(); // out-of-line int GetModelNum(); bool isTer() const { return false; } // gemmi has no TER atoms; see notes void SetCoordinates(realtype xx, realtype yy, realtype zz, realtype occ, realtype tF); int GetIndex(); + void MakeTer() { Ter = 1; } // mark as chain terminator + pstr GetAtomID(pstr S); // "/mdl/chain/seq(res).ins/name[elem]:alt" (out-of-line) + int GetUDData(int h, pstr &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } + // copy another atom's data into this one (mmdb Atom::Copy — no hierarchy refs) + void Copy(PAtom a) { + g() = a->g(); + Het = a->Het; WhatIsSet = a->WhatIsSet; + std::memcpy(segID, a->segID, sizeof segID); + } + // apply a 4x4 (rot+trans) or 3x3+vec to the coordinates (mmdb Atom::Transform) + void Transform(const mat44 &tm) { + gemmi::Position &p = g().pos; double x = p.x, y = p.y, z = p.z; + p.x = tm[0][0]*x + tm[0][1]*y + tm[0][2]*z + tm[0][3]; + p.y = tm[1][0]*x + tm[1][1]*y + tm[1][2]*z + tm[1][3]; + p.z = tm[2][0]*x + tm[2][1]*y + tm[2][2]*z + tm[2][3]; + } + void Transform(const mat33 &tm, vect3 &v) { + gemmi::Position &p = g().pos; double x = p.x, y = p.y, z = p.z; + p.x = tm[0][0]*x + tm[0][1]*y + tm[0][2]*z + v[0]; + p.y = tm[1][0]*x + tm[1][1]*y + tm[1][2]*z + v[1]; + p.z = tm[2][0]*x + tm[2][1]*y + tm[2][2]*z + v[2]; + } // UDData int PutUDData(int h, int v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } int PutUDData(int h, realtype v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } @@ -160,17 +450,43 @@ public: int GetUDData(int h, realtype &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } private: - AtomName _name_buf{}; Element _elem_buf{}; + friend class Residue; // AddAtom pushes the strncpy'd altLoc buffer to gemmi + mutable AtomName _name_buf{}; Element _elem_buf{}; mutable char _altloc_buf[4]{}; }; // =========================================================================== class Residue : public UDStore { public: Manager *mgr = nullptr; - Chain *chain = nullptr; // parent + Chain *chain = nullptr; // parent; null => detached (use _local) int ri = 0; bool alive = true; + gemmi::Residue _local; // backing store while detached std::vector atoms; // canonical child wrappers == PPAtom table + PPAtom atom = nullptr; // MMDB public atom-table field; kept = atoms.data() + int nAtoms = 0; // MMDB public field; kept = atoms.size() + void _sync_atom() { atom = atoms.data(); nAtoms = (int)atoms.size(); } + // mmcif label_* (shim-owned; Coot sets when building dictionary residues) + ResName label_comp_id{}; ChainID label_asym_id{}; int label_seq_id = 0; + + Residue() = default; + explicit Residue(Chain *c); // construct + add to chain (out-of-line) + + // MMDB public char-array fields. Coot reads `residue->name` and writes + // `strncpy(residue->insCode,..)`. Kept as the interface: synced gemmi->buffer on + // load (_load_id, in build_from_gemmi) and buffer->gemmi at the adopt point + // (_store_id, in Chain::Add/InsResidue). SetResName/SetResID keep both in step. + ResName name{}; + InsCode insCode{}; + void _load_id() { + std::snprintf(name, sizeof name, "%s", g().name.c_str()); + insCode[0] = g().seqid.icode && g().seqid.icode != ' ' ? g().seqid.icode : '\0'; + insCode[1] = '\0'; + } + void _store_id() { + g().name = name; + g().seqid.icode = insCode[0] ? insCode[0] : ' '; + } gemmi::Residue &g() const; @@ -183,18 +499,53 @@ public: const AltLoc aloc = nullptr); void GetAtomTable(PPAtom &atomTable, int &n) { atomTable = atoms.data(); n = (int)atoms.size(); } PAtom AddAtom(Manager &m, gemmi::Atom a); // append: O(1) - int AddAtom(PAtom /*atm*/) { unimpl("Residue::AddAtom(PAtom)"); } + // Adopt a detached atom (Coot's `new mmdb::Atom` idiom). Copies the atom's + // local gemmi into this residue's gemmi (detached or bound, via g()) and + // rebinds the wrapper. Pushes the strncpy'd altLoc buffer back into gemmi. + int AddAtom(PAtom atm) { + g().atoms.push_back(atm->_local); + atm->res = this; atm->mgr = mgr; atm->ai = (int)atoms.size(); + if (atm->_altloc_buf[0]) g().atoms[atm->ai].altloc = atm->_altloc_buf[0]; + atoms.push_back(atm); + _sync_atom(); + return 0; + } void DeleteAtom(int pos); + void TrimAtomTable() {} // compact after deletions — shim keeps them in sync pstr GetResName(); - void SetResName(const ResName n) { g().name = n; } - int GetSeqNum(); + void SetResName(const ResName n) { + g().name = n ? n : ""; + std::snprintf(name, sizeof name, "%s", n ? n : ""); + } + void SetResID(const ResName resName, int seqNo, const InsCode ic) { + g().name = resName ? resName : ""; + g().seqid.num.value = seqNo; + g().seqid.icode = (ic && ic[0]) ? ic[0] : ' '; + std::snprintf(name, sizeof name, "%s", resName ? resName : ""); + insCode[0] = (ic && ic[0]) ? ic[0] : '\0'; insCode[1] = '\0'; + } + int &GetSeqNum(); // writable (rewrite maps `->seqNum` reads and writes) pstr GetInsCode(); - cpstr GetChainID(); + pstr GetChainID(); int GetModelNum(); - int GetIndex() { return ri; } + int &GetIndex() { return ri; } // ref: rewritten `->index` is assignable Chain *GetChain() { return chain; } + Model *GetModel() { return chain ? chain->model : nullptr; } + // terminus tests — positional within the chain (approximates MMDB's peptide-bond + // check; good enough for Coot's terminal-residue handling). TODO: bond-aware. + bool isNTerminus() { return chain && ri == 0; } + bool isCTerminus(); // last in chain (out-of-line: needs Chain) + pstr GetResidueID(pstr S) { // "seqnum(name):inscode" + if (S) std::snprintf(S, 100, "%d(%s):%s", GetSeqNum(), name, insCode); + return S; + } Residue *next = nullptr; // MMDB has this; wired lazily if needed + int SSE = SSE_None; // secondary-structure element (shim-owned public field) + bool isAminoacid() { return gemmi::find_tabulated_residue(g().name).is_amino_acid(); } + bool isNucleotide() { return gemmi::find_tabulated_residue(g().name).is_nucleic_acid(); } + bool isDNARNA() { return isNucleotide(); } + bool isSolvent() { return gemmi::find_tabulated_residue(g().name).is_water(); } // UDData int PutUDData(int h, int v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } int PutUDData(int h, realtype v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } @@ -210,9 +561,10 @@ private: class Chain : public UDStore { public: Manager *mgr = nullptr; - Model *model = nullptr; // parent + Model *model = nullptr; // parent; null => detached (use _local) int ci = 0; bool alive = true; + gemmi::Chain _local; // backing store while detached std::vector residues; gemmi::Chain &g() const; @@ -221,10 +573,60 @@ public: PResidue GetResidue(int resNo) { return (resNo >= 0 && resNo < (int)residues.size()) ? residues[resNo] : nullptr; } + // find by (seqNum, insCode) — MMDB's 2-arg overload + PResidue GetResidue(int seqNum, const InsCode insCode) { + char ic = (insCode && insCode[0]) ? insCode[0] : ' '; + for (Residue *r : residues) { + gemmi::Residue &gr = r->g(); + char ric = gr.seqid.icode ? gr.seqid.icode : ' '; + if (gr.seqid.num.value == seqNum && ric == ic) return r; + } + return nullptr; + } void GetResidueTable(PPResidue &t, int &n) { t = residues.data(); n = (int)residues.size(); } - cpstr GetChainID(); + // delete residue at index: erase gemmi + wrapper, reindex the tail + void DeleteResidue(int resNo) { + if (resNo < 0 || resNo >= (int)residues.size()) return; + g().residues.erase(g().residues.begin() + resNo); + residues.erase(residues.begin() + resNo); + for (int k = resNo; k < (int)residues.size(); ++k) residues[k]->ri = k; + } + void TrimResidueTable() {} // compact after deletions — shim stays in sync + void DeleteResidue(int seqNum, const InsCode ic) { // by (seqNum, insCode) + PResidue r = GetResidue(seqNum, ic); + if (r) DeleteResidue(r->ri); + } + pstr GetChainID(); + pstr GetChainID(pstr buf) { if (buf) std::snprintf(buf, sizeof(ChainID), "%s", g().name.c_str()); return buf; } + void SetChainID(const ChainID id) { g().name = id ? id : ""; } + Chain() = default; + Chain(Model *m, const ChainID id); // construct + add to model (out-of-line) + void Copy(PChain src); // deep-copy subtree (out-of-line: needs Manager) + void SortResidues(int /*sortKey*/ = 0) {} // gemmi keeps file order; no-op + bool isAminoacidChain(); // defined out-of-line (needs Residue predicates) + bool isNucleotideChain(); + bool isSolventChain(); PResidue AddResidue(Manager &m, gemmi::Residue r); // append PResidue InsResidue(Manager &m, int pos, gemmi::Residue r); + // Adopt a detached residue (its atom wrappers already point at it, so they + // ride along once its gemmi is copied in and the wrapper is rebound). + int AddResidue(PResidue res) { + res->_store_id(); // push name/insCode buffers into gemmi + g().residues.push_back(res->g()); // res detached -> its _local (with atoms) + res->chain = this; res->mgr = mgr; res->ri = (int)residues.size(); + residues.push_back(res); + return 0; + } + int InsResidue(PResidue res, int pos) { + if (pos < 0) pos = 0; + if (pos > (int)residues.size()) pos = (int)residues.size(); + res->_store_id(); + g().residues.insert(g().residues.begin() + pos, res->g()); + res->chain = this; res->mgr = mgr; res->ri = pos; + residues.insert(residues.begin() + pos, res); + for (int k = pos + 1; k < (int)residues.size(); ++k) residues[k]->ri = k; + return 0; + } private: ChainID _chainid_buf{}; @@ -233,8 +635,9 @@ private: // =========================================================================== class Model : public UDStore { public: - Manager *mgr = nullptr; + Manager *mgr = nullptr; // null => detached (use _local) int mi = 0; // 0-based internal; GetModel is 1-based externally + gemmi::Model _local{1}; // backing store while detached (gemmi Model num is int) std::vector chains; gemmi::Model &g() const; @@ -244,10 +647,75 @@ public: return (chainNo >= 0 && chainNo < (int)chains.size()) ? chains[chainNo] : nullptr; } PChain GetChain(const ChainID chID); + // Adopt a detached chain (Coot's `new mmdb::Chain` idiom): copy its local + // gemmi (with any residues/atoms) into this model and rebind, cascading mgr + // to the sub-tree that was built while detached (mgr was null). + int AddChain(PChain chn) { + g().chains.push_back(chn->g()); + chn->model = this; chn->mgr = mgr; chn->ci = (int)chains.size(); + chains.push_back(chn); + for (Residue *r : chn->residues) { + r->mgr = mgr; + for (Atom *a : r->atoms) a->mgr = mgr; + } + return 0; + } int GetSerNum() { return mi + 1; } - // LINK records — TODO: map from gemmi Structure connections. - int GetNumberOfLinks() { return 0; } - PLink GetLink(int /*i*/) { return nullptr; } + // delete chain at index: erase gemmi + wrapper, reindex the tail + void DeleteChain(int chainNo) { + if (chainNo < 0 || chainNo >= (int)chains.size()) return; + g().chains.erase(g().chains.begin() + chainNo); + chains.erase(chains.begin() + chainNo); + for (int k = chainNo; k < (int)chains.size(); ++k) chains[k]->ci = k; + } + void DeleteChain(const ChainID chainID) { + for (int i = 0; i < (int)chains.size(); ++i) + if (chains[i]->g().name == (chainID ? chainID : "")) { DeleteChain(i); return; } + } + void GetChainTable(PPChain &t, int &n) { t = chains.data(); n = (int)chains.size(); } + std::vector all_atoms; // flat, filled by build_from_gemmi + PPAtom GetAllAtoms() { return all_atoms.data(); } + int GetNumberOfAtoms() { return (int)all_atoms.size(); } + int GetNumberOfAtoms(bool /*countTers*/) { return (int)all_atoms.size(); } + int CalcSecStructure(bool /*flag*/) { return 0; } // TODO: gemmi SS assignment + // LINK records — Coot-owned Link* objects stored here (AddLink); GetLink is + // 1-based like MMDB. (Reading from gemmi connections is a separate TODO.) + std::vector _links; + int GetNumberOfLinks() { return (int)_links.size(); } + PLink GetLink(int i) { return (i >= 1 && i <= (int)_links.size()) ? _links[i - 1] : nullptr; } + void AddLink(PLink link) { if (link) _links.push_back(link); } + int GetNumberOfLinkRs() { return 0; } + PLinkR GetLinkR(int /*i*/) { return nullptr; } + std::vector _cispeps; + int GetNumberOfCisPeps() { return (int)_cispeps.size(); } + PCisPep GetCisPep(int i) { return (i >= 1 && i <= (int)_cispeps.size()) ? _cispeps[i - 1] : nullptr; } + void AddCisPep(PCisPep cp) { if (cp) _cispeps.push_back(cp); } + void RemoveCisPeps() { _cispeps.clear(); } + // secondary structure — TODO: map from gemmi helices/sheets. + int GetNumberOfHelices() { return 0; } + PHelix GetHelix(int /*i*/) { return nullptr; } + int GetNumberOfSheets() { return 0; } + PSheet GetSheet(int /*i*/) { return nullptr; } + Sheets sheets; // SS records (not gemmi-backed; access_model fills) + Helices helices; // " " " + PSheets GetSheets() { return &sheets; } + int GetModelID() { return mi + 1; } + pstr GetModelID(pstr buf) { if (buf) std::snprintf(buf, 16, "%d", mi + 1); return buf; } + int CalcSecStructure(int /*flag*/, int /*selHnd*/) { return SSERC_Ok; } // TODO gemmi SS + void Copy(PModel src); // deep-copy subtree (out-of-line) + Manager *GetCoordHierarchy() { return mgr; } // parent manager + int GetNumberOfResidues() { + int n = 0; for (Chain *c : chains) n += c->GetNumberOfResidues(); return n; + } + LinkContainer _linkc; + PLinkContainer GetLinks() { + _linkc.data.assign(_links.begin(), _links.end()); return &_linkc; + } + void RemoveLinks() { _links.clear(); } + void SortChains(int /*sortKey*/ = 0) {} // gemmi keeps file order; no-op + PChain CreateChain(const ChainID id); // add empty chain (out-of-line: needs Manager) + int GetNumberOfStrands(int /*sheetNo*/) { return 0; } + PStrand GetStrand(int /*sheetNo*/, int /*strandNo*/) { return nullptr; } }; // =========================================================================== @@ -271,9 +739,88 @@ public: int i = modelNo - 1; return (i >= 0 && i < (int)models.size()) ? models[i] : nullptr; } + // per-model chain access (modelNo is 1-based, chainNo 0-based) — mmdb_coormngr.h + int GetNumberOfChains(int modelNo) { + PModel m = GetModel(modelNo); return m ? m->GetNumberOfChains() : 0; + } + PChain GetChain(int modelNo, int chainNo) { + PModel m = GetModel(modelNo); return m ? m->GetChain(chainNo) : nullptr; + } + // Re-index/renumber after edits. The shim keeps sibling indices in sync as it + // mutates, so this is a no-op re-validation for now (TODO: serial renumbering). + word PDBCleanup(word /*CleanKey*/) { return 0; } + + // PDB title records — Coot reaches `title` via an access_mol subclass. + Title title; + pstr GetStructureTitle(pstr T) { if (T) T[0] = '\0'; return T; } + + // symmetry transformation matrix. Real symmetry needs gemmi spacegroup/cell; + // for now return identity for the no-op (Nop==0, no cell shift) and signal + // "no symmetry" (nonzero) otherwise so Coot skips symmetry expansion. TODO. + int GetTMatrix(mat44 &TMatrix, int Nop, int cellshift_a, int cellshift_b, int cellshift_c) { + Mat4Init(TMatrix); + return (Nop == 0 && cellshift_a == 0 && cellshift_b == 0 && cellshift_c == 0) ? 0 : 1; + } void build_from_gemmi(); + // adopt a detached model (Coot: `new mmdb::Model` -> AddChain… -> AddModel). + // Copy its local gemmi into st, rebind, cascade mgr through the sub-tree. + int AddModel(PModel mw) { + st.models.push_back(mw->g()); + mw->mgr = this; mw->mi = (int)models.size(); + models.push_back(mw); + for (Chain *cw : mw->chains) { + cw->mgr = this; + for (Residue *rw : cw->residues) { + rw->mgr = this; + for (Atom *aw : rw->atoms) { aw->mgr = this; all_atoms.push_back(aw); mw->all_atoms.push_back(aw); } + } + } + return 0; + } + + // clone another manager's structure (mmdb Manager::Copy(PManager, COPY_MASK)). + // Copies the whole gemmi Structure and rebuilds all wrappers — clean & correct. + void Copy(PManager m, int /*CopyMask*/) { if (m) { st = m->st; build_from_gemmi(); } } + + // ---- crystal cell & symmetry (gemmi UnitCell / SpaceGroup) ---- + std::string _sg_buf, _symop_buf; + void GetCell(realtype &a, realtype &b, realtype &c, realtype &al, realtype &be, + realtype &ga, realtype &vol, int &orthcode) { + const gemmi::UnitCell &u = st.cell; + a = u.a; b = u.b; c = u.c; al = u.alpha; be = u.beta; ga = u.gamma; + vol = u.volume; orthcode = 1; + } + void GetCell(realtype &a, realtype &b, realtype &c, realtype &al, realtype &be, + realtype &ga, realtype &vol) { int oc; GetCell(a,b,c,al,be,ga,vol,oc); } + void SetCell(realtype a, realtype b, realtype c, realtype al, realtype be, + realtype ga, int /*OrthCode*/ = 1) { st.cell.set(a, b, c, al, be, ga); } + void Orth2Frac(realtype x, realtype y, realtype z, realtype &u, realtype &v, realtype &w) { + gemmi::Fractional f = st.cell.fractionalize(gemmi::Position(x, y, z)); + u = f.x; v = f.y; w = f.z; + } + void Frac2Orth(realtype u, realtype v, realtype w, realtype &x, realtype &y, realtype &z) { + gemmi::Position p = st.cell.orthogonalize(gemmi::Fractional(u, v, w)); + x = p.x; y = p.y; z = p.z; + } + pstr GetSpaceGroup() { _sg_buf = st.spacegroup_hm; return (pstr) _sg_buf.c_str(); } + pstr GetSpaceGroupFix() { return GetSpaceGroup(); } + int SetSpaceGroup(cpstr sg) { st.spacegroup_hm = sg ? sg : ""; return 0; } + int GetNumberOfSymOps() { + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(st.spacegroup_hm); + return sg ? (int) sg->operations().order() : 0; + } + pstr GetSymOp(int Nop) { + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(st.spacegroup_hm); + if (!sg) return nullptr; + int i = 0; + for (gemmi::Op op : sg->operations()) { + if (i++ == Nop) { _symop_buf = op.triplet(); return (pstr) _symop_buf.c_str(); } + } + return nullptr; + } + // ---- selection ---- struct Selection { SELECTION_TYPE type = STYPE_UNDEFINED; @@ -296,6 +843,87 @@ public: void GetSelIndex(int selHnd, PPResidue &SelRes, int &n) { Selection &s = selections[selHnd - 1]; SelRes = s.residues.data(); n = (int)s.residues.size(); } + // chain selections aren't modelled by the engine yet — return empty. TODO. + void GetSelIndex(int /*selHnd*/, PPChain &SelChain, int &n) { SelChain = nullptr; n = 0; } + // select atoms by serial-number range (iSer1..iSer2; 0,0 => all). + void SelectAtoms(int selHnd, int iSer1, int iSer2, SELECTION_KEY key) { + if (selHnd < 1 || selHnd > (int)selections.size()) return; + Selection &s = selections[selHnd - 1]; + std::vector pick; + for (Atom *a : all_atoms) { + int sn = a->g().serial; + if ((iSer1 == 0 && iSer2 == 0) || (sn >= iSer1 && sn <= iSer2)) pick.push_back(a); + } + if (key == SKEY_OR) { for (Atom *a : pick) if (!a->isInSelection(selHnd)) s.atoms.push_back(a); } + else { for (Atom *a : s.atoms) a->_setInSel(selHnd, false); s.atoms = pick; } + s.type = STYPE_ATOM; + for (Atom *a : s.atoms) a->_setInSel(selHnd, true); + } + + // full spatial+CID atom selection (mmdb_selmngr.h) — sphere around (x,y,z) with + // chain/resname/atomname/element filters ("!X" = exclusion, "*" = any). + void SelectAtoms(int selHnd, int /*iModel*/, cpstr Chains, int ResNo1, cpstr /*Ins1*/, + int ResNo2, cpstr /*Ins2*/, cpstr RNames, cpstr ANames, cpstr Elements, + cpstr /*altLocs*/, cpstr /*segIDs*/, cpstr /*charges*/, + realtype /*occ1*/, realtype /*occ2*/, realtype x, realtype y, realtype z, + realtype radius, SELECTION_KEY key) { + if (selHnd < 1 || selHnd > (int)selections.size()) return; + Selection &s = selections[selHnd - 1]; + // self-contained comma-list matcher ("*"=any, "!X"=exclude); `detail::` is + // declared after Manager, so don't depend on it in this inline body. + auto inlist = [](cpstr list, const std::string &v) -> bool { + if (!list || !*list || std::strcmp(list, "*") == 0) return true; + for (const char *p = list; *p; ) { + const char *c = std::strchr(p, ','); + std::string tok(p, c ? (size_t)(c - p) : std::strlen(p)); + size_t a = tok.find_first_not_of(' '), b = tok.find_last_not_of(' '); + tok = (a == std::string::npos) ? std::string() : tok.substr(a, b - a + 1); + if (tok == v) return true; + if (!c) break; p = c + 1; + } + return false; + }; + auto match = [&](cpstr list, const std::string &v) -> bool { + if (!list || !*list || std::strcmp(list, "*") == 0) return true; + if (list[0] == '!') return !inlist(list + 1, v); + return inlist(list, v); + }; + gemmi::Position pt(x, y, z); double r2 = radius * radius; + std::vector pick; + for (Atom *a : all_atoms) { + if (radius > 0 && a->g().pos.dist_sq(pt) > r2) continue; + Residue *r = a->res; + int sn = r->GetSeqNum(); + if (ResNo1 != ANY_RES && sn < ResNo1) continue; + if (ResNo2 != ANY_RES && sn > ResNo2) continue; + if (!match(Chains, r->chain->g().name)) continue; + if (!match(RNames, std::string(r->GetResName()))) continue; + if (!match(ANames, std::string(a->GetAtomName()))) continue; + if (!match(Elements, gemmi::Element(a->g().element).name())) continue; + pick.push_back(a); + } + if (key == SKEY_OR) { for (Atom *a : pick) if (!a->isInSelection(selHnd)) s.atoms.push_back(a); } + else { for (Atom *a : s.atoms) a->_setInSel(selHnd, false); s.atoms = pick; } + s.type = STYPE_ATOM; + for (Atom *a : s.atoms) a->_setInSel(selHnd, true); + } + + // --- misc hierarchy/bond/UDData ops used by Coot --- + void RemoveBonds() {} // gemmi has no persistent bond table + void Delete(int /*DelKey*/) {} // partial-hierarchy delete — no-op (TODO) + pstr GetInputBuffer(pstr buf, int &count) { count = 0; if (buf) buf[0] = '\0'; return buf; } + // place an atom into the flat table (mmdb Manager::PutAtom) — the shim builds + // hierarchy via Add*/gemmi, so this is a stub returning the index. TODO if a + // PutAtom-built molecule is needed. + int PutAtom(int index, PAtom /*atom*/, int /*serNum*/ = 0) { return index; } + // hierarchy-level UDData (UDR_HIERARCHY) — Manager owns its own UDStore. + UDStore _ud; + int PutUDData(int h, int v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } + int PutUDData(int h, realtype v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } + int PutUDData(int h, cpstr v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } + int GetUDData(int h, int &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } + int GetUDData(int h, realtype &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } + int GetUDData(int h, pstr &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } // primary CID-range selection (STYPE via Select; SelectAtoms forwards as STYPE_ATOM) void Select(int selHnd, SELECTION_TYPE sType, int iModel, cpstr Chains, int ResNo1, cpstr Ins1, int ResNo2, cpstr Ins2, cpstr RNames, @@ -308,13 +936,50 @@ public: } void SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, realtype y, realtype z, realtype r, SELECTION_KEY sKey = SKEY_OR); + // select-from-selection: combine selHnd2's contents into selHnd1 per sKey + void Select(int selHnd1, SELECTION_TYPE sType, int selHnd2, SELECTION_KEY sKey); + // atoms within [d1,d2] of any atom in the given set (defined in contacts.cc) + void SelectNeighbours(int selHnd, SELECTION_TYPE sType, PPAtom atoms, int nAtoms, + realtype d1, realtype d2, SELECTION_KEY sKey = SKEY_OR); + void SetFlag(int /*flags*/) {} // no-op: read/write behaviour is fixed + void SetFlag(cpstr /*flags*/) {} + int PutPDBString(cpstr /*card*/) { return Error_NoError; } // no-op + int MakeBonds(bool /*calc*/) { return 0; } // TODO: gemmi bonds + + // flat atom access (across the whole hierarchy) + std::vector all_atoms; + int GetNumberOfAtoms() { return (int)all_atoms.size(); } + int GetNumberOfAtoms(bool /*countTers*/) { return (int)all_atoms.size(); } + int GetNumberOfAtoms(cpstr CID); // count atoms matching CID (defined below) + PAtom GetAtomI(int i) { return (i >= 0 && i < (int)all_atoms.size()) ? all_atoms[i] : nullptr; } + void GetAtomTable(PPAtom &t, int &n) { t = all_atoms.data(); n = (int)all_atoms.size(); } + void GetModelTable(PPModel &t, int &n) { t = models.data(); n = (int)models.size(); } + void GetAtomStatistics(int selHnd, RAtomStat AS); // defined below + int MakeSelIndex(int selHnd) { + return (selHnd >= 1 && selHnd <= (int)selections.size()) + ? (int)selections[selHnd - 1].atoms.size() : 0; + } + void SelectAtom(int selHnd, PAtom atom, SELECTION_KEY sKey, bool makeIndex = true); + // CID-string selection, e.g. "/1/A/10-20/CA" + void Select(int selHnd, SELECTION_TYPE sType, cpstr CID, SELECTION_KEY sKey); // ---- contacts (gemmi-free uniform-grid search) ---- + // TMatrix is MMDB's optional symmetry transform applied to the 2nd set; the + // shim does no symmetry (see contacts.cc image_idx!=0 exclusion), so it's + // accepted and ignored. TODO: gemmi symmetry-aware contacts. void SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, realtype d2, int seqDist, PContact &contact, int &ncontacts, - int maxlen = 0, long group = 0); + int maxlen = 0, pmat44 TMatrix = nullptr, long group = 0); void SeekContacts(PPAtom A, int n, realtype d1, realtype d2, int seqDist, - PContact &contact, int &ncontacts, int maxlen = 0, long group = 0); + PContact &contact, int &ncontacts, int maxlen = 0, + pmat44 TMatrix = nullptr, long group = 0); + // single-atom vs selection (forwards to the array overload with a 1-elem array) + void SeekContacts(PAtom a, PPAtom A2, int n2, realtype d1, realtype d2, int seqDist, + PContact &contact, int &ncontacts, int maxlen = 0, + pmat44 TMatrix = nullptr, long group = 0) { + PAtom a1[1] = { a }; + SeekContacts(a1, 1, A2, n2, d1, d2, seqDist, contact, ncontacts, maxlen, TMatrix, group); + } int FinishStructEdit() { return 0; } // no-op: wrappers stay in sync eagerly @@ -347,10 +1012,15 @@ public: }; // ---- g() resolvers ---- -inline gemmi::Model &Model::g() const { return mgr->st.models[mi]; } -inline gemmi::Chain &Chain::g() const { return model->g().chains[ci]; } -inline gemmi::Residue &Residue::g() const { return chain->g().residues[ri]; } -inline gemmi::Atom &Atom::g() const { return res->g().atoms[ai]; } +// A wrapper with no parent is "detached" (Coot's `new mmdb::Atom` idiom: build +// standalone, set fields, then Add*() into a parent). While detached, g() +// resolves to a wrapper-owned local gemmi object; Add*() copies that local into +// the parent's gemmi vector and rebinds (sets parent + index). Index-based +// resolution makes the vector push/reallocation harmless for siblings. +inline gemmi::Model &Model::g() const { return mgr ? mgr->st.models[mi] : const_cast(this)->_local; } +inline gemmi::Chain &Chain::g() const { return model ? model->g().chains[ci] : const_cast(this)->_local; } +inline gemmi::Residue &Residue::g() const { return chain ? chain->g().residues[ri] : const_cast(this)->_local; } +inline gemmi::Atom &Atom::g() const { return res ? res->g().atoms[ai] : const_cast(this)->_local; } // ---- UDData helpers ---- inline Manager::UDReg *_ud_desc(Manager *mgr, UDR_TYPE myType, int handle, int kind, @@ -385,9 +1055,14 @@ inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, realtype &v) { if ((int)s._udr.size() <= d->slot) return UDDATA_NoData; v = s._udr[d->slot]; return UDDATA_Ok; } +inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, pstr &v) { + int e; auto *d = _ud_desc(mgr, t, h, 2, e); if (!d) return e; + if ((int)s._uds.size() <= d->slot) return UDDATA_NoData; + v = (pstr) s._uds[d->slot].c_str(); return UDDATA_Ok; // borrowed +} // ---- Atom out-of-line ---- -inline pstr Atom::GetAtomName() { +inline pstr Atom::GetAtomName() const { std::snprintf(_name_buf, sizeof(_name_buf), "%s", g().name.c_str()); return _name_buf; } @@ -397,8 +1072,10 @@ inline pstr Atom::GetElementName() { return _elem_buf; } inline void Atom::SetElementName(const Element elName) { g().element = gemmi::Element(elName); } -inline cpstr Atom::GetChainID() { return res->GetChainID(); } +inline pstr Atom::GetChainID() { return res->GetChainID(); } inline int Atom::GetSeqNum() { return res->GetSeqNum(); } +inline Chain *Atom::GetChain() { return res ? res->GetChain() : nullptr; } +inline Model *Atom::GetModel() { return res ? res->chain->model : nullptr; } inline pstr Atom::GetInsCode() { return res->GetInsCode(); } inline pstr Atom::GetResName() { return res->GetResName(); } inline int Atom::GetModelNum() { return res->GetModelNum(); } @@ -413,12 +1090,12 @@ inline pstr Residue::GetResName() { std::snprintf(_resname_buf, sizeof(_resname_buf), "%s", g().name.c_str()); return _resname_buf; } -inline int Residue::GetSeqNum() { return g().seqid.num.value; } +inline int &Residue::GetSeqNum() { return g().seqid.num.value; } inline pstr Residue::GetInsCode() { _inscode_buf[0] = g().seqid.icode == ' ' ? '\0' : g().seqid.icode; _inscode_buf[1] = '\0'; return _inscode_buf; } -inline cpstr Residue::GetChainID() { return chain->GetChainID(); } +inline pstr Residue::GetChainID() { return chain->GetChainID(); } inline int Residue::GetModelNum() { return chain->model->GetSerNum(); } inline PAtom Residue::GetAtom(const AtomName aname, const Element elname, const AltLoc aloc) { for (Atom *a : atoms) { @@ -444,7 +1121,20 @@ inline void Residue::DeleteAtom(int pos) { } // ---- Chain out-of-line ---- -inline cpstr Chain::GetChainID() { +inline bool Chain::isAminoacidChain() { + for (Residue *r : residues) if (r->isAminoacid()) return true; + return false; +} +inline bool Chain::isNucleotideChain() { + for (Residue *r : residues) if (r->isNucleotide()) return true; + return false; +} +inline bool Chain::isSolventChain() { + if (residues.empty()) return false; + for (Residue *r : residues) if (!r->isSolvent()) return false; + return true; +} +inline pstr Chain::GetChainID() { std::snprintf(_chainid_buf, sizeof(_chainid_buf), "%s", g().name.c_str()); return _chainid_buf; } @@ -477,6 +1167,7 @@ inline PChain Model::GetChain(const ChainID chID) { // ---- Manager out-of-line ---- inline void Manager::build_from_gemmi() { models.clear(); + all_atoms.clear(); for (int mi = 0; mi < (int)st.models.size(); ++mi) { Model *mw = newModel(); mw->mgr = this; mw->mi = mi; auto &gm = st.models[mi]; @@ -488,8 +1179,13 @@ inline void Manager::build_from_gemmi() { auto &gr = gc.residues[ri]; for (int ai = 0; ai < (int)gr.atoms.size(); ++ai) { Atom *aw = newAtom(); aw->mgr = this; aw->res = rw; aw->ai = ai; - rw->atoms.push_back(aw); + aw->WhatIsSet = ASET_Coordinates | ASET_Occupancy | ASET_tempFactor; + const gemmi::SMat33 &an = gr.atoms[ai].aniso; + if (an.u11 != 0.f || an.u22 != 0.f || an.u33 != 0.f) aw->WhatIsSet |= ASET_Anis_tFac; + rw->atoms.push_back(aw); all_atoms.push_back(aw); mw->all_atoms.push_back(aw); } + rw->_sync_atom(); + rw->_load_id(); cw->residues.push_back(rw); } mw->chains.push_back(cw); @@ -570,6 +1266,104 @@ inline void Manager::Select(int selHnd, SELECTION_TYPE sType, int iModel, for (Residue *r : sel.residues) r->_setInSel(selHnd, true); } +// select-from-selection: combine selHnd2's contents into selHnd1 +inline void Manager::Select(int selHnd1, SELECTION_TYPE sType, int selHnd2, + SELECTION_KEY sKey) { + Selection &s1 = selections[selHnd1 - 1]; + Selection &s2 = selections[selHnd2 - 1]; + if (s1.type == STYPE_UNDEFINED) s1.type = sType; + std::vector oldA = s1.atoms; std::vector oldR = s1.residues; + auto combine = [&](auto &cur, auto &m) { + using Vec = typename std::decay::type; + std::set curset(cur.begin(), cur.end()); + std::set mset(m.begin(), m.end()); + if (sKey == SKEY_NEW) cur = m; + else if (sKey == SKEY_OR) { for (auto *x : m) if (!curset.count(x)) cur.push_back(x); } + else if (sKey == SKEY_AND) { Vec o; for (auto *x : cur) if (mset.count(x)) o.push_back(x); cur = o; } + else if (sKey == SKEY_XOR) { Vec o; for (auto *x : cur) if (!mset.count(x)) o.push_back(x); + for (auto *x : m) if (!curset.count(x)) o.push_back(x); cur = o; } + else if (sKey == SKEY_CLR) { Vec o; for (auto *x : cur) if (!mset.count(x)) o.push_back(x); cur = o; } + }; + if (sType == STYPE_ATOM) combine(s1.atoms, s2.atoms); + else if (sType == STYPE_RESIDUE) combine(s1.residues, s2.residues); + for (Atom *a : oldA) a->_setInSel(selHnd1, false); + for (Atom *a : s1.atoms) a->_setInSel(selHnd1, true); + for (Residue *r : oldR) r->_setInSel(selHnd1, false); + for (Residue *r : s1.residues) r->_setInSel(selHnd1, true); +} + +inline void Manager::SelectAtom(int selHnd, PAtom atom, SELECTION_KEY sKey, bool) { + Selection &sel = selections[selHnd - 1]; + if (sel.type == STYPE_UNDEFINED) sel.type = STYPE_ATOM; + if (sKey == SKEY_NEW) { + for (Atom *a : sel.atoms) a->_setInSel(selHnd, false); + sel.atoms.clear(); + } + if (atom && !atom->isInSelection(selHnd)) { + sel.atoms.push_back(atom); atom->_setInSel(selHnd, true); + } +} + +// Pragmatic CID parser: "/model/chain/seqNum1(-seqNum2)/atom" (best-effort; +// strips (resname)/[element]/:altloc suffixes). TODO: full MMDB CID grammar. +inline void Manager::Select(int selHnd, SELECTION_TYPE sType, cpstr CID, + SELECTION_KEY sKey) { + std::string s = CID ? CID : ""; + std::vector t; + size_t p = (!s.empty() && s[0] == '/') ? 1 : 0; + while (p <= s.size()) { + size_t q = s.find('/', p); + t.push_back(s.substr(p, q == std::string::npos ? std::string::npos : q - p)); + if (q == std::string::npos) break; + p = q + 1; + } + auto tok = [&](size_t i) { return i < t.size() ? t[i] : std::string(); }; + auto strip = [](std::string v, const char *seps) { + size_t c = v.find_first_of(seps); return c == std::string::npos ? v : v.substr(0, c); + }; + int iModel = 0; std::string m = tok(0); + if (!m.empty() && m != "*" && m != "0") iModel = atoi(m.c_str()); + std::string chains = tok(1).empty() ? "*" : tok(1); + int r1 = ANY_RES, r2 = ANY_RES; + std::string rr = strip(tok(2), "("); // drop (resname) + if (!rr.empty() && rr != "*") { + size_t dash = rr.find('-', rr[0] == '-' ? 1 : 0); + if (dash == std::string::npos) { r1 = r2 = atoi(rr.c_str()); } + else { r1 = atoi(rr.substr(0, dash).c_str()); r2 = atoi(rr.substr(dash + 1).c_str()); } + } + std::string anames = strip(strip(tok(3), "["), ":"); // drop [element]/:altloc + if (anames.empty()) anames = "*"; + Select(selHnd, sType, iModel, chains.c_str(), r1, "*", r2, "*", "*", + anames.c_str(), "*", "*", sKey); +} + +inline int Manager::GetNumberOfAtoms(cpstr CID) { + int h = NewSelection(); + Select(h, STYPE_ATOM, CID, SKEY_NEW); + int n = (int)selections[h - 1].atoms.size(); + DeleteSelection(h); + return n; +} + +inline void Manager::GetAtomStatistics(int selHnd, RAtomStat AS) { + AS = AtomStat(); + std::vector &atoms = selections[selHnd - 1].atoms; + AS.nAtoms = (int)atoms.size(); + if (atoms.empty()) return; + double sx = 0, sy = 0, sz = 0; + AS.xmin = AS.xmax = atoms[0]->x(); + AS.ymin = AS.ymax = atoms[0]->y(); + AS.zmin = AS.zmax = atoms[0]->z(); + for (Atom *a : atoms) { + double X = a->x(), Y = a->y(), Z = a->z(); + sx += X; sy += Y; sz += Z; + AS.xmin = X < AS.xmin ? X : AS.xmin; AS.xmax = X > AS.xmax ? X : AS.xmax; + AS.ymin = Y < AS.ymin ? Y : AS.ymin; AS.ymax = Y > AS.ymax ? Y : AS.ymax; + AS.zmin = Z < AS.zmin ? Z : AS.zmin; AS.zmax = Z > AS.zmax ? Z : AS.zmax; + } + AS.xm = sx / atoms.size(); AS.ym = sy / atoms.size(); AS.zm = sz / atoms.size(); +} + inline void Manager::SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, realtype y, realtype z, realtype r, SELECTION_KEY sKey) { Selection &sel = selections[selHnd - 1]; @@ -601,4 +1395,91 @@ inline void Manager::SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, // SeekContacts (both overloads) is defined in mmdb-shim/src/contacts.cc using // gemmi::NeighborSearch — keeps the heavy neighbor.hpp out of Coot's many TUs. +// ---- detached-construction constructors + subtree ops (need complete types) ---- +inline Atom::Atom(Residue *r) { if (r) r->AddAtom(this); } +inline Residue::Residue(Chain *c) { if (c) c->AddResidue(this); } +inline Chain::Chain(Model *m, const ChainID id) { if (m) m->AddChain(this); SetChainID(id); } + +inline bool Residue::isCTerminus() { + return chain && ri == (int)chain->residues.size() - 1; +} + +inline void Chain::Copy(PChain src) { + Manager *pool = mgr ? mgr : src->mgr; + g() = src->g(); // deep gemmi copy (residues + atoms) + residues.clear(); + if (!pool) return; + gemmi::Chain &gc = g(); + for (int r = 0; r < (int)gc.residues.size(); ++r) { + Residue *rw = pool->newRes(); rw->mgr = mgr; rw->chain = this; rw->ri = r; + for (int a = 0; a < (int)gc.residues[r].atoms.size(); ++a) { + Atom *aw = pool->newAtom(); aw->mgr = mgr; aw->res = rw; aw->ai = a; + rw->atoms.push_back(aw); + } + rw->_sync_atom(); rw->_load_id(); + residues.push_back(rw); + } +} + +inline void Model::Copy(PModel src) { + Manager *pool = mgr ? mgr : src->mgr; + g() = src->g(); + chains.clear(); + if (!pool) return; + gemmi::Model &gm = g(); + for (int c = 0; c < (int)gm.chains.size(); ++c) { + Chain *cw = pool->newChain(); cw->mgr = mgr; cw->model = this; cw->ci = c; + for (int r = 0; r < (int)gm.chains[c].residues.size(); ++r) { + Residue *rw = pool->newRes(); rw->mgr = mgr; rw->chain = cw; rw->ri = r; + for (int a = 0; a < (int)gm.chains[c].residues[r].atoms.size(); ++a) { + Atom *aw = pool->newAtom(); aw->mgr = mgr; aw->res = rw; aw->ai = a; + rw->atoms.push_back(aw); + } + rw->_sync_atom(); rw->_load_id(); + cw->residues.push_back(rw); + } + chains.push_back(cw); + } +} + +inline PChain Model::CreateChain(const ChainID id) { + Chain *c = mgr ? mgr->newChain() : new Chain(); + c->mgr = mgr; c->model = this; c->ci = (int)chains.size(); + g().chains.emplace_back(id ? id : ""); + chains.push_back(c); + return c; +} + +inline pstr Atom::GetAtomID(pstr S) { + if (S) std::snprintf(S, 100, "/%d/%s/%d(%s)/%s", GetModelNum(), GetChainID(), + res ? res->GetSeqNum() : 0, GetResName(), GetAtomName()); + return S; +} + +// one-letter residue code (mmdb_tables.h) via gemmi's tabulated residues +inline void Get1LetterCode(cpstr res3, pstr res1) { + if (!res1) return; + char c = gemmi::find_tabulated_residue(res3 ? res3 : "").one_letter_code; + res1[0] = c ? (char) std::toupper((unsigned char) c) : 'X'; res1[1] = '\0'; +} +inline void Get1LetterCode(cpstr res3, char &res1) { char b[2]; Get1LetterCode(res3, b); res1 = b[0]; } + +// sort a contact array by distance (mmdb_coormngr.h SortContacts) — sortkey ignored +inline void SortContacts(PContact contacts, int nContacts, int /*sortkey*/) { + if (contacts && nContacts > 1) + std::sort(contacts, contacts + nContacts, + [](const Contact &a, const Contact &b) { return a.dist < b.dist; }); +} + +// centroid of an atom array (mmdb_coormngr.h GetMassCenter) +inline void GetMassCenter(PPAtom A, int nA, realtype &xc, realtype &yc, realtype &zc) { + double sx = 0, sy = 0, sz = 0; int n = 0; + for (int i = 0; i < nA; ++i) if (A[i]) { sx += A[i]->x(); sy += A[i]->y(); sz += A[i]->z(); ++n; } + if (n) { xc = sx / n; yc = sy / n; zc = sz / n; } else { xc = yc = zc = 0; } +} + } // namespace mmdb + +// mmdb::mmcif::* (thin veneer over gemmi::cif) — re-opens mmdb{mmcif{...}}. +// pstr/cpstr/realtype are already in scope from the headers above. +#include "_mmcif_impl.hh" diff --git a/mmdb-shim/shim-cxx b/mmdb-shim/shim-cxx new file mode 100755 index 0000000000..ef43dfd6ba --- /dev/null +++ b/mmdb-shim/shim-cxx @@ -0,0 +1,9 @@ +#!/bin/sh +# Compiler wrapper that forces the mmdb->gemmi shim's headers to win over real +# mmdb2. Autotools puts pkg-config's `-I` in AM_CPPFLAGS, which precedes +# CPPFLAGS on the compile line — so a shim -I in CPPFLAGS can never win. But +# $(CXX) is emitted before everything, so a -I here is searched FIRST. +# Used via: export CXX="/mmdb-shim/shim-cxx" +# Override the underlying compiler with REAL_CXX if needed (default: c++). +d="$(cd "$(dirname "$0")" && pwd)" +exec "${REAL_CXX:-/usr/bin/c++}" -I"$d/include" -DCOOT_USE_MMDB_SHIM "$@" diff --git a/mmdb-shim/src/contacts.cc b/mmdb-shim/src/contacts.cc index 7572ffaf0d..ef6a4780b8 100644 --- a/mmdb-shim/src/contacts.cc +++ b/mmdb-shim/src/contacts.cc @@ -27,11 +27,50 @@ inline Atom *mark_to_atom(Model *mw, const gemmi::NeighborSearch::Mark *m) { return mw->chains[m->chain_idx]->residues[m->residue_idx]->atoms[m->atom_idx]; } +template +void skcombine(Vec &cur, Vec &m, SELECTION_KEY k) { + std::set cs(cur.begin(), cur.end()), ms(m.begin(), m.end()); + if (k == SKEY_NEW) cur = m; + else if (k == SKEY_OR) { for (auto *x : m) if (!cs.count(x)) cur.push_back(x); } + else if (k == SKEY_AND) { Vec o; for (auto *x : cur) if (ms.count(x)) o.push_back(x); cur = o; } + else if (k == SKEY_XOR) { Vec o; for (auto *x : cur) if (!ms.count(x)) o.push_back(x); + for (auto *x : m) if (!cs.count(x)) o.push_back(x); cur = o; } + else if (k == SKEY_CLR) { Vec o; for (auto *x : cur) if (!ms.count(x)) o.push_back(x); cur = o; } +} + } // namespace +// atoms within [d1,d2] of any atom in the given set. +void Manager::SelectNeighbours(int selHnd, SELECTION_TYPE sType, PPAtom atoms, + int nAtoms, realtype d1, realtype d2, SELECTION_KEY sKey) { + std::vector mAtoms; std::vector mResidues; + if (nAtoms > 0) { + Model *mw = atoms[0]->res->chain->model; + gemmi::NeighborSearch ns(mw->g(), st.cell, d2); + ns.populate(true); + std::set seenA; std::set seenR; + for (int i = 0; i < nAtoms; ++i) + for (auto *m : ns.find_atoms(atoms[i]->g().pos, '\0', d1, d2)) { + if (m->image_idx != 0) continue; + Atom *b = mark_to_atom(mw, m); + if (sType == STYPE_ATOM) { if (seenA.insert(b).second) mAtoms.push_back(b); } + else if (sType == STYPE_RESIDUE) { if (seenR.insert(b->res).second) mResidues.push_back(b->res); } + } + } + Selection &sel = selections[selHnd - 1]; + if (sel.type == STYPE_UNDEFINED) sel.type = sType; + std::vector oldA = sel.atoms; std::vector oldR = sel.residues; + if (sType == STYPE_ATOM) skcombine(sel.atoms, mAtoms, sKey); + else if (sType == STYPE_RESIDUE) skcombine(sel.residues, mResidues, sKey); + for (Atom *a : oldA) a->_setInSel(selHnd, false); + for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); + for (Residue *r : oldR) r->_setInSel(selHnd, false); + for (Residue *r : sel.residues) r->_setInSel(selHnd, true); +} + void Manager::SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, realtype d2, int seqDist, PContact &contact, int &ncontacts, int /*maxlen*/, - long group) { + pmat44 /*TMatrix*/, long group) { std::vector found; if (n1 > 0 && n2 > 0) { Model *mw = A1[0]->res->chain->model; // NeighborSearch is per-model @@ -58,7 +97,8 @@ void Manager::SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, } void Manager::SeekContacts(PPAtom A, int n, realtype d1, realtype d2, - int seqDist, PContact &contact, int &ncontacts, int /*maxlen*/, long group) { + int seqDist, PContact &contact, int &ncontacts, int /*maxlen*/, + pmat44 /*TMatrix*/, long group) { std::vector found; if (n > 0) { Model *mw = A[0]->res->chain->model; diff --git a/pli/dots-representation-info.cc b/pli/dots-representation-info.cc index 38fc63f562..6a04eece0c 100644 --- a/pli/dots-representation-info.cc +++ b/pli/dots-representation-info.cc @@ -185,7 +185,7 @@ pli::dots_representation_info_t::pure_points(mmdb::Manager *mol) { for (int iat=0; iatGetAtom(iat); - local_points.push_back(clipper::Coord_orth(at->x, at->y, at->z)); + local_points.push_back(clipper::Coord_orth(at->x(), at->y(), at->z())); } } } @@ -218,7 +218,7 @@ pli::dots_representation_info_t::solvent_exposure(int SelHnd_in, mmdb::Manager * std::vector radius(n_atoms); for (int iat=0; iatelement); + std::string ele(atoms[iat]->GetElementName()); radius[iat] = get_radius(ele); } @@ -230,9 +230,9 @@ pli::dots_representation_info_t::solvent_exposure(int SelHnd_in, mmdb::Manager * for (int iatom=0; iatomisTer()) { - clipper::Coord_orth centre(atoms[iatom]->x, - atoms[iatom]->y, - atoms[iatom]->z); + clipper::Coord_orth centre(atoms[iatom]->x(), + atoms[iatom]->y(), + atoms[iatom]->z()); bool even = 1; int n_points = 0; int n_sa = 0; @@ -257,11 +257,11 @@ pli::dots_representation_info_t::solvent_exposure(int SelHnd_in, mmdb::Manager * std::string other_res_name = other_at->GetResName(); if (other_res_name != "HOH") { if (atoms[iatom] != other_at) { - std::string other_ele = other_at->element; + std::string other_ele = other_at->GetElementName(); if (other_ele != " H") { double other_atom_r = fudge * (get_radius(other_ele) + water_radius); double other_atom_r_sq = other_atom_r * other_atom_r; - clipper::Coord_orth pt_other(other_at->x, other_at->y, other_at->z); + clipper::Coord_orth pt_other(other_at->x(), other_at->y(), other_at->z()); if ((pt-pt_other).lengthsq() < other_atom_r_sq) { is_solvent_accessible = 0; break; @@ -279,7 +279,7 @@ pli::dots_representation_info_t::solvent_exposure(int SelHnd_in, mmdb::Manager * double exposure_frac = double(n_sa)/double(n_points); if (0) - std::cout << "Atom " << atoms[iatom]->name << " has exposure " << n_sa << "/" << n_points + std::cout << "Atom " << atoms[iatom]->GetAtomName() << " has exposure " << n_sa << "/" << n_points << " = " << exposure_frac << std::endl; std::pair p(atoms[iatom], exposure_frac); v.push_back(p); @@ -406,7 +406,7 @@ pli::dots_representation_info_t::add_dots(int SelHnd, mmdb::Manager *mol, std::vector radius_exclude; std::vector colour(n_atoms); for (int iat=0; iatelement); + std::string ele(atoms[iat]->GetElementName()); radius[iat] = get_radius(ele); if (use_single_colour) colour[iat] = single_colour; @@ -423,7 +423,7 @@ pli::dots_representation_info_t::add_dots(int SelHnd, mmdb::Manager *mol, mol_exclude->GetSelIndex(SelHnd_exclude, atoms_exclude, n_atoms_exclude); radius_exclude.resize(n_atoms_exclude); for (int iat=0; iatelement); + std::string ele(atoms_exclude[iat]->GetElementName()); radius_exclude[iat] = get_radius(ele); } } @@ -432,9 +432,9 @@ pli::dots_representation_info_t::add_dots(int SelHnd, mmdb::Manager *mol, std::vector local_points; coot::colour_t col = colour[iatom]; if (! atoms[iatom]->isTer()) { - clipper::Coord_orth centre(atoms[iatom]->x, - atoms[iatom]->y, - atoms[iatom]->z); + clipper::Coord_orth centre(atoms[iatom]->x(), + atoms[iatom]->y(), + atoms[iatom]->z()); bool even = true; for (double theta=0; thetaisTer()) { double radius_j = radius[jatom]; double radius_j_squared = radius_j * radius_j; - clipper::Coord_orth pt_j(atoms[jatom]->x, atoms[jatom]->y, atoms[jatom]->z); + clipper::Coord_orth pt_j(atoms[jatom]->x(), atoms[jatom]->y(), atoms[jatom]->z()); if ((pt-pt_j).lengthsq() < radius_j_squared) { draw_it = false; break; @@ -482,9 +482,9 @@ pli::dots_representation_info_t::add_dots(int SelHnd, mmdb::Manager *mol, double dist_j_squared = dist_j * dist_j; for (int jatom=0; jatomisTer()) { - clipper::Coord_orth pt_j(atoms_exclude[jatom]->x, - atoms_exclude[jatom]->y, - atoms_exclude[jatom]->z); + clipper::Coord_orth pt_j(atoms_exclude[jatom]->x(), + atoms_exclude[jatom]->y(), + atoms_exclude[jatom]->z()); if ((pt-pt_j).lengthsq() < dist_j_squared) { draw_it = true; break; diff --git a/pli/flev-annotations.hh b/pli/flev-annotations.hh index 435754a806..07a8c338ee 100644 --- a/pli/flev-annotations.hh +++ b/pli/flev-annotations.hh @@ -204,7 +204,7 @@ namespace pli { if (! ligand_atom_is_donor_flag) std::swap(ligand_atom, residue_atom); - if (is_a_metal(residue_atom->residue)) { + if (is_a_metal(residue_atom->GetResidue())) { r_bond_type = METAL_CONTACT_BOND; } else { diff --git a/pli/flev-attached-hydrogens.cc b/pli/flev-attached-hydrogens.cc index b95dbe3efd..76bbc654a7 100644 --- a/pli/flev-attached-hydrogens.cc +++ b/pli/flev-attached-hydrogens.cc @@ -161,7 +161,7 @@ pli::flev_attached_hydrogens_t::cannonballs(mmdb::Residue *ligand_residue_3d, if (n_contacts > 0) { for (int i=0; i< n_contacts; i++) { mmdb::Atom *at = non_hydrogen_selection[pscontact[i].id2]; - std::string atom_name_bonded_to_H(at->name); + std::string atom_name_bonded_to_H(at->GetAtomName()); bool found_torsion_for_this_H = 0; @@ -227,7 +227,7 @@ pli::flev_attached_hydrogens_t::distances_to_protein_using_correct_Hs(mmdb::Resi mmdb::Atom *lig_at = NULL; mmdb::Atom *H_at = NULL; for (int iat=0; iatname); + std::string atom_name(residue_atoms[iat]->GetAtomName()); if (atom_name == atoms_with_riding_hydrogens[irh].first) lig_at = residue_atoms[iat]; if (atom_name == atoms_with_riding_hydrogens[irh].second) @@ -237,8 +237,8 @@ pli::flev_attached_hydrogens_t::distances_to_protein_using_correct_Hs(mmdb::Resi } if (lig_at && H_at) { - clipper::Coord_orth H_pt(H_at->x, H_at->y, H_at->z); - clipper::Coord_orth lig_atom_pt(lig_at->x, lig_at->y, lig_at->z); + clipper::Coord_orth H_pt(H_at->x(), H_at->y(), H_at->z()); + clipper::Coord_orth lig_atom_pt(lig_at->x(), lig_at->y(), lig_at->z()); std::vector atoms = close_atoms(H_pt, env_residues); coot::bash_distance_t bash = find_bash_distance(lig_atom_pt, H_pt, atoms); @@ -258,7 +258,7 @@ pli::flev_attached_hydrogens_t::distances_to_protein_using_correct_Hs(mmdb::Resi mmdb::Atom *lig_at = NULL; mmdb::Atom *H_at = NULL; for (int iat=0; iatname); + std::string atom_name(residue_atoms[iat]->GetAtomName()); if (atom_name == atoms_with_rotating_hydrogens[irh].first) lig_at = residue_atoms[iat]; if (atom_name == atoms_with_rotating_hydrogens[irh].second) @@ -267,8 +267,8 @@ pli::flev_attached_hydrogens_t::distances_to_protein_using_correct_Hs(mmdb::Resi break; } if (lig_at && H_at) { - clipper::Coord_orth H_pt(H_at->x, H_at->y, H_at->z); - clipper::Coord_orth lig_atom_pt(lig_at->x, lig_at->y, lig_at->z); + clipper::Coord_orth H_pt(H_at->x(), H_at->y(), H_at->z()); + clipper::Coord_orth lig_atom_pt(lig_at->x(), lig_at->y(), lig_at->z()); std::vector atoms = close_atoms(H_pt, env_residues); @@ -424,7 +424,7 @@ pli::flev_attached_hydrogens_t::find_bash_distance(const clipper::Coord_orth &li // std::vector radius(close_residue_atoms.size()); for (unsigned int iat=0; iatelement); + std::string ele(close_residue_atoms[iat]->GetElementName()); radius[iat] = get_radius(ele); } @@ -433,9 +433,9 @@ pli::flev_attached_hydrogens_t::find_bash_distance(const clipper::Coord_orth &li std::vector atom_positions(close_residue_atoms.size()); // likewise set the atom positions so that we don't have to keep doing it. for (unsigned int i=0; ix, - close_residue_atoms[i]->y, - close_residue_atoms[i]->z); + atom_positions[i] = clipper::Coord_orth(close_residue_atoms[i]->x(), + close_residue_atoms[i]->y(), + close_residue_atoms[i]->z()); for (double slide=0; slide<=max_dist; slide+=0.04) { clipper::Coord_orth test_pt = ligand_atom_pos + slide * h_vector; @@ -486,7 +486,7 @@ pli::flev_attached_hydrogens_t::close_atoms(const clipper::Coord_orth &pt, int n_residue_atoms; residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatx, residue_atoms[iat]->y, residue_atoms[iat]->z); + clipper::Coord_orth atom_pos(residue_atoms[iat]->x(), residue_atoms[iat]->y(), residue_atoms[iat]->z()); double d_squared = (pt - atom_pos).lengthsq(); if (d_squared < dist_crit_squared) { std::string rn(residue_atoms[iat]->GetResName()); @@ -524,7 +524,7 @@ pli::flev_attached_hydrogens_t::get_atom_pos_bonded_to_atom(mmdb::Atom *lig_at, mmdb::Residue *ligand_residue, const coot::protein_geometry &geom) const { int imol = 0; // FIXME needs checking - std::string res_name(lig_at->residue->GetResName()); + std::string res_name(lig_at->GetResidue()->GetResName()); std::pair p = geom.get_monomer_restraints_at_least_minimal(res_name, imol); @@ -536,8 +536,8 @@ pli::flev_attached_hydrogens_t::get_atom_pos_bonded_to_atom(mmdb::Atom *lig_at, } else { mmdb::Atom *bonded_atom = NULL; std::string bonded_atom_name; - std::string lig_at_name = lig_at->name; - std::string H_at_name = H_at->name; + std::string lig_at_name = lig_at->GetAtomName(); + std::string H_at_name = H_at->GetAtomName(); for (unsigned int ibond=0; ibondGetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname; + std::string atom_name = residue_atoms[iat]->GetAtomName(); if (atom_name == bonded_atom_name) { bonded_atom = residue_atoms[iat]; break; @@ -575,7 +575,7 @@ pli::flev_attached_hydrogens_t::get_atom_pos_bonded_to_atom(mmdb::Atom *lig_at, throw std::runtime_error(m); } else { // good - return clipper::Coord_orth(bonded_atom->x, bonded_atom->y, bonded_atom->z); + return clipper::Coord_orth(bonded_atom->x(), bonded_atom->y(), bonded_atom->z()); } } @@ -602,7 +602,7 @@ pli::flev_attached_hydrogens_t::named_hydrogens_to_reference_ligand(mmdb::Residu int n_residue_atoms; ligand_residue_3d->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatname); + std::string atom_name(residue_atoms[iat]->GetAtomName()); if (atom_name == named_torsions[i].base_atom_name) { atom_base = residue_atoms[iat]; } @@ -615,9 +615,9 @@ pli::flev_attached_hydrogens_t::named_hydrogens_to_reference_ligand(mmdb::Residu } if (atom_base && atom_2 && atom_bonded_to_H) { - clipper::Coord_orth pos_atom_base(atom_base->x, atom_base->y, atom_base->z); - clipper::Coord_orth pos_atom_2(atom_2->x, atom_2->y, atom_2->z); - clipper::Coord_orth pos_atom_bonded_to_H(atom_bonded_to_H->x, atom_bonded_to_H->y, atom_bonded_to_H->z); + clipper::Coord_orth pos_atom_base(atom_base->x(), atom_base->y(), atom_base->z()); + clipper::Coord_orth pos_atom_2(atom_2->x(), atom_2->y(), atom_2->z()); + clipper::Coord_orth pos_atom_bonded_to_H(atom_bonded_to_H->x(), atom_bonded_to_H->y(), atom_bonded_to_H->z()); clipper::Coord_orth new_pt(pos_atom_base, pos_atom_2, pos_atom_bonded_to_H, 1.0, // unit vector @@ -665,7 +665,7 @@ pli::flev_attached_hydrogens_t::hydrogen_pos(const pli::named_torsion_t &named_t int n_residue_atoms; residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iname); + std::string atom_name(residue_atoms[i]->GetAtomName()); if (atom_name == named_tor.base_atom_name) at_1 = residue_atoms[i]; if (atom_name == named_tor.atom_name_2) @@ -677,9 +677,9 @@ pli::flev_attached_hydrogens_t::hydrogen_pos(const pli::named_torsion_t &named_t if (! (at_1 && at_2 && at_3)) { throw(std::runtime_error("missing atoms in residue")); } else { - clipper::Coord_orth pt_1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth pt_2(at_2->x, at_2->y, at_2->z); - clipper::Coord_orth pt_3(at_3->x, at_3->y, at_3->z); + clipper::Coord_orth pt_1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth pt_2(at_2->x(), at_2->y(), at_2->z()); + clipper::Coord_orth pt_3(at_3->x(), at_3->y(), at_3->z()); clipper::Coord_orth p4_h(pt_1, pt_2, pt_3, named_tor.dist, clipper::Util::d2rad(named_tor.angle), @@ -707,9 +707,9 @@ pli::flev_attached_hydrogens_t::add_named_torsion(mmdb::Atom *h_at, mmdb::Atom * int hydrogen_type) { bool found_torsion_for_this_H = 0; - std::string atom_name_bonded_to_H(at->name); - clipper::Coord_orth p_h(h_at->x, h_at->y, h_at->z); - clipper::Coord_orth p_1(at->x, at->y, at->z); + std::string atom_name_bonded_to_H(at->GetAtomName()); + clipper::Coord_orth p_h(h_at->x(), h_at->y(), h_at->z()); + clipper::Coord_orth p_1(at->x(), at->y(), at->z()); // now we work back through the restraints, finding // an atom that bonds to at/atom_name_bonded_to_H, @@ -761,7 +761,7 @@ pli::flev_attached_hydrogens_t::add_named_torsion(mmdb::Atom *h_at, mmdb::Atom * int n_atoms = residue_p->GetNumberOfAtoms(); for (int iat=0; iatGetAtom(iat); - std::string res_atom_name(residue_at->name); + std::string res_atom_name(residue_at->GetAtomName()); if (res_atom_name == At_name_2) At_2 = residue_at; if (res_atom_name == base_atom_name) @@ -780,8 +780,8 @@ pli::flev_attached_hydrogens_t::add_named_torsion(mmdb::Atom *h_at, mmdb::Atom * << At_name_2 << std::endl; } else { try { - clipper::Coord_orth p_2(At_2->x, At_2->y, At_2->z); - clipper::Coord_orth p_base(base_atom->x, base_atom->y, base_atom->z); + clipper::Coord_orth p_2(At_2->x(), At_2->y(), At_2->z()); + clipper::Coord_orth p_base(base_atom->x(), base_atom->y(), base_atom->z()); double tors_r = clipper::Coord_orth::torsion(p_base, p_2, p_1, p_h); double tors = clipper::Util::rad2d(tors_r); diff --git a/pli/flev.cc b/pli/flev.cc index 805b13e990..00ffedd4f7 100644 --- a/pli/flev.cc +++ b/pli/flev.cc @@ -49,17 +49,17 @@ pli::make_flat_ligand_name_map(mmdb::Residue *flat_res) { flat_res->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatelement; - clipper::Coord_orth pt_i(at_i->x, at_i->y, at_i->z); + std::string ele_i = at_i->GetElementName(); + clipper::Coord_orth pt_i(at_i->x(), at_i->y(), at_i->z()); if (ele_i == " H") { for (int jat=0; jatelement; + std::string ele_j = at_j->GetElementName(); if (ele_j != " H") { - clipper::Coord_orth pt_j(at_j->x, at_j->y, at_j->z); + clipper::Coord_orth pt_j(at_j->x(), at_j->y(), at_j->z()); if ((pt_i - pt_j).lengthsq() < b2Hd2) { - map[at_j->name] = at_i->name; + map[at_j->GetAtomName()] = at_i->GetAtomName(); break; } } diff --git a/pli/pi-stacking.cc b/pli/pi-stacking.cc index 695f939d4c..483557b19b 100644 --- a/pli/pi-stacking.cc +++ b/pli/pi-stacking.cc @@ -293,11 +293,11 @@ pli::pi_stacking_container_t::get_ligand_cations(mmdb::Residue *res_ref, mmdb::PPAtom residue_atoms = NULL; res_ref->GetAtomTable(residue_atoms, n_residue_atoms); for (int iat=0; iatelement); + std::string ele(residue_atoms[iat]->GetElementName()); if (ele == " N") { // how many bonds does this N have? int n_bonds = 0; - std::string atom_name(residue_atoms[iat]->name); + std::string atom_name(residue_atoms[iat]->GetAtomName()); for (unsigned int ibond=0; ibond 3) { // i.e. 4 - clipper::Coord_orth pt(residue_atoms[iat]->x, - residue_atoms[iat]->y, - residue_atoms[iat]->z); + clipper::Coord_orth pt(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); std::pair p(atom_name, pt); v.push_back(p); } @@ -488,11 +488,11 @@ pli::pi_stacking_container_t::get_ring_pi_centre_points(const std::vector aromatic_plane_points; for (unsigned int iring_at=0; iring_atname); + std::string atom_name(residue_atoms[iat]->GetAtomName()); if (atom_name == ring_atom_names[iring_at]) { - clipper::Coord_orth at_pt(residue_atoms[iat]->x, - residue_atoms[iat]->y, - residue_atoms[iat]->z); + clipper::Coord_orth at_pt(residue_atoms[iat]->x(), + residue_atoms[iat]->y(), + residue_atoms[iat]->z()); aromatic_plane_points.push_back(at_pt); break; } @@ -731,11 +731,11 @@ pli::pi_stacking_container_t::get_cation_atom_positions(mmdb::Residue *res) cons int n_residue_atoms; res->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iname); + std::string atom_name(residue_atoms[i]->GetAtomName()); if (atom_name == " NZ ") { - clipper::Coord_orth pt(residue_atoms[i]->x, - residue_atoms[i]->y, - residue_atoms[i]->z); + clipper::Coord_orth pt(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); v.push_back(pt); } } @@ -746,12 +746,12 @@ pli::pi_stacking_container_t::get_cation_atom_positions(mmdb::Residue *res) cons int n_residue_atoms; res->GetAtomTable(residue_atoms, n_residue_atoms); for (int i=0; iname); + std::string atom_name(residue_atoms[i]->GetAtomName()); if ((atom_name == " NH1") || (atom_name == " NH2")) { - clipper::Coord_orth pt(residue_atoms[i]->x, - residue_atoms[i]->y, - residue_atoms[i]->z); + clipper::Coord_orth pt(residue_atoms[i]->x(), + residue_atoms[i]->y(), + residue_atoms[i]->z()); v.push_back(pt); } } diff --git a/pli/protein-ligand-interactions.cc b/pli/protein-ligand-interactions.cc index ff3507d762..839d997364 100644 --- a/pli/protein-ligand-interactions.cc +++ b/pli/protein-ligand-interactions.cc @@ -144,7 +144,7 @@ pli::get_fle_ligand_bonds(mmdb::Residue *ligand_res, // } if (debug) - std::cout << "constructing fle ligand bond " << ligand_atom->name + std::cout << "constructing fle ligand bond " << ligand_atom->GetAtomName() << " " << bond_type << " " << hbonds[i].dist << " " << coot::atom_spec_t(env_residue_atom) << " " << env_residue_atom->GetResName() @@ -172,7 +172,7 @@ pli::get_fle_ligand_bonds(mmdb::Residue *ligand_res, std::string residue_name = ligand_atom->GetResName(); if (residue_name == "HOH") - bond.water_protein_length = find_water_protein_length(ligand_atom->residue, mol); + bond.water_protein_length = find_water_protein_length(ligand_atom->GetResidue(), mol); v.push_back(bond); } @@ -297,8 +297,8 @@ pli::get_covalent_bonds_by_distance(mmdb::Manager *mol, mmdb::Atom *at_2 = other_atom_selection[pscontact[i].id2]; // move on if these are interacting atoms - std::string alt_conf_1 = at_1->altLoc; - std::string alt_conf_2 = at_2->altLoc; + std::string alt_conf_1 = at_1->altLoc(); + std::string alt_conf_2 = at_2->altLoc(); if (!alt_conf_1.empty() && ! alt_conf_2.empty()) if (alt_conf_1 != alt_conf_2) continue; @@ -309,12 +309,12 @@ pli::get_covalent_bonds_by_distance(mmdb::Manager *mol, std::pair pair(at_1->GetResidue(), at_2->GetResidue()); - std::string ele_1 = at_1->element; - std::string ele_2 = at_2->element; + std::string ele_1 = at_1->GetElementName(); + std::string ele_2 = at_2->GetElementName(); if (ele_1 != " H") { if (ele_2 != " H") { - clipper::Coord_orth pt_1(at_1->x, at_1->y, at_1->z); - clipper::Coord_orth pt_2(at_2->x, at_2->y, at_2->z); + clipper::Coord_orth pt_1(at_1->x(), at_1->y(), at_1->z()); + clipper::Coord_orth pt_2(at_2->x(), at_2->y(), at_2->z()); double d = (pt_1-pt_2).lengthsq(); double dist_for_bond = max_dist; @@ -379,8 +379,8 @@ pli::get_covalent_bonds_by_links(mmdb::Residue *residue_ligand_p, if (at_1 && at_2) { // move on if these are interacting atoms - std::string alt_conf_1 = at_1->altLoc; - std::string alt_conf_2 = at_2->altLoc; + std::string alt_conf_1 = at_1->altLoc(); + std::string alt_conf_2 = at_2->altLoc(); if (!alt_conf_1.empty() && ! alt_conf_2.empty()) if (alt_conf_1 != alt_conf_2) continue; @@ -405,8 +405,8 @@ pli::get_covalent_bonds_by_links(mmdb::Residue *residue_ligand_p, if (at_1 && at_2) { // move on if these are interacting atoms - std::string alt_conf_1 = at_1->altLoc; - std::string alt_conf_2 = at_2->altLoc; + std::string alt_conf_1 = at_1->altLoc(); + std::string alt_conf_2 = at_2->altLoc(); if (!alt_conf_1.empty() && ! alt_conf_2.empty()) if (alt_conf_1 != alt_conf_2) continue; @@ -454,20 +454,20 @@ pli::get_metal_bonds(mmdb::Residue *ligand_residue, const std::vectoraltLoc; - std::string alt_conf_2 = at_2->altLoc; + std::string alt_conf_1 = at_1->altLoc(); + std::string alt_conf_2 = at_2->altLoc(); if (!alt_conf_1.empty() && ! alt_conf_2.empty()) if (alt_conf_1 != alt_conf_2) continue; - std::string ele(residue_atoms[irat]->element); + std::string ele(residue_atoms[irat]->GetElementName()); if ((ele == " H") || (ele == " C")) { - clipper::Coord_orth pt_1(ligand_residue_atoms[ilat]->x, - ligand_residue_atoms[ilat]->y, - ligand_residue_atoms[ilat]->z); - clipper::Coord_orth pt_2(residue_atoms[irat]->x, - residue_atoms[irat]->y, - residue_atoms[irat]->z); + clipper::Coord_orth pt_1(ligand_residue_atoms[ilat]->x(), + ligand_residue_atoms[ilat]->y(), + ligand_residue_atoms[ilat]->z()); + clipper::Coord_orth pt_2(residue_atoms[irat]->x(), + residue_atoms[irat]->y(), + residue_atoms[irat]->z()); double d2 = (pt_1-pt_2).clipper::Coord_orth::lengthsq(); if (d2 < best_dist_sqrd) { best_dist_sqrd = d2; @@ -627,14 +627,14 @@ pli::find_water_protein_length(mmdb::Residue *ligand_residue, mmdb::Manager *mol residue_p->GetAtomTable(residue_atoms, n_residue_atoms); for (int il=0; ilelement); + std::string ele(residue_atoms[irat]->GetElementName()); if ((ele == " O") || (ele == " N")) { - clipper::Coord_orth pt_1(ligand_residue_atoms[il]->x, - ligand_residue_atoms[il]->y, - ligand_residue_atoms[il]->z); - clipper::Coord_orth pt_2(residue_atoms[irat]->x, - residue_atoms[irat]->y, - residue_atoms[irat]->z); + clipper::Coord_orth pt_1(ligand_residue_atoms[il]->x(), + ligand_residue_atoms[il]->y(), + ligand_residue_atoms[il]->z()); + clipper::Coord_orth pt_2(residue_atoms[irat]->x(), + residue_atoms[irat]->y(), + residue_atoms[irat]->z()); double d2 = (pt_1-pt_2).clipper::Coord_orth::lengthsq(); if (d2 < dist_sqrd) { dist_sqrd = d2; diff --git a/python/coot_commands/mic.py b/python/coot_commands/mic.py new file mode 100644 index 0000000000..f14e7e145f --- /dev/null +++ b/python/coot_commands/mic.py @@ -0,0 +1,124 @@ +# coot_commands/mic.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""Record a voice request from the microphone and output it as base64 WAV. + +Protocol (one JSON object per line on stdout): + {"type": "recording"} — microphone opened, recording has started + {"type": "audio", "data": "..."} — base64-encoded 16 kHz mono WAV, ready to send + {"type": "error", "message": "..."} + +Records until a period of silence is detected or the maximum duration is +reached. Requires ``sounddevice`` and ``numpy`` (pip install sounddevice numpy). +""" + +from __future__ import annotations + +import base64 +import io +import json +import sys +import wave + +SAMPLERATE = 16000 +SILENCE_THRESHOLD = 500 # RMS on int16 scale (0–32 768); tune to mic +SILENCE_DURATION = 1.5 # seconds of quiet that ends the recording +MAX_DURATION = 30.0 # hard cap in seconds + + +def _emit(obj: dict) -> None: + print(json.dumps(obj), flush=True) + + +def _record(samplerate: int = SAMPLERATE, + silence_threshold: float = SILENCE_THRESHOLD, + silence_duration: float = SILENCE_DURATION, + max_duration: float = MAX_DURATION): + import numpy as np + import sounddevice as sd + + chunk_s = 0.1 # 100 ms chunks + chunk_frames = int(samplerate * chunk_s) + max_chunks = int(max_duration / chunk_s) + silence_chunks_needed = int(silence_duration / chunk_s) + + chunks = [] + silent_count = 0 + speech_started = False + + with sd.InputStream(samplerate=samplerate, channels=1, dtype="int16") as stream: + for _ in range(max_chunks): + chunk, _ = stream.read(chunk_frames) + chunks.append(chunk.copy()) + rms = float(np.sqrt(np.mean(chunk.astype(np.float32) ** 2))) + if rms >= silence_threshold: + speech_started = True + silent_count = 0 + elif speech_started: + silent_count += 1 + if silent_count >= silence_chunks_needed: + break + + import numpy as np + return np.concatenate(chunks, axis=0) if chunks else np.zeros((0, 1), dtype="int16") + + +def _to_wav_b64(samples, samplerate: int = SAMPLERATE) -> str: + buf = io.BytesIO() + with wave.open(buf, "wb") as wf: + wf.setnchannels(1) + wf.setsampwidth(2) # int16 = 2 bytes per sample + wf.setframerate(samplerate) + wf.writeframes(samples.flatten().tobytes()) + return base64.b64encode(buf.getvalue()).decode("ascii") + + +def main() -> int: + try: + import numpy # noqa: F401 + except ImportError: + _emit({"type": "error", "message": "numpy not installed (pip install numpy)"}) + return 1 + try: + import sounddevice # noqa: F401 + except ImportError: + _emit({"type": "error", "message": "sounddevice not installed (pip install sounddevice)"}) + return 1 + + _emit({"type": "recording"}) + try: + samples = _record() + except Exception as exc: + _emit({"type": "error", "message": f"recording failed: {exc}"}) + return 1 + + import numpy as np + if samples.size == 0 or float(np.sqrt(np.mean(samples.astype(np.float32) ** 2))) < SILENCE_THRESHOLD / 2: + _emit({"type": "error", "message": "no speech detected"}) + return 1 + + try: + data = _to_wav_b64(samples) + except Exception as exc: + _emit({"type": "error", "message": f"WAV encoding failed: {exc}"}) + return 1 + + _emit({"type": "audio", "data": data}) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/python/coot_commands/tts.py b/python/coot_commands/tts.py new file mode 100644 index 0000000000..5e0adcd8ff --- /dev/null +++ b/python/coot_commands/tts.py @@ -0,0 +1,100 @@ +# coot_commands/tts.py +# +# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology +# +# This file is part of Coot +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +"""Speak a line of text aloud with a local Piper (onnxruntime) neural voice. + +Coot's Assistant tab spawns this as a subprocess to read the agent's final +answer out loud, in place of the macOS ``say`` command. The text is passed as +the first command-line argument (falling back to stdin), synthesised entirely +offline with Piper, and played through the default output device. The process +runs until playback finishes, or until Coot force-exits it to interrupt speech. + +Errors are reported as a single JSON line on stdout so the GUI can surface them +(``{"type": "error", "message": "..."}``); success is silent. Requires +``piper-tts`` and ``sounddevice`` (pip install piper-tts sounddevice). The +voice model is chosen by ``COOT_PIPER_VOICE`` (path to a ``.onnx`` file), +defaulting to ``~/.local/share/coot/piper/en_GB-northern_english_male-medium.onnx``. +""" + +from __future__ import annotations + +import json +import os +import sys + +DEFAULT_VOICE = os.path.expanduser( + "~/.local/share/coot/piper/en_GB-northern_english_male-medium.onnx") + + +def _emit(obj: dict) -> None: + print(json.dumps(obj), flush=True) + + +def _voice_path() -> str: + return os.environ.get("COOT_PIPER_VOICE", DEFAULT_VOICE) + + +def speak(text: str) -> int: + """Synthesise *text* with Piper and play it; return a process exit code.""" + text = text.strip() + if not text: + return 0 + + try: + import numpy as np + import sounddevice as sd + from piper import PiperVoice + except ImportError as exc: + _emit({"type": "error", + "message": f"text-to-speech needs piper-tts + sounddevice ({exc})"}) + return 1 + + voice_path = _voice_path() + if not os.path.exists(voice_path): + _emit({"type": "error", + "message": f"Piper voice not found: {voice_path} " + "(set COOT_PIPER_VOICE or download a voice)"}) + return 1 + + try: + voice = PiperVoice.load(voice_path) + parts = [chunk.audio_int16_array for chunk in voice.synthesize(text)] + except Exception as exc: # noqa: BLE001 - report any synthesis failure + _emit({"type": "error", "message": f"speech synthesis failed: {exc}"}) + return 1 + + if not parts: + return 0 + samples = np.concatenate(parts) + try: + sd.play(samples, samplerate=voice.config.sample_rate) + sd.wait() + except Exception as exc: # noqa: BLE001 - playback device may be unavailable + _emit({"type": "error", "message": f"audio playback failed: {exc}"}) + return 1 + return 0 + + +def main() -> int: + if len(sys.argv) > 1: + text = sys.argv[1] + else: + text = sys.stdin.read() + return speak(text) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/skeleton/BuildCas.cc b/skeleton/BuildCas.cc index 0a8add14f7..d75effe845 100644 --- a/skeleton/BuildCas.cc +++ b/skeleton/BuildCas.cc @@ -204,8 +204,8 @@ BuildCas::convert_to_atoms_internal(clipper::Spacegroup spg, if (i_atom_loop_count == 0 || diff_residue_flag == 1) { res_p = new mmdb::Residue; - res_p->seqNum = 1 + i_res_add; // set the residue number to 1 + ... - strcpy(res_p->name, molecule_name.c_str()); + res_p->GetSeqNum() = 1 + i_res_add; // set the residue number to 1 + ... + res_p->SetResName(molecule_name.c_str()); chain_p->AddResidue ( res_p ); } @@ -431,9 +431,9 @@ BuildCas::point_list_by_symmetry(atom_selection_container_t AtomSel, // consider pushing back contact[ii].id2, with // std::vector big_ball; // - coot::Cartesian a(trans_selection [ contact[ii].id2 ]->x, - trans_selection [ contact[ii].id2 ]->y, - trans_selection [ contact[ii].id2 ]->z); + coot::Cartesian a(trans_selection [ contact[ii].id2 ]->x(), + trans_selection [ contact[ii].id2 ]->y(), + trans_selection [ contact[ii].id2 ]->z()); // coot::Cartesian_and_Grid cag(a, grids[ii]); // big_ball_l.push_back(cag); @@ -1231,11 +1231,11 @@ BuildCas::check_angle_torsion(atom_selection_container_t asc) const { for (int i=0; i< asc.n_selected_atoms; i++) { - if (std::string(asc.atom_selection[i]->name) == " CA " ) { + if (std::string(asc.atom_selection[i]->GetAtomName()) == " CA " ) { - coot::Cartesian pos(asc.atom_selection[i]->x, - asc.atom_selection[i]->y, - asc.atom_selection[i]->z); + coot::Cartesian pos(asc.atom_selection[i]->x(), + asc.atom_selection[i]->y(), + asc.atom_selection[i]->z()); std::cout << "Got a CA at " << pos << std::endl; @@ -1557,8 +1557,8 @@ BuildCas::move_by_symmetry(coot::Cartesian middle_mol, atom->SetCoordinates(middle_mol.x(), middle_mol.y(), middle_mol.z(), 1.0, 99); // - std::cout << "atom from middle_mol: " << atom->x << " " - << atom->y << " " << atom->z << std::endl; + std::cout << "atom from middle_mol: " << atom->x() << " " + << atom->y() << " " << atom->z() << std::endl; short int moved_it_flag = TRUE; @@ -1577,9 +1577,9 @@ BuildCas::move_by_symmetry(coot::Cartesian middle_mol, trans_atom->Copy(atom); trans_atom->Transform(my_matt); - coot::Cartesian cart_atom(trans_atom->x, - trans_atom->y, - trans_atom->z); + coot::Cartesian cart_atom(trans_atom->x(), + trans_atom->y(), + trans_atom->z()); std::cout << "testing atom at: " << cart_atom << std::endl; @@ -1598,7 +1598,7 @@ BuildCas::move_by_symmetry(coot::Cartesian middle_mol, } } - coot::Cartesian a(atom->x, atom->y, atom->z); + coot::Cartesian a(atom->x(), atom->y(), atom->z()); delete atom; delete trans_atom; diff --git a/src/coot-nomenclature.cc b/src/coot-nomenclature.cc index 17cf64edac..48d9e2782c 100644 --- a/src/coot-nomenclature.cc +++ b/src/coot-nomenclature.cc @@ -125,7 +125,7 @@ coot::nomenclature::fix_and_swap_maybe(const coot::protein_geometry *Geom_p, boo int imol = 0; // dummy std::vector chiral_restraints = - Geom_p->get_monomer_chiral_volumes(std::string(residue_p->name), imol); + Geom_p->get_monomer_chiral_volumes(std::string(residue_p->GetResName()), imol); coot::dict_chiral_restraint_t chiral_restraint; for (unsigned int irestr=0; irestraltLoc; - std::string atom_name = residue_atoms[iat]->name; + std::string alt_conf = residue_atoms[iat]->altLoc(); + std::string atom_name = residue_atoms[iat]->GetAtomName(); if (atom_name == " OG1" ) if (alt_conf == alt_conf_bad) og1 = residue_atoms[iat]; @@ -243,8 +243,8 @@ coot::nomenclature::fix_and_swap_maybe(const coot::protein_geometry *Geom_p, boo mmdb::Atom *cg1 = 0; // cd1 and cd2 for LEU of course mmdb::Atom *cg2 = 0; for (int iat=0; iataltLoc; - std::string atom_name = residue_atoms[iat]->name; + std::string alt_conf = residue_atoms[iat]->altLoc(); + std::string atom_name = residue_atoms[iat]->GetAtomName(); if (atom_name == target_atom_1 ) if (alt_conf == alt_conf_bad) cg1 = residue_atoms[iat]; @@ -304,9 +304,9 @@ coot::nomenclature::test_and_fix_PHE_TYR_nomenclature_errors(mmdb::Residue *resi std::vector alt_conf_list; // first get the altconfs in the residue: for (int i=0; iname; + std::string atom_name = residue_atoms[i]->GetAtomName(); if(atom_name == " CD1") { - alt_conf_list.push_back(residue_atoms[i]->altLoc); + alt_conf_list.push_back(residue_atoms[i]->altLoc()); } } @@ -323,8 +323,8 @@ coot::nomenclature::test_and_fix_PHE_TYR_nomenclature_errors(mmdb::Residue *resi mmdb::Atom *CD1 = 0; mmdb::Atom *CD2 = 0; for (int i=0; iname; - std::string atom_altconf = residue_atoms[i]->altLoc; + std::string atom_name = residue_atoms[i]->GetAtomName(); + std::string atom_altconf = residue_atoms[i]->altLoc(); if (atom_altconf == alt_conf_list[ialtconf]) { if (atom_name == " CA ") CA = residue_atoms[i]; @@ -340,8 +340,8 @@ coot::nomenclature::test_and_fix_PHE_TYR_nomenclature_errors(mmdb::Residue *resi } if (CA==0 || CB==0 || CG==0) { // no need for CD1, it will be set for (int i=0; iname; - std::string atom_altconf = residue_atoms[i]->altLoc; + std::string atom_name = residue_atoms[i]->GetAtomName(); + std::string atom_altconf = residue_atoms[i]->altLoc(); if (atom_altconf == "") { if (atom_name == " CA ") CA = residue_atoms[i]; @@ -359,10 +359,10 @@ coot::nomenclature::test_and_fix_PHE_TYR_nomenclature_errors(mmdb::Residue *resi if (CA && CB && CG && CD1) { - clipper::Coord_orth a1(CA->x, CA->y, CA->z); - clipper::Coord_orth a2(CB->x, CB->y, CB->z); - clipper::Coord_orth a3(CG->x, CG->y, CG->z); - clipper::Coord_orth a4(CD1->x, CD1->y, CD1->z); + clipper::Coord_orth a1(CA->x(), CA->y(), CA->z()); + clipper::Coord_orth a2(CB->x(), CB->y(), CB->z()); + clipper::Coord_orth a3(CG->x(), CG->y(), CG->z()); + clipper::Coord_orth a4(CD1->x(), CD1->y(), CD1->z()); double tors = clipper::Util::rad2d(clipper::Coord_orth::torsion(a1, a2, a3, a4)); @@ -371,7 +371,7 @@ coot::nomenclature::test_and_fix_PHE_TYR_nomenclature_errors(mmdb::Residue *resi // ooops, there was a problem with this torsion. if (CD2) { - clipper::Coord_orth a4_o(CD2->x, CD2->y, CD2->z); + clipper::Coord_orth a4_o(CD2->x(), CD2->y(), CD2->z()); double cg2_tors = clipper::Util::rad2d(clipper::Coord_orth::torsion(a1, a2, a3, a4_o)); // if cg2_tors is in range, then we swap atom names @@ -384,8 +384,8 @@ coot::nomenclature::test_and_fix_PHE_TYR_nomenclature_errors(mmdb::Residue *resi mmdb::Atom *HE1 = 0; mmdb::Atom *HE2 = 0; for (int ie=0; iename; - std::string e_atom_altconf = residue_atoms[ie]->altLoc; + std::string e_atom_name = residue_atoms[ie]->GetAtomName(); + std::string e_atom_altconf = residue_atoms[ie]->altLoc(); if (e_atom_altconf == alt_conf_list[ialtconf]) { if (e_atom_name == " CE1") CE1 = residue_atoms[ie]; @@ -410,15 +410,15 @@ coot::nomenclature::test_and_fix_PHE_TYR_nomenclature_errors(mmdb::Residue *resi CE1->SetAtomName(" CE2"); CE2->SetAtomName(" CE1"); #endif - mmdb::realtype pos_cd1[3] = {CD1->x, CD1->y, CD1->z}; - mmdb::realtype pos_cd2[3] = {CD2->x, CD2->y, CD2->z}; - mmdb::realtype pos_ce1[3] = {CE1->x, CE1->y, CE1->z}; - mmdb::realtype pos_ce2[3] = {CE2->x, CE2->y, CE2->z}; - - CD1->x = pos_cd2[0]; CD1->y = pos_cd2[1]; CD1->z = pos_cd2[2]; - CD2->x = pos_cd1[0]; CD2->y = pos_cd1[1]; CD2->z = pos_cd1[2]; - CE1->x = pos_ce2[0]; CE1->y = pos_ce2[1]; CE1->z = pos_ce2[2]; - CE2->x = pos_ce1[0]; CE2->y = pos_ce1[1]; CE2->z = pos_ce1[2]; + mmdb::realtype pos_cd1[3] = {CD1->x(), CD1->y(), CD1->z()}; + mmdb::realtype pos_cd2[3] = {CD2->x(), CD2->y(), CD2->z()}; + mmdb::realtype pos_ce1[3] = {CE1->x(), CE1->y(), CE1->z()}; + mmdb::realtype pos_ce2[3] = {CE2->x(), CE2->y(), CE2->z()}; + + CD1->x() = pos_cd2[0]; CD1->y() = pos_cd2[1]; CD1->z() = pos_cd2[2]; + CD2->x() = pos_cd1[0]; CD2->y() = pos_cd1[1]; CD2->z() = pos_cd1[2]; + CE1->x() = pos_ce2[0]; CE1->y() = pos_ce2[1]; CE1->z() = pos_ce2[2]; + CE2->x() = pos_ce1[0]; CE2->y() = pos_ce1[1]; CE2->z() = pos_ce1[2]; } if (false) std::cout << "DEBUG:: swapped in test_and_fix_PHE_TYR_nomenclature_errors()" @@ -477,9 +477,9 @@ coot::nomenclature::test_and_fix_ASP_GLU_nomenclature_errors(mmdb::Residue *resi std::vector alt_conf_list; // first get the altconfs in the residue: for (int i=0; iname; + std::string atom_name = residue_atoms[i]->GetAtomName(); if(atom_name == test_atom_name) { - alt_conf_list.push_back(residue_atoms[i]->altLoc); + alt_conf_list.push_back(residue_atoms[i]->altLoc()); } } @@ -490,8 +490,8 @@ coot::nomenclature::test_and_fix_ASP_GLU_nomenclature_errors(mmdb::Residue *resi coot::atom_index_quad quad; for (int i=0; iname; - std::string atom_altconf = residue_atoms[i]->altLoc; + std::string atom_name = residue_atoms[i]->GetAtomName(); + std::string atom_altconf = residue_atoms[i]->altLoc(); if (atom_altconf == alt_conf_list[ialtconf]) { if (residue_name == "ASP") { @@ -540,8 +540,8 @@ coot::nomenclature::test_and_fix_ASP_GLU_nomenclature_errors(mmdb::Residue *resi mmdb::Atom *at_1 = 0; mmdb::Atom *at_2 = 0; for (int i=0; iname; - std::string atom_altconf = residue_atoms[i]->altLoc; + std::string atom_name = residue_atoms[i]->GetAtomName(); + std::string atom_altconf = residue_atoms[i]->altLoc(); if (atom_altconf == alt_conf_list[ialtconf]) { if (atom_name == swap_name_1) at_1 = residue_atoms[i]; From 8404c0c66644e5a69f69bd32e177e362787406e1 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Tue, 21 Jul 2026 23:56:58 +0100 Subject: [PATCH 06/23] Added other shims to make Coot compile --- mmdb-shim/include/gemmi/mmdb.hpp | 43 +++ mmdb-shim/include/mmdb2/_graph_impl.hh | 346 +++++++++++++++++++++++++ mmdb-shim/include/mmdb2/_shim_impl.hh | 73 +++++- mmdb-shim/include/ssm/ssm_align.h | 72 +++++ 4 files changed, 521 insertions(+), 13 deletions(-) create mode 100644 mmdb-shim/include/gemmi/mmdb.hpp create mode 100644 mmdb-shim/include/mmdb2/_graph_impl.hh create mode 100644 mmdb-shim/include/ssm/ssm_align.h diff --git a/mmdb-shim/include/gemmi/mmdb.hpp b/mmdb-shim/include/gemmi/mmdb.hpp new file mode 100644 index 0000000000..2f6e22657d --- /dev/null +++ b/mmdb-shim/include/gemmi/mmdb.hpp @@ -0,0 +1,43 @@ +// -*- mode: c++; -*- +// +// mmdb-shim: replacement for gemmi's own bridge. +// +// The real gemmi/mmdb.hpp converts gemmi::Structure <-> mmdb::Manager by copying +// field-by-field through real-mmdb PUBLIC FIELDS (atom->x = ..., chain->seqRes, +// mmdb::newAtom(), Cryst::Z, ...). That is fundamentally incompatible with the +// accessor-based shim (x/y/z are methods, not fields). +// +// But it is also unnecessary: the shim's mmdb::Manager already OWNS a live +// gemmi::Structure (Manager::st), so the conversions are near-trivial. This header +// is picked up instead of gemmi's because the shim include dir precedes gemmi's on +// the -I path. Only the functions Coot actually calls are provided. +// +// Copyright 2026 by Medical Research Council Laboratory of Molecular Biology +#ifndef COOT_MMDB_SHIM_GEMMI_MMDB_HPP +#define COOT_MMDB_SHIM_GEMMI_MMDB_HPP + +#include // shim mmdb::Manager (wraps gemmi::Structure) +#include // gemmi::Structure + +namespace gemmi { + +// gemmi::Structure -> mmdb::Manager: the shim Manager IS a gemmi::Structure +// wrapper, so adopt the structure and (re)build the wrapper hierarchy. +inline void copy_to_mmdb(const Structure& st, mmdb::Manager* manager) { + if (!manager) return; + manager->st = st; + manager->build_from_gemmi(); +} + +// mmdb::Manager -> gemmi::Structure: st is the source of truth (all wrappers +// resolve into it), so just return it. +inline Structure copy_from_mmdb(mmdb::Manager* manager) { + return manager ? manager->st : Structure(); +} + +// SEQRES already travels inside Manager::st, so this is a no-op in the shim. +inline void transfer_seqres_to_mmdb(const Structure&, mmdb::Manager*) {} + +} // namespace gemmi + +#endif // COOT_MMDB_SHIM_GEMMI_MMDB_HPP diff --git a/mmdb-shim/include/mmdb2/_graph_impl.hh b/mmdb-shim/include/mmdb2/_graph_impl.hh new file mode 100644 index 0000000000..b4edbeab48 --- /dev/null +++ b/mmdb-shim/include/mmdb2/_graph_impl.hh @@ -0,0 +1,346 @@ +// -*- mode: c++; -*- +// +// mmdb-shim: mmdb::math::{Vertex,Edge,Graph,GraphMatch} — molecular graph + +// subgraph matching. gemmi has NO subgraph-isomorphism facility (see +// mmdb-graph-matching-for-gemmi.md §3), so per coot-shim-prefer-gemmi this is one +// of the few pieces genuinely hand-written: a branch-and-bound maximum-common- +// (induced-)subgraph matcher. Element typing uses gemmi::Element. +// +// Copyright 2026 by Medical Research Council Laboratory of Molecular Biology +// +// Included at the end of _shim_impl.hh (Residue/Atom complete; pstr/cpstr/ +// realtype/ivector/word already in namespace mmdb). +#ifndef COOT_MMDB_SHIM_GRAPH_IMPL_HH +#define COOT_MMDB_SHIM_GRAPH_IMPL_HH + +#include + +#include +#include +#include +#include +#include +#include + +namespace mmdb { +namespace math { + +// ---- constants (mmdb_math_graph.h) -------------------------------------- +enum GRAPH_BOND { BOND_SINGLE = 1, BOND_DOUBLE = 2, BOND_AROMATIC = 3, BOND_TRIPLE = 4 }; +enum GRAPH_RC { MKGRAPH_Ok = 0, MKGRAPH_NoAtoms = -1, + MKGRAPH_ChangedAltLoc = 1, MKGRAPH_MaxOccupancy = 2 }; +enum GRAPH_MATCH_FLAG { GMF_UniqueMatch = 0x00000001, GMF_NoCombinations = 0x00000002 }; +enum VERTEX_EXT_TYPE { EXTTYPE_Ignore = 0, EXTTYPE_Equal = 1, EXTTYPE_AND = 2, + EXTTYPE_OR = 3, EXTTYPE_XOR = 4, EXTTYPE_NotEqual = 5, + EXTTYPE_NotAND = 6, EXTTYPE_NotOR = 7 }; + +namespace gdetail { + inline std::string trim(cpstr s) { + std::string t(s ? s : ""); + size_t a = t.find_first_not_of(" \t"), b = t.find_last_not_of(" \t"); + return a == std::string::npos ? std::string() : t.substr(a, b - a + 1); + } + inline int bond_from_string(cpstr s) { + std::string t = trim(s); + for (auto &c : t) c = (char) std::tolower((unsigned char) c); + if (t == "single" || t == "sing" || t == "1") return BOND_SINGLE; + if (t == "double" || t == "doub" || t == "2") return BOND_DOUBLE; + if (t == "aromatic" || t == "arom" || t == "ar") return BOND_AROMATIC; + if (t == "triple" || t == "trip" || t == "3") return BOND_TRIPLE; + return BOND_SINGLE; + } +} + +// ========================================================================= +// Vertex — a graph node (atom). `type` encodes element (atomic number) so +// GetType() equality means "same element". +// ========================================================================= +class Vertex { + public: + int type = 0, type_ext = 0, property = 0, nBonds = 0, id = 0, user_id = 0; + std::string name; + + Vertex() {} + Vertex(cpstr chem_elem) { SetVertex(chem_elem); } + Vertex(cpstr chem_elem, cpstr vname) { SetVertex(chem_elem); name = vname ? vname : ""; } + Vertex(int vtype, cpstr vname) { type = vtype; name = vname ? vname : ""; } + explicit Vertex(int vtype) { type = vtype; } + + void SetVertex(cpstr chem_elem) { + type = (int) gemmi::Element(gdetail::trim(chem_elem).c_str()).atomic_number(); + } + void SetVertex(int vtype, cpstr vname) { type = vtype; name = vname ? vname : ""; } + void SetVertex(int vtype) { type = vtype; } + void SetName(cpstr vname) { name = vname ? vname : ""; } + void SetType(int t) { type = t; } + void SetTypeExt(int t) { type_ext = t; } + void SaveType() { property = type; } + void RestoreType() { type = property; } + void SetUserID(int u) { user_id = u; } + cpstr GetName() { return name.c_str(); } + int GetType() { return type; } + int GetTypeExt() { return type_ext; } + int GetNBonds() { return nBonds; } + int GetUserID() { return user_id; } // 0-based atom index (see MakeVertexIDs/MakeGraph) + void Print(int /*PKey*/ = 0) {} +}; +typedef Vertex *PVertex; typedef Vertex **PPVertex; + +// ========================================================================= +// Edge — a graph connection (bond). v1/v2 are 1-indexed vertex numbers. +// ========================================================================= +class Edge { + public: + int v1 = 0, v2 = 0, type = 0, property = 0; + + Edge() {} + Edge(int vx1, int vx2, int btype) { v1 = vx1; v2 = vx2; type = btype; } + Edge(int vx1, int vx2, cpstr btype) { v1 = vx1; v2 = vx2; type = gdetail::bond_from_string(btype); } + + void SetEdge(int vx1, int vx2, int btype) { v1 = vx1; v2 = vx2; type = btype; } + void SetEdge(int vx1, int vx2, cpstr btype) { v1 = vx1; v2 = vx2; type = gdetail::bond_from_string(btype); } + void SetType(int t) { type = t; } + int GetVertex1() { return v1; } + int GetVertex2() { return v2; } + int GetType() { return type; } + void Print(int /*PKey*/ = 0) {} +}; +typedef Edge *PEdge; typedef Edge **PPEdge; + +// ========================================================================= +// Graph — vertices + edges + adjacency matrix (built by Build()). +// Owns the Vertex/Edge objects handed to AddVertex/AddEdge (mmdb semantics). +// ========================================================================= +class Graph { + public: + std::string gname; + std::vector V; // owned; 1-indexed via GetVertex + std::vector E; // owned + std::vector> adj; // (n+1)x(n+1), 1-indexed; adj[i][j]=bond type or 0 + + Graph() {} + ~Graph() { for (auto *p : V) delete p; for (auto *e : E) delete e; } + Graph(const Graph &) = delete; + Graph &operator=(const Graph &) = delete; + + void SetName(cpstr n) { gname = n ? n : ""; } + pstr GetName() { return (pstr) gname.c_str(); } + void AddVertex(PVertex v) { if (v) V.push_back(v); } + void AddEdge(PEdge e) { if (e) E.push_back(e); } + int GetNofVertices() { return (int) V.size(); } + int GetNofEdges() { return (int) E.size(); } + PVertex GetVertex(int i) { return (i >= 1 && i <= (int) V.size()) ? V[i - 1] : nullptr; } + PEdge GetEdge(int i) { return (i >= 1 && i <= (int) E.size()) ? E[i - 1] : nullptr; } + void GetVertices(PPVertex &v, int &n) { v = V.data(); n = (int) V.size(); } + void GetEdges(PPEdge &e, int &n) { e = E.data(); n = (int) E.size(); } + // number vertices; user_id = 0-based position so `residue->atom[V->GetUserID()]` + // (Coot's manual make_graph path) indexes the residue's 0-based atom table. + void MakeVertexIDs() { for (int i = 0; i < (int) V.size(); ++i) { V[i]->id = i + 1; V[i]->user_id = i; } } + void Print() {} + void Print1() {} + void MakeSymmetryRelief(bool /*noCO2*/) {} // type_ext modifiers — low priority, no-op + void IdentifyRings() {} // " " + void IdentifyConnectedComponents() {} + + // adjacency matrix; bondOrder=false collapses all bonds to 1 (connectivity only) + int Build(bool bondOrder) { + int n = (int) V.size(); + adj.assign(n + 1, std::vector(n + 1, 0)); + for (Edge *e : E) + if (e->v1 >= 1 && e->v1 <= n && e->v2 >= 1 && e->v2 <= n) { + int t = bondOrder ? (e->type > 0 ? e->type : 1) : 1; + adj[e->v1][e->v2] = t; adj[e->v2][e->v1] = t; + } + for (int i = 1; i <= n; ++i) { + int b = 0; for (int j = 1; j <= n; ++j) if (adj[i][j]) ++b; + V[i - 1]->nBonds = b; + } + return 0; + } + + int MakeGraph(PPAtom atom, int nAtoms); // build from atoms (distance bonds) + int MakeGraph(PResidue R, cpstr altLoc = nullptr); +}; +typedef Graph *PGraph; + +// ========================================================================= +// GraphMatch — maximum common (induced) subgraph via branch-and-bound. +// ========================================================================= +class GraphMatch { + public: + struct Match { std::vector f1, f2; }; // 1-indexed vertex numbers + std::vector matches; + int maxMatch = 0; + int maxNofMatches = 1000000; + bool stopOnMax = false; + int timeLimit = 0; // seconds; 0 = no limit + word flags = 0; + bool Stop = false; + // stable 1-indexed ivector storage for GetMatch (freed with this object) + std::vector> fv1, fv2; + + void SetFlag(word f) { flags |= f; } + void RemoveFlag(word f) { flags &= ~f; } + void SetMaxNofMatches(int m, bool stopOnMaxN) { maxNofMatches = m > 0 ? m : 1; stopOnMax = stopOnMaxN; } + void SetTimeLimit(int t = 0) { timeLimit = t; } + int GetNofMatches() { return (int) matches.size(); } + int GetMaxMatchSize() { return maxMatch; } + bool GetStopSignal() { return Stop; } + void Reset() { matches.clear(); fv1.clear(); fv2.clear(); maxMatch = 0; } + void PrintMatches() {} + + void MatchGraphs(PGraph Gh1, PGraph Gh2, int minMatch, bool vertexType = true, + VERTEX_EXT_TYPE vertexExt = EXTTYPE_Ignore); + void GetMatch(int MatchNo, ivector &FV1, ivector &FV2, int &nv, realtype &p1, realtype &p2); +}; +typedef GraphMatch *PGraphMatch; + +// ---- MatchGraphs: branch-and-bound maximum common induced subgraph ------- +inline void GraphMatch::MatchGraphs(PGraph g1, PGraph g2, int minMatch, + bool vertexType, VERTEX_EXT_TYPE vertexExt) { + Reset(); Stop = false; + int n1 = g1->GetNofVertices(), n2 = g2->GetNofVertices(); + if (n1 == 0 || n2 == 0) return; + if ((int) g1->adj.size() != n1 + 1) g1->Build(false); + if ((int) g2->adj.size() != n2 + 1) g2->Build(false); + const std::vector> &A1 = g1->adj, &A2 = g2->adj; + + auto t0 = std::chrono::steady_clock::now(); + auto timed_out = [&]() -> bool { + if (timeLimit <= 0) return false; + if (std::chrono::duration_cast( + std::chrono::steady_clock::now() - t0).count() >= timeLimit) { Stop = true; return true; } + return false; + }; + + std::vector> cur; // matched (g1,g2) 1-indexed pairs + std::vector used2(n2 + 1, 0); + std::vector>> best; + + auto compatible = [&](int i1, int i2) -> bool { + if (vertexType && g1->V[i1 - 1]->type != g2->V[i2 - 1]->type) return false; + if (vertexExt == EXTTYPE_Equal && g1->V[i1 - 1]->type_ext != g2->V[i2 - 1]->type_ext) return false; + for (const auto &pr : cur) // preserve edges (incl. absence) + bond type + if (A1[i1][pr.first] != A2[i2][pr.second]) return false; + return true; + }; + + std::function rec = [&](int idx) { + if (Stop || timed_out()) return; + // bound: best achievable from here can't exceed cur + remaining g1 vertices + if ((int) cur.size() + (n1 - idx + 1) < maxMatch) return; + if (idx > n1) { + int sz = (int) cur.size(); + if (sz >= minMatch && sz >= maxMatch) { + if (sz > maxMatch) { maxMatch = sz; best.clear(); } + if ((int) best.size() < maxNofMatches) best.push_back(cur); + else if (stopOnMax) Stop = true; + } + return; + } + for (int i2 = 1; i2 <= n2 && !Stop; ++i2) { // Option A: map g1[idx] + if (used2[i2] || !compatible(idx, i2)) continue; + cur.push_back({idx, i2}); used2[i2] = 1; + rec(idx + 1); + used2[i2] = 0; cur.pop_back(); + } + if (!Stop) rec(idx + 1); // Option B: skip g1[idx] + }; + rec(1); + + for (auto &m : best) { + Match mm; + for (auto &pr : m) { mm.f1.push_back(pr.first); mm.f2.push_back(pr.second); } + matches.push_back(std::move(mm)); + } +} + +inline void GraphMatch::GetMatch(int MatchNo, ivector &FV1, ivector &FV2, + int &nv, realtype &p1, realtype &p2) { + if (MatchNo < 0 || MatchNo >= (int) matches.size()) { FV1 = FV2 = nullptr; nv = 0; p1 = p2 = 0; return; } + if ((int) fv1.size() != (int) matches.size()) { fv1.resize(matches.size()); fv2.resize(matches.size()); } + Match &m = matches[MatchNo]; + nv = (int) m.f1.size(); + std::vector &a = fv1[MatchNo]; std::vector &b = fv2[MatchNo]; + a.assign(nv + 1, 0); b.assign(nv + 1, 0); // 1-indexed: [1..nv] valid + for (int i = 0; i < nv; ++i) { a[i + 1] = m.f1[i]; b[i + 1] = m.f2[i]; } + FV1 = a.data(); FV2 = b.data(); + p1 = p2 = (realtype) nv; +} + +// ---- MakeGraph from atoms (distance-based bonds) ------------------------- +inline int Graph::MakeGraph(PPAtom atom, int nAtoms) { + for (auto *p : V) delete p; for (auto *e : E) delete e; + V.clear(); E.clear(); adj.clear(); + if (nAtoms <= 0) return MKGRAPH_NoAtoms; + for (int i = 0; i < nAtoms; ++i) { + Vertex *v = new Vertex(atom[i]->GetElementName(), atom[i]->GetAtomName()); + v->user_id = i; // 0-based atom index for atom-table lookup + V.push_back(v); + } + // covalent-ish bonds by distance (< 1.9 A) — gemmi has no residue bond table + for (int i = 0; i < nAtoms; ++i) + for (int j = i + 1; j < nAtoms; ++j) { + double dx = atom[i]->x() - atom[j]->x(); + double dy = atom[i]->y() - atom[j]->y(); + double dz = atom[i]->z() - atom[j]->z(); + if (dx * dx + dy * dy + dz * dz < 1.9 * 1.9) + E.push_back(new Edge(i + 1, j + 1, BOND_SINGLE)); + } + return MKGRAPH_Ok; +} +inline int Graph::MakeGraph(PResidue R, cpstr /*altLoc*/) { + if (!R) return MKGRAPH_NoAtoms; + PPAtom a = nullptr; int n = 0; + R->GetAtomTable(a, n); + return MakeGraph(a, n); +} + +// ========================================================================= +// Alignment — global (Needleman-Wunsch) sequence alignment (mmdb_math_align.h). +// Coot uses it to align a model sequence to a target and read back the gapped +// strings + score (for mutation/indel detection). +// ========================================================================= +class Alignment { + public: + std::string _s, _t; // aligned (gapped) sequences + realtype VAchieved = 0; // alignment score + + void Align(cpstr S, cpstr T, realtype /*VGap*/ = 0.0, realtype VSpace = -1.0) { + std::string a(S ? S : ""), b(T ? T : ""); + int n = (int) a.size(), m = (int) b.size(); + const realtype MATCH = 1.0, MIS = 0.0, GAP = VSpace != 0.0 ? VSpace : -1.0; + std::vector> D(n + 1, std::vector(m + 1, 0.0)); + for (int i = 1; i <= n; ++i) D[i][0] = D[i - 1][0] + GAP; + for (int j = 1; j <= m; ++j) D[0][j] = D[0][j - 1] + GAP; + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= m; ++j) { + realtype diag = D[i - 1][j - 1] + (a[i - 1] == b[j - 1] ? MATCH : MIS); + realtype up = D[i - 1][j] + GAP, left = D[i][j - 1] + GAP; + D[i][j] = std::max(diag, std::max(up, left)); + } + VAchieved = D[n][m]; + std::string as, bs; // traceback + int i = n, j = m; + while (i > 0 || j > 0) { + if (i > 0 && j > 0 && + D[i][j] == D[i - 1][j - 1] + (a[i - 1] == b[j - 1] ? MATCH : MIS)) { + as += a[i - 1]; bs += b[j - 1]; --i; --j; + } else if (i > 0 && D[i][j] == D[i - 1][j] + GAP) { + as += a[i - 1]; bs += '-'; --i; + } else { + as += '-'; bs += b[j - 1]; --j; + } + } + std::reverse(as.begin(), as.end()); std::reverse(bs.begin(), bs.end()); + _s = as; _t = bs; + } + pstr GetAlignedS() { return (pstr) _s.c_str(); } + pstr GetAlignedT() { return (pstr) _t.c_str(); } + realtype GetScore() { return VAchieved; } +}; + +} // namespace math +} // namespace mmdb + +#endif // COOT_MMDB_SHIM_GRAPH_IMPL_HH diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh index 4f64061ce0..057a5ed938 100644 --- a/mmdb-shim/include/mmdb2/_shim_impl.hh +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -203,6 +203,10 @@ typedef LinkContainer *PLinkContainer; // gemmi Structure meta (raw_remarks / metadata). class Compound : public ContainerClass { public: char Line[256] = {0}; }; typedef Compound *PCompound; +class Author : public ContainerClass { public: char Line[256] = {0}; }; +typedef Author *PAuthor; +class Journal : public ContainerClass { public: char Line[256] = {0}; }; +typedef Journal *PJournal; class TitleContainer { public: std::vector data; @@ -213,9 +217,16 @@ public: }; class Title { public: - TitleContainer compound, author; // public so Coot's access_title can reach them + TitleContainer compound, author, journal; // public so Coot's access_title can reach them + TitleContainer *GetCompound() { return &compound; } // real Title exposes these + TitleContainer *GetAuthor() { return &author; } // publicly; access_title + TitleContainer *GetJournal() { return &journal; } // inherits GetJournal() }; +// gzip mode flag (mmdb_io_file.h). Minimal mmdb::io — the shim does I/O via gemmi, +// so only this compression-mode enum is provided (Coot passes it to write calls). +namespace io { enum GZ_MODE { GZM_NONE = 0, GZM_CHECK = 1, GZM_ENFORCE = 2 }; } + // Crystal/symmetry record (mmdb_cryst.h). Minimal — used by Coot as a pointer // type; symmetry math goes through Manager::GetTMatrix (gemmi TODO). class Cryst { public: @@ -236,16 +247,10 @@ inline void Mat4Init(mat44 &A) { for (int j = 0; j < 4; ++j) A[i][j] = (i == j) ? 1.0 : 0.0; } -// mmdb::math graph-matching subsystem — forward decls only for now (headers use -// Graph/GraphMatch/Edge by pointer/reference). Full gemmi-backed impl is a -// separate task; see coot/mmdb-graph-matching-for-gemmi.md. -namespace math { - class Graph; class GraphMatch; class Vertex; class Edge; class Alignment; - typedef Graph *PGraph; - typedef GraphMatch *PGraphMatch; - typedef Vertex *PVertex; typedef Vertex **PPVertex; - typedef Edge *PEdge; typedef Edge **PPEdge; -} +// mmdb::math graph-matching subsystem — full classes defined in _graph_impl.hh +// (included at end of this file, after Atom/Residue are complete). Only the +// Alignment class (unused by the cootapi build) stays a forward decl. +namespace math { class Alignment; } struct AtomBond { PAtom atom = nullptr; int order = 0; }; typedef AtomBond *PAtomBond; typedef AtomBond **PPAtomBond; @@ -386,6 +391,11 @@ public: void set_tempFactor(realtype v) { g().b_iso = (float)v; } void set_altLoc(char c) { g().altloc = c; } void SetCharge(realtype ch) { g().charge = (signed char) ch; } + // coordinate/occupancy/B ESDs (MMDB public fields) — gemmi has none, so shim- + // owned; reference-returning so the rewritten `->sigX` covers reads and writes. + float &sigX() { return _sigx; } float &sigY() { return _sigy; } + float &sigZ() { return _sigz; } float &sigOcc() { return _sigocc; } + float &sigTemp() { return _sigtemp; } bool isMetal() const { return gemmi::Element(g().element).is_metal(); } // anisotropic B tensor — gemmi's SMat33 aniso. Reference-returning so the // rewritten `->u11` covers both reads (bonds display) and writes (SHELX import). @@ -416,6 +426,11 @@ public: Chain *GetChain(); // out-of-line (needs complete Residue/Chain) Model *GetModel(); // out-of-line int GetModelNum(); + // residue-delegating accessors (bound by the Python API); out-of-line. + pstr GetLabelCompID(); pstr GetLabelAsymID(); + int GetLabelSeqID(); int GetLabelEntityID(); + int GetResidueNo(); int GetSSEType(); + bool isSolvent(); bool isNTerminus(); bool isCTerminus(); bool isTer() const { return false; } // gemmi has no TER atoms; see notes void SetCoordinates(realtype xx, realtype yy, realtype zz, realtype occ, realtype tF); @@ -452,6 +467,7 @@ public: private: friend class Residue; // AddAtom pushes the strncpy'd altLoc buffer to gemmi mutable AtomName _name_buf{}; Element _elem_buf{}; mutable char _altloc_buf[4]{}; + float _sigx = 0, _sigy = 0, _sigz = 0, _sigocc = 0, _sigtemp = 0; }; // =========================================================================== @@ -467,7 +483,18 @@ public: int nAtoms = 0; // MMDB public field; kept = atoms.size() void _sync_atom() { atom = atoms.data(); nAtoms = (int)atoms.size(); } // mmcif label_* (shim-owned; Coot sets when building dictionary residues) - ResName label_comp_id{}; ChainID label_asym_id{}; int label_seq_id = 0; + ResName label_comp_id{}; ChainID label_asym_id{}; int label_seq_id = 0, label_entity_id = 0; + pstr GetLabelCompID() { return label_comp_id; } + pstr GetLabelAsymID() { return label_asym_id; } + int GetLabelSeqID() { return label_seq_id; } + int GetLabelEntityID() { return label_entity_id; } + int GetResidueNo() { return ri; } // 0-based index within its chain + int GetNofAltLocations() { // distinct non-blank altLocs + std::set a; for (Atom *at : atoms) { char c = at->g().altloc; if (c && c != ' ') a.insert(c); } + return a.empty() ? 1 : (int) a.size(); + } + bool isSugar() { return false; } // TODO: gemmi residue classification + bool isModRes() { return false; } // TODO Residue() = default; explicit Residue(Chain *c); // construct + add to chain (out-of-line) @@ -531,7 +558,7 @@ public: int GetModelNum(); int &GetIndex() { return ri; } // ref: rewritten `->index` is assignable Chain *GetChain() { return chain; } - Model *GetModel() { return chain ? chain->model : nullptr; } + Model *GetModel(); // out-of-line (Chain incomplete here) // terminus tests — positional within the chain (approximates MMDB's peptide-bond // check; good enough for Coot's terminal-residue handling). TODO: bond-aware. bool isNTerminus() { return chain && ri == 0; } @@ -598,6 +625,7 @@ public: } pstr GetChainID(); pstr GetChainID(pstr buf) { if (buf) std::snprintf(buf, sizeof(ChainID), "%s", g().name.c_str()); return buf; } + Manager *GetCoordHierarchy() { return mgr; } // parent manager void SetChainID(const ChainID id) { g().name = id ? id : ""; } Chain() = default; Chain(Model *m, const ChainID id); // construct + add to model (out-of-line) @@ -911,6 +939,11 @@ public: // --- misc hierarchy/bond/UDData ops used by Coot --- void RemoveBonds() {} // gemmi has no persistent bond table void Delete(int /*DelKey*/) {} // partial-hierarchy delete — no-op (TODO) + void DeleteAllModels() { st.models.clear(); build_from_gemmi(); } // clears the hierarchy + void DeleteModel(int modelNo) { // 1-based; erase model + rebuild wrappers + int i = modelNo - 1; + if (i >= 0 && i < (int)st.models.size()) { st.models.erase(st.models.begin() + i); build_from_gemmi(); } + } pstr GetInputBuffer(pstr buf, int &count) { count = 0; if (buf) buf[0] = '\0'; return buf; } // place an atom into the flat table (mmdb Manager::PutAtom) — the shim builds // hierarchy via Add*/gemmi, so this is a stub returning the index. TODO if a @@ -1076,6 +1109,15 @@ inline pstr Atom::GetChainID() { return res->GetChainID(); } inline int Atom::GetSeqNum() { return res->GetSeqNum(); } inline Chain *Atom::GetChain() { return res ? res->GetChain() : nullptr; } inline Model *Atom::GetModel() { return res ? res->chain->model : nullptr; } +inline pstr Atom::GetLabelCompID() { return res ? res->GetLabelCompID() : nullptr; } +inline pstr Atom::GetLabelAsymID() { return res ? res->GetLabelAsymID() : nullptr; } +inline int Atom::GetLabelSeqID() { return res ? res->GetLabelSeqID() : 0; } +inline int Atom::GetLabelEntityID() { return res ? res->GetLabelEntityID() : 0; } +inline int Atom::GetResidueNo() { return res ? res->GetResidueNo() : 0; } +inline int Atom::GetSSEType() { return res ? res->SSE : SSE_None; } +inline bool Atom::isSolvent() { return res ? res->isSolvent() : false; } +inline bool Atom::isNTerminus() { return res ? res->isNTerminus() : false; } +inline bool Atom::isCTerminus() { return res ? res->isCTerminus() : false; } inline pstr Atom::GetInsCode() { return res->GetInsCode(); } inline pstr Atom::GetResName() { return res->GetResName(); } inline int Atom::GetModelNum() { return res->GetModelNum(); } @@ -1403,6 +1445,7 @@ inline Chain::Chain(Model *m, const ChainID id) { if (m) m->AddChain(this); SetC inline bool Residue::isCTerminus() { return chain && ri == (int)chain->residues.size() - 1; } +inline Model *Residue::GetModel() { return chain ? chain->model : nullptr; } inline void Chain::Copy(PChain src) { Manager *pool = mgr ? mgr : src->mgr; @@ -1483,3 +1526,7 @@ inline void GetMassCenter(PPAtom A, int nA, realtype &xc, realtype &yc, realtype // mmdb::mmcif::* (thin veneer over gemmi::cif) — re-opens mmdb{mmcif{...}}. // pstr/cpstr/realtype are already in scope from the headers above. #include "_mmcif_impl.hh" + +// mmdb::math::{Vertex,Edge,Graph,GraphMatch} — molecular graph + subgraph match. +// Included after the mmdb namespace close so Atom/Residue are complete (MakeGraph). +#include "_graph_impl.hh" diff --git a/mmdb-shim/include/ssm/ssm_align.h b/mmdb-shim/include/ssm/ssm_align.h new file mode 100644 index 0000000000..eda5542195 --- /dev/null +++ b/mmdb-shim/include/ssm/ssm_align.h @@ -0,0 +1,72 @@ +// -*- mode: c++; -*- +// +// mmdb-shim: no-op replacement for . +// +// The real SSM library (libssm) is a precompiled binary built against REAL MMDB +// 2.0.22, and its headers derive from mmdb::io::Stream / use mmdb binary +// serialization (DefineClass, io::RFile) that the gemmi-backed shim does not +// provide. Worse, even if the headers parsed, passing shim mmdb objects (thin +// gemmi wrappers) into precompiled ssm would be an ABI mismatch -> crash. +// +// Per the project decision to NOT build SSM code against the shim (SSM is being +// removed/replaced), this header shadows the real ssm/ssm_align.h (the shim +// include dir precedes ssm's on the -I path) with a self-contained, header-only, +// no-op ssm::Align. Everything compiles and links (no real libssm symbols are +// referenced); SSM structural superposition simply reports "no match" (identity +// transform), so callers take their no-alignment path. +// +// Copyright 2026 by Medical Research Council Laboratory of Molecular Biology +#ifndef COOT_MMDB_SHIM_SSM_ALIGN_H +#define COOT_MMDB_SHIM_SSM_ALIGN_H + +#include // mmdb::mat44/realtype/ivector/rvector/PManager (shim) + +namespace ssm { + +// return codes (ssm_defs.h RETURN_CODE) +enum RETURN_CODE { RC_Ok, RC_NoHits, RC_NoSuperposition, RC_NoGraph, + RC_NoVertices, RC_NoGraph2, RC_NoVertices2, RC_TooFewMatches }; +// precision levels (ssm_defs.h PRECISION) +enum PRECISION { PREC_Highest, PREC_High, PREC_Normal, PREC_Low, PREC_Lowest }; +// connectivity check modes (ssm_defs.h CONNECTIVITY) +enum CONNECTIVITY { CONNECT_None, CONNECT_Flexible, CONNECT_Strict }; + +// global tuning knobs (ssm_vxedge.h) — no-ops in the shim +inline void SetMatchPrecision(PRECISION) {} +inline void SetConnectivityCheck(CONNECTIVITY) {} + +// SSM structure alignment result + driver. Public fields mirror ssm::Align so +// Coot's superpose code compiles; all methods are inert. +class Align { + public: + mmdb::mat44 TMatrix; // superposition matrix (identity => no move) + mmdb::realtype rmsd = 0, Qscore = 0, ncombs = 0, seqIdentity = 0; + int cnCheck = 0; + int nres1 = 0, nres2 = 0; // residues in each structure + int nsel1 = 0, nsel2 = 0; // residues in aligned selections + int nalgn = 0, ngaps = 0, nmd = 0; + int selHndCa1 = 0, selHndCa2 = 0; + mmdb::ivector Ca1 = nullptr, Ca2 = nullptr; // C-alpha correspondence vectors + mmdb::rvector dist1 = nullptr; // optimised C-alpha distances + + Align() { + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 4; ++j) TMatrix[i][j] = (i == j) ? 1.0 : 0.0; + } + ~Align() {} + + // no-op alignment: report "no hits" with an identity transform and zero counts, + // so callers skip the Ca1/Ca2 correspondence loops (bounded by nsel*/nalgn == 0). + int align(mmdb::PManager, mmdb::PManager, PRECISION, CONNECTIVITY, + int /*selHnd1*/ = 0, int /*selHnd2*/ = 0) { return RC_NoHits; } + int AlignSelectedMatch(mmdb::PManager, mmdb::PManager, PRECISION, CONNECTIVITY, + int /*selHnd1*/ = 0, int /*selHnd2*/ = 0, int /*nselect*/ = 0) { + return RC_NoHits; + } + int GetNMatches() const { return 0; } +}; +typedef Align *PAlign; + +} // namespace ssm + +#endif // COOT_MMDB_SHIM_SSM_ALIGN_H From eaeee7a1d4b6780d9757fd93b937b46e5113b4c4 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Wed, 22 Jul 2026 10:07:55 +0100 Subject: [PATCH 07/23] Updated stubbed functions and formatted implementations --- mmdb-shim/include/mmdb2/_graph_impl.hh | 11 +- mmdb-shim/include/mmdb2/_shim_impl.hh | 530 +++++++++++++++++++++---- mmdb-shim/src/contacts.cc | 63 ++- mmdb-shim/src/io.cc | 10 +- 4 files changed, 521 insertions(+), 93 deletions(-) diff --git a/mmdb-shim/include/mmdb2/_graph_impl.hh b/mmdb-shim/include/mmdb2/_graph_impl.hh index b4edbeab48..1815c14096 100644 --- a/mmdb-shim/include/mmdb2/_graph_impl.hh +++ b/mmdb-shim/include/mmdb2/_graph_impl.hh @@ -299,7 +299,16 @@ inline int Graph::MakeGraph(PResidue R, cpstr /*altLoc*/) { // ========================================================================= // Alignment — global (Needleman-Wunsch) sequence alignment (mmdb_math_align.h). // Coot uses it to align a model sequence to a target and read back the gapped -// strings + score (for mutation/indel detection). +// strings + score (for mutation/indel detection, api/coot-molecule.cc). +// +// NOTE on prefer-gemmi: gemmi DOES provide sequence alignment (align.hpp / +// seqalign.hpp), but only over a substitution-scoring matrix. MMDB's aligner — +// which Coot's mutation detection was tuned against — uses simple identity +// scoring (match=1 / mismatch=0 / linear gap). Swapping in gemmi's scorer would +// change which residues are called mutations vs. indels, i.e. it would NOT +// reproduce the MMDB baseline this shim exists to preserve. So this stays a +// faithful re-creation of MMDB's *specific* simple-scoring global aligner — +// the exact form gemmi does not offer — rather than a gratuitous reimplementation. // ========================================================================= class Alignment { public: diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh index 057a5ed938..5bac6a7b6c 100644 --- a/mmdb-shim/include/mmdb2/_shim_impl.hh +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -137,8 +137,8 @@ class ContainerClass { public: virtual ~ContainerClass() {} }; typedef ContainerClass *PContainerClass; // LINK record. Public data members mirror real MMDB (Coot reads them directly). -// Not gemmi-backed yet — Model::GetNumberOfLinks currently returns 0 (TODO: map -// gemmi Structure connections), so these are declared for compilation. +// Populated from gemmi Structure::connections on load (Manager::_load_metadata); +// Coot-created links are appended via Model::AddLink. class Link : public ContainerClass { public: AtomName atName1{}, atName2{}; @@ -155,7 +155,7 @@ public: typedef Link *PLink; typedef Link **PPLink; // Refmac LINK record (mmdb_model.h LinkR). Public members mirror real MMDB; -// Model::GetNumberOfLinkRs returns 0 for now (TODO: map gemmi connections). +// populated from gemmi Connections carrying a link_id (Manager::_load_metadata). class LinkR { public: LinkRID linkRID{}; @@ -170,7 +170,7 @@ public: typedef LinkR *PLinkR; typedef LinkR **PPLinkR; // CIS-peptide record (mmdb_model.h CisPep). Public members mirror real MMDB; -// Model::GetNumberOfCisPeps returns 0 for now (TODO: map gemmi cispeps). +// populated from gemmi Structure::cispeps on load (Manager::_load_metadata). class CisPep { public: int serNum = 0; @@ -198,9 +198,10 @@ public: typedef LinkContainer *PLinkContainer; // PDB title records (mmdb_title.h). Coot subclasses Manager & Title to reach the -// COMPND/AUTHOR line containers. Not gemmi-backed yet (title/header records are -// dropped on round-trip) — just enough surface to compile & run. TODO: map to -// gemmi Structure meta (raw_remarks / metadata). +// COMPND/AUTHOR line containers. The AUTHOR container is filled from gemmi +// meta.authors on load and the TITLE string comes from Structure::get_info +// ("_struct.title"); COMPND/JRNL have no structured gemmi home, so those +// containers stay empty. class Compound : public ContainerClass { public: char Line[256] = {0}; }; typedef Compound *PCompound; class Author : public ContainerClass { public: char Line[256] = {0}; }; @@ -227,26 +228,63 @@ public: // so only this compression-mode enum is provided (Coot passes it to write calls). namespace io { enum GZ_MODE { GZM_NONE = 0, GZM_CHECK = 1, GZM_ENFORCE = 2 }; } -// Crystal/symmetry record (mmdb_cryst.h). Minimal — used by Coot as a pointer -// type; symmetry math goes through Manager::GetTMatrix (gemmi TODO). +// initialise a 4x4 matrix to identity (mmdb_mattype.h Mat4Init) +inline void Mat4Init(mat44 &A) { + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 4; ++j) A[i][j] = (i == j) ? 1.0 : 0.0; +} + +// Orthogonal symmetry transformation for operator Nop (0-based) + integer cell +// shifts, from a gemmi cell + space group. The op acts in fractional space; we +// conjugate it with the cell frac<->orth transforms so TMatrix maps orthogonal +// coordinates directly (MMDB semantics). Returns 0 on success, 1 if there is no +// usable space group / the operator is out of range. Shared by Manager and Cryst. +inline int gemmi_sym_tmatrix(const gemmi::UnitCell &cell, const std::string &sg_name, + mat44 &TMatrix, int Nop, int a, int b, int c) { + Mat4Init(TMatrix); + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(sg_name); + if (!sg || !cell.is_crystal()) return 1; + gemmi::GroupOps gops = sg->operations(); + if (Nop < 0 || Nop >= (int) gops.order()) return 1; + int i = 0; gemmi::Op op; + for (gemmi::Op o : gops) { if (i++ == Nop) { op = o; break; } } + gemmi::Transform sym{ gemmi::rot_as_mat33(op), + gemmi::tran_as_vec3(op) + gemmi::Vec3(a, b, c) }; + gemmi::Transform t = cell.orth.combine(sym).combine(cell.frac); + for (int r = 0; r < 3; ++r) { + for (int cc = 0; cc < 3; ++cc) TMatrix[r][cc] = t.mat.a[r][cc]; + TMatrix[r][3] = t.vec.at(r); + } + return 0; +} + +// Crystal/symmetry record (mmdb_cryst.h). Holds a gemmi cell + space-group name +// and computes symmetry through the shared helper — same result as Manager for a +// populated Cryst (Manager is the usual live symmetry path). class Cryst { public: + gemmi::UnitCell cell; + std::string spaceGroup; virtual ~Cryst() {} - // symmetry not carried on the bare Cryst (Manager owns gemmi cell/SG) — identity/0. int GetTMatrix(mat44 &T, int Nop, int a, int b, int c) { - for (int i=0;i<4;i++) for (int j=0;j<4;j++) T[i][j]=(i==j)?1.0:0.0; - return (Nop==0 && a==0 && b==0 && c==0) ? 0 : 1; + return gemmi_sym_tmatrix(cell, spaceGroup, T, Nop, a, b, c); } - int GetNumberOfSymOps() { return 0; } - pstr GetSymOp(int) { return nullptr; } + int GetNumberOfSymOps() { + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(spaceGroup); + return sg ? (int) sg->operations().order() : 0; + } + pstr GetSymOp(int Nop) { + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(spaceGroup); + if (!sg) return nullptr; + int i = 0; + for (gemmi::Op op : sg->operations()) + if (i++ == Nop) { _symop_buf = op.triplet(); return (pstr) _symop_buf.c_str(); } + return nullptr; + } +private: + std::string _symop_buf; }; typedef Cryst *PCryst; -// initialise a 4x4 matrix to identity (mmdb_mattype.h Mat4Init) -inline void Mat4Init(mat44 &A) { - for (int i = 0; i < 4; ++i) - for (int j = 0; j < 4; ++j) A[i][j] = (i == j) ? 1.0 : 0.0; -} - // mmdb::math graph-matching subsystem — full classes defined in _graph_impl.hh // (included at end of this file, after Atom/Residue are complete). Only the // Alignment class (unused by the cootapi build) stays a forward decl. @@ -291,9 +329,9 @@ enum PDB_CLEAN_FLAG { PDBCLEAN_ELEMENT_STRONG = 0x00002000 }; -// SS records — minimal public-member structs. Model::GetNumberOf{Helices,Sheets} -// return 0 for now (TODO: map gemmi Structure helices/sheets), so these aren't -// dereferenced; fields present for compilation. +// SS records — public-member structs. Model::GetNumberOf{Helices,Sheets} are +// populated from gemmi Structure::{helices,sheets} on load (_load_metadata) and +// also fillable by Coot's own SS computation via the access_model subclass. class Helix { public: ChainID initChainID{}, endChainID{}; int initSeqNum = 0, endSeqNum = 0, serNum = 0, helixClass = 0, length = 0; ResName initResName{}, endResName{}; InsCode initICode{}, endICode{}; char helixID[20]{}, comment[80]{}; @@ -303,7 +341,7 @@ class Strand { public: ResName initResName{}, endResName{}; InsCode initICode{}, endICode{}; char sheetID[20]{}; }; class Sheet { public: int nStrands = 0; Strand **strand = nullptr; char sheetID[20]{}; }; -class Sheets { public: int nSheets = 0; Sheet **sheet = nullptr; }; // container (SS TODO) +class Sheets { public: int nSheets = 0; Sheet **sheet = nullptr; }; // filled from gemmi in _load_metadata typedef Helix *PHelix; typedef Strand *PStrand; typedef Sheet *PSheet; typedef Sheets *PSheets; // container of helices (Model.helices); Coot's access_model subclass fills it. class Helices { public: std::vector data; void AddData(PHelix h) { if (h) data.push_back(h); } int nHelices = 0; }; @@ -398,14 +436,19 @@ public: float &sigTemp() { return _sigtemp; } bool isMetal() const { return gemmi::Element(g().element).is_metal(); } // anisotropic B tensor — gemmi's SMat33 aniso. Reference-returning so the - // rewritten `->u11` covers both reads (bonds display) and writes (SHELX import). - // NOTE: writing here does not set ASET_Anis_tFac in WhatIsSet (TODO if needed). - float &u11() { return g().aniso.u11; } - float &u22() { return g().aniso.u22; } - float &u33() { return g().aniso.u33; } - float &u12() { return g().aniso.u12; } - float &u13() { return g().aniso.u13; } - float &u23() { return g().aniso.u23; } + // rewritten `->u11` covers both reads and writes. The mutable accessor marks the + // tensor present (ASET_Anis_tFac) so a write (e.g. SHELX import) sets the flag as + // real MMDB does. Const reads never set it; a non-const read over-approximates, + // which is harmless — the PDB/mmCIF writer emits ANISOU on the actual values. + float &u11() { WhatIsSet |= ASET_Anis_tFac; return g().aniso.u11; } + float &u22() { WhatIsSet |= ASET_Anis_tFac; return g().aniso.u22; } + float &u33() { WhatIsSet |= ASET_Anis_tFac; return g().aniso.u33; } + float &u12() { WhatIsSet |= ASET_Anis_tFac; return g().aniso.u12; } + float &u13() { WhatIsSet |= ASET_Anis_tFac; return g().aniso.u13; } + float &u23() { WhatIsSet |= ASET_Anis_tFac; return g().aniso.u23; } + float u11() const { return g().aniso.u11; } float u22() const { return g().aniso.u22; } + float u33() const { return g().aniso.u33; } float u12() const { return g().aniso.u12; } + float u13() const { return g().aniso.u13; } float u23() const { return g().aniso.u23; } // bonds — not modelled yet (gemmi connections); report none. int GetNBonds() { return 0; } void GetBonds(PAtomBond &atomBond, int &n) { atomBond = nullptr; n = 0; } @@ -493,8 +536,20 @@ public: std::set a; for (Atom *at : atoms) { char c = at->g().altloc; if (c && c != ' ') a.insert(c); } return a.empty() ? 1 : (int) a.size(); } - bool isSugar() { return false; } // TODO: gemmi residue classification - bool isModRes() { return false; } // TODO + // sugar / modified-residue classification via gemmi's tabulated residues. + bool isSugar() { + gemmi::ResidueKind k = gemmi::find_tabulated_residue(g().name).kind; + return k == gemmi::ResidueKind::PYR || k == gemmi::ResidueKind::KET; + } + // MMDB isModRes reflects PDB MODRES records (a non-standard, modified form of a + // standard residue). gemmi has no per-residue MODRES flag on the model tree, so + // approximate: an amino/nucleic residue whose one-letter code is lower-case + // (gemmi marks non-standard monomers that way). Water/ligands are excluded. + bool isModRes() { + const gemmi::ResidueInfo ri = gemmi::find_tabulated_residue(g().name); + return ri.found() && !ri.is_standard() && + (ri.is_amino_acid() || ri.is_nucleic_acid()); + } Residue() = default; explicit Residue(Chain *c); // construct + add to chain (out-of-line) @@ -559,10 +614,11 @@ public: int &GetIndex() { return ri; } // ref: rewritten `->index` is assignable Chain *GetChain() { return chain; } Model *GetModel(); // out-of-line (Chain incomplete here) - // terminus tests — positional within the chain (approximates MMDB's peptide-bond - // check; good enough for Coot's terminal-residue handling). TODO: bond-aware. - bool isNTerminus() { return chain && ri == 0; } - bool isCTerminus(); // last in chain (out-of-line: needs Chain) + // terminus tests — peptide-bond-aware: N-terminus if no preceding residue's C is + // within bonding distance of this N, C-terminus if this C bonds no following N + // (out-of-line: need Chain + backbone atom geometry). + bool isNTerminus(); + bool isCTerminus(); pstr GetResidueID(pstr S) { // "seqnum(name):inscode" if (S) std::snprintf(S, 100, "%d(%s):%s", GetSeqNum(), name, insCode); return S; @@ -630,7 +686,29 @@ public: Chain() = default; Chain(Model *m, const ChainID id); // construct + add to model (out-of-line) void Copy(PChain src); // deep-copy subtree (out-of-line: needs Manager) - void SortResidues(int /*sortKey*/ = 0) {} // gemmi keeps file order; no-op + // Reorder residues (and their gemmi backing) ascending by (seqNum, insCode), + // MMDB's default. Keeps the wrapper vector and gemmi vector in lock-step and + // re-indexes ri. sortKey variants beyond ascending-by-number are uncommon in + // Coot and treated as the default. + void SortResidues(int /*sortKey*/ = 0) { + int n = (int)residues.size(); + if (n < 2) return; + std::vector ord(n); + for (int i = 0; i < n; ++i) ord[i] = i; + gemmi::Chain &gc = g(); + std::stable_sort(ord.begin(), ord.end(), [&](int a, int b) { + const gemmi::Residue &ra = gc.residues[a], &rb = gc.residues[b]; + if (ra.seqid.num.value != rb.seqid.num.value) return ra.seqid.num.value < rb.seqid.num.value; + char ia = ra.seqid.icode ? ra.seqid.icode : ' ', ib = rb.seqid.icode ? rb.seqid.icode : ' '; + return ia < ib; + }); + std::vector gnew; gnew.reserve(n); + std::vector wnew; wnew.reserve(n); + for (int k = 0; k < n; ++k) { gnew.push_back(std::move(gc.residues[ord[k]])); wnew.push_back(residues[ord[k]]); } + gc.residues = std::move(gnew); + residues = std::move(wnew); + for (int k = 0; k < n; ++k) residues[k]->ri = k; + } bool isAminoacidChain(); // defined out-of-line (needs Residue predicates) bool isNucleotideChain(); bool isSolventChain(); @@ -705,31 +783,42 @@ public: PPAtom GetAllAtoms() { return all_atoms.data(); } int GetNumberOfAtoms() { return (int)all_atoms.size(); } int GetNumberOfAtoms(bool /*countTers*/) { return (int)all_atoms.size(); } - int CalcSecStructure(bool /*flag*/) { return 0; } // TODO: gemmi SS assignment - // LINK records — Coot-owned Link* objects stored here (AddLink); GetLink is - // 1-based like MMDB. (Reading from gemmi connections is a separate TODO.) + // Secondary-structure assignment: mocked. gemmi's DSSP has its SS prediction + // disabled upstream ("commented out ... wasn't correct anyway"), so there is no + // gemmi-backed SS to forward to. Return the non-OK code so callers treat SS as + // unavailable rather than trusting a bogus assignment. (residue SSE stays None.) + int CalcSecStructure(bool /*flag*/) { return SSERC_noResidues; } + // LINK records — gemmi-loaded (Manager::_load_metadata) plus Coot-created ones + // (AddLink) stored here; GetLink is 1-based like MMDB. std::vector _links; int GetNumberOfLinks() { return (int)_links.size(); } PLink GetLink(int i) { return (i >= 1 && i <= (int)_links.size()) ? _links[i - 1] : nullptr; } void AddLink(PLink link) { if (link) _links.push_back(link); } - int GetNumberOfLinkRs() { return 0; } - PLinkR GetLinkR(int /*i*/) { return nullptr; } + // Refmac LINKR records — gemmi Connections that carry a link_id (_load_metadata). + std::vector _linkrs; + int GetNumberOfLinkRs() { return (int)_linkrs.size(); } + PLinkR GetLinkR(int i) { return (i >= 1 && i <= (int)_linkrs.size()) ? _linkrs[i - 1] : nullptr; } + void AddLinkR(PLinkR lr) { if (lr) _linkrs.push_back(lr); } std::vector _cispeps; int GetNumberOfCisPeps() { return (int)_cispeps.size(); } PCisPep GetCisPep(int i) { return (i >= 1 && i <= (int)_cispeps.size()) ? _cispeps[i - 1] : nullptr; } void AddCisPep(PCisPep cp) { if (cp) _cispeps.push_back(cp); } void RemoveCisPeps() { _cispeps.clear(); } - // secondary structure — TODO: map from gemmi helices/sheets. - int GetNumberOfHelices() { return 0; } - PHelix GetHelix(int /*i*/) { return nullptr; } - int GetNumberOfSheets() { return 0; } - PSheet GetSheet(int /*i*/) { return nullptr; } - Sheets sheets; // SS records (not gemmi-backed; access_model fills) + // secondary structure. Records live in `helices`/`sheets` below, populated + // either from gemmi on load (build_from_gemmi) or by Coot's own SS computation + // via the access_model subclass (which reaches these public members directly). + // 1-based indexing to match MMDB. + int GetNumberOfHelices() { return (int)helices.data.size(); } + PHelix GetHelix(int i) { return (i >= 1 && i <= (int)helices.data.size()) ? helices.data[i - 1] : nullptr; } + int GetNumberOfSheets() { return sheets.nSheets; } + PSheet GetSheet(int i) { return (i >= 1 && i <= sheets.nSheets && sheets.sheet) ? sheets.sheet[i - 1] : nullptr; } + Sheets sheets; // SS records (gemmi-backed on load; access_model fills) Helices helices; // " " " + std::vector _sheet_ptrs; // backing array for sheets.sheet (gemmi load) PSheets GetSheets() { return &sheets; } int GetModelID() { return mi + 1; } pstr GetModelID(pstr buf) { if (buf) std::snprintf(buf, 16, "%d", mi + 1); return buf; } - int CalcSecStructure(int /*flag*/, int /*selHnd*/) { return SSERC_Ok; } // TODO gemmi SS + int CalcSecStructure(int /*flag*/, int /*selHnd*/) { return SSERC_noResidues; } // mocked; see bool overload void Copy(PModel src); // deep-copy subtree (out-of-line) Manager *GetCoordHierarchy() { return mgr; } // parent manager int GetNumberOfResidues() { @@ -740,10 +829,34 @@ public: _linkc.data.assign(_links.begin(), _links.end()); return &_linkc; } void RemoveLinks() { _links.clear(); } - void SortChains(int /*sortKey*/ = 0) {} // gemmi keeps file order; no-op + // Reorder chains (and gemmi backing) by chain ID. sortKey selects ascending + // (default) or descending; other MMDB sort keys collapse to ID order. + void SortChains(int sortKey = 0) { + int n = (int)chains.size(); + if (n < 2) return; + bool desc = (sortKey == SORT_CHAIN_ChainID_Desc); + std::vector ord(n); + for (int i = 0; i < n; ++i) ord[i] = i; + gemmi::Model &gm = g(); + std::stable_sort(ord.begin(), ord.end(), [&](int a, int b) { + return desc ? (gm.chains[a].name > gm.chains[b].name) + : (gm.chains[a].name < gm.chains[b].name); + }); + std::vector gnew; gnew.reserve(n); + std::vector wnew; wnew.reserve(n); + for (int k = 0; k < n; ++k) { gnew.push_back(std::move(gm.chains[ord[k]])); wnew.push_back(chains[ord[k]]); } + gm.chains = std::move(gnew); + chains = std::move(wnew); + for (int k = 0; k < n; ++k) chains[k]->ci = k; + } PChain CreateChain(const ChainID id); // add empty chain (out-of-line: needs Manager) - int GetNumberOfStrands(int /*sheetNo*/) { return 0; } - PStrand GetStrand(int /*sheetNo*/, int /*strandNo*/) { return nullptr; } + int GetNumberOfStrands(int sheetNo) { + PSheet s = GetSheet(sheetNo); return s ? s->nStrands : 0; + } + PStrand GetStrand(int sheetNo, int strandNo) { + PSheet s = GetSheet(sheetNo); + return (s && strandNo >= 1 && strandNo <= s->nStrands && s->strand) ? s->strand[strandNo - 1] : nullptr; + } }; // =========================================================================== @@ -756,6 +869,18 @@ public: std::deque chain_pool; std::deque model_pool; std::vector models; + // stable-address pools for gemmi-derived metadata records (LINK / CISPEP / + // HELIX / SHEET). Filled by build_from_gemmi -> _load_metadata(); owned here so + // the Model containers can hold bare pointers into them. + std::deque link_pool; + std::deque linkr_pool; + std::deque cispep_pool; + std::deque helix_pool; + std::deque sheet_pool; + std::deque strand_pool; + std::deque> strandarr_pool; // backing for Sheet::strand (Strand**) + std::deque author_pool; // backing for title.author records + void _load_metadata(); // out-of-line: needs complete gemmi metadata types Atom *newAtom() { atom_pool.emplace_back(); return &atom_pool.back(); } Residue *newRes() { res_pool.emplace_back(); return &res_pool.back(); } @@ -774,20 +899,31 @@ public: PChain GetChain(int modelNo, int chainNo) { PModel m = GetModel(modelNo); return m ? m->GetChain(chainNo) : nullptr; } - // Re-index/renumber after edits. The shim keeps sibling indices in sync as it - // mutates, so this is a no-op re-validation for now (TODO: serial renumbering). - word PDBCleanup(word /*CleanKey*/) { return 0; } + // Re-index/renumber after edits. Sibling indices are kept in sync as the shim + // mutates (so PDBCLEAN_INDEX is implicit); PDBCLEAN_SERIAL renumbers atom serials + // 1..N in hierarchy order. Other clean flags are not needed by the shim. + word PDBCleanup(word CleanKey) { + if (CleanKey & (PDBCLEAN_SERIAL | PDBCLEAN_INDEX)) { + int s = 1; + for (Atom *a : all_atoms) a->g().serial = s++; + } + return 0; + } - // PDB title records — Coot reaches `title` via an access_mol subclass. + // PDB title records — Coot reaches `title` via an access_mol subclass; the + // TITLE string comes from gemmi (_struct.title), authors are filled on load. Title title; - pstr GetStructureTitle(pstr T) { if (T) T[0] = '\0'; return T; } + pstr GetStructureTitle(pstr T) { + if (T) std::strcpy(T, st.get_info("_struct.title").c_str()); // caller allocates (MMDB contract) + return T; + } - // symmetry transformation matrix. Real symmetry needs gemmi spacegroup/cell; - // for now return identity for the no-op (Nop==0, no cell shift) and signal - // "no symmetry" (nonzero) otherwise so Coot skips symmetry expansion. TODO. + // Orthogonal symmetry transformation for operator Nop (0-based) + cell shifts, + // via gemmi's space group + unit cell (shared helper). Returns 0 on success, + // nonzero if there is no usable space group / the operator is out of range. int GetTMatrix(mat44 &TMatrix, int Nop, int cellshift_a, int cellshift_b, int cellshift_c) { - Mat4Init(TMatrix); - return (Nop == 0 && cellshift_a == 0 && cellshift_b == 0 && cellshift_c == 0) ? 0 : 1; + return gemmi_sym_tmatrix(st.cell, st.spacegroup_hm, TMatrix, Nop, + cellshift_a, cellshift_b, cellshift_c); } void build_from_gemmi(); @@ -854,6 +990,7 @@ public: SELECTION_TYPE type = STYPE_UNDEFINED; std::vector atoms; std::vector residues; + std::vector chains; }; std::vector selections; // handle is 1-based index @@ -863,6 +1000,7 @@ public: Selection &s = selections[selHnd - 1]; for (Atom *a : s.atoms) a->_setInSel(selHnd, false); for (Residue *r : s.residues) r->_setInSel(selHnd, false); + for (Chain *c : s.chains) c->_setInSel(selHnd, false); s = Selection(); } void GetSelIndex(int selHnd, PPAtom &SelAtom, int &n) { @@ -871,8 +1009,9 @@ public: void GetSelIndex(int selHnd, PPResidue &SelRes, int &n) { Selection &s = selections[selHnd - 1]; SelRes = s.residues.data(); n = (int)s.residues.size(); } - // chain selections aren't modelled by the engine yet — return empty. TODO. - void GetSelIndex(int /*selHnd*/, PPChain &SelChain, int &n) { SelChain = nullptr; n = 0; } + void GetSelIndex(int selHnd, PPChain &SelChain, int &n) { + Selection &s = selections[selHnd - 1]; SelChain = s.chains.data(); n = (int)s.chains.size(); + } // select atoms by serial-number range (iSer1..iSer2; 0,0 => all). void SelectAtoms(int selHnd, int iSer1, int iSer2, SELECTION_KEY key) { if (selHnd < 1 || selHnd > (int)selections.size()) return; @@ -938,17 +1077,37 @@ public: // --- misc hierarchy/bond/UDData ops used by Coot --- void RemoveBonds() {} // gemmi has no persistent bond table - void Delete(int /*DelKey*/) {} // partial-hierarchy delete — no-op (TODO) + // Partial-hierarchy delete (mmdb Manager::Delete). Coot's use is + // Delete(MMDBFCM_SC) to drop secondary-structure/connectivity records before + // writing; also honour Coord (atoms) and Cryst (cell/SG) for completeness. + void Delete(int DelKey) { + bool all = DelKey == MMDBFCM_All; + if (all || (DelKey & MMDBFCM_SC)) { + for (Model *m : models) { + m->_links.clear(); m->_linkrs.clear(); m->_cispeps.clear(); + m->helices.data.clear(); + m->sheets.nSheets = 0; m->sheets.sheet = nullptr; m->_sheet_ptrs.clear(); + } + link_pool.clear(); linkr_pool.clear(); cispep_pool.clear(); + helix_pool.clear(); sheet_pool.clear(); strand_pool.clear(); strandarr_pool.clear(); + } + if (all || (DelKey & MMDBFCM_Cryst)) { st.cell = gemmi::UnitCell(); st.spacegroup_hm.clear(); } + if (all || (DelKey & MMDBFCM_Coord)) { st.models.clear(); build_from_gemmi(); } + } void DeleteAllModels() { st.models.clear(); build_from_gemmi(); } // clears the hierarchy void DeleteModel(int modelNo) { // 1-based; erase model + rebuild wrappers int i = modelNo - 1; if (i >= 0 && i < (int)st.models.size()) { st.models.erase(st.models.begin() + i); build_from_gemmi(); } } pstr GetInputBuffer(pstr buf, int &count) { count = 0; if (buf) buf[0] = '\0'; return buf; } - // place an atom into the flat table (mmdb Manager::PutAtom) — the shim builds - // hierarchy via Add*/gemmi, so this is a stub returning the index. TODO if a - // PutAtom-built molecule is needed. - int PutAtom(int index, PAtom /*atom*/, int /*serNum*/ = 0) { return index; } + // Insert (a copy of) an atom into the hierarchy (mmdb Manager::PutAtom). MMDB + // keeps a flat atom array with a parallel hierarchy rebuilt by FinishStructEdit; + // the shim's storage IS the hierarchy, so PutAtom finds/creates the chain and + // residue implied by the atom's source residue and appends a copy there. Only + // append (index<=0 or top) is supported — the semantics Coot relies on + // (create_mmdbmanager_from_atom_selection_straight). Returns the atom's 1-based + // position (so GetAtomI(pos) returns it). Defined out-of-line (needs Add*). + int PutAtom(int index, PAtom atom, int serNum = 0); // hierarchy-level UDData (UDR_HIERARCHY) — Manager owns its own UDStore. UDStore _ud; int PutUDData(int h, int v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } @@ -977,14 +1136,18 @@ public: void SetFlag(int /*flags*/) {} // no-op: read/write behaviour is fixed void SetFlag(cpstr /*flags*/) {} int PutPDBString(cpstr /*card*/) { return Error_NoError; } // no-op - int MakeBonds(bool /*calc*/) { return 0; } // TODO: gemmi bonds + // No persistent bond table. Verified safe: Coot's only caller (make_bonds in + // coot-utils/bonded-atoms.cc) ignores the mmdb bond table and recomputes bonds + // itself from geometry, so a no-op here matches observed Coot behaviour. + int MakeBonds(bool /*calc*/) { return 0; } // flat atom access (across the whole hierarchy) std::vector all_atoms; int GetNumberOfAtoms() { return (int)all_atoms.size(); } int GetNumberOfAtoms(bool /*countTers*/) { return (int)all_atoms.size(); } int GetNumberOfAtoms(cpstr CID); // count atoms matching CID (defined below) - PAtom GetAtomI(int i) { return (i >= 0 && i < (int)all_atoms.size()) ? all_atoms[i] : nullptr; } + // MMDB GetAtomI is 1-based: returns Atom[index-1]. + PAtom GetAtomI(int i) { return (i >= 1 && i <= (int)all_atoms.size()) ? all_atoms[i - 1] : nullptr; } void GetAtomTable(PPAtom &t, int &n) { t = all_atoms.data(); n = (int)all_atoms.size(); } void GetModelTable(PPModel &t, int &n) { t = models.data(); n = (int)models.size(); } void GetAtomStatistics(int selHnd, RAtomStat AS); // defined below @@ -996,10 +1159,10 @@ public: // CID-string selection, e.g. "/1/A/10-20/CA" void Select(int selHnd, SELECTION_TYPE sType, cpstr CID, SELECTION_KEY sKey); - // ---- contacts (gemmi-free uniform-grid search) ---- - // TMatrix is MMDB's optional symmetry transform applied to the 2nd set; the - // shim does no symmetry (see contacts.cc image_idx!=0 exclusion), so it's - // accepted and ignored. TODO: gemmi symmetry-aware contacts. + // ---- contacts (gemmi NeighborSearch; TMatrix path uses a uniform grid) ---- + // TMatrix is MMDB's optional symmetry transform applied to the 2nd set: when + // given, contacts.cc transforms that set and searches against it (symmetry + // mates); when null, gemmi NeighborSearch over the untransformed model is used. void SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, realtype d2, int seqDist, PContact &contact, int &ncontacts, int maxlen = 0, pmat44 TMatrix = nullptr, long group = 0); @@ -1234,6 +1397,162 @@ inline void Manager::build_from_gemmi() { } models.push_back(mw); } + _load_metadata(); +} + +// Map gemmi's structure-level metadata (connections / cispeps / helices / +// sheets) onto the MMDB per-Model record containers. gemmi is the reader; the +// shim just re-shapes. Connections/helices/sheets are not model-scoped in gemmi, +// so they go on model 1 (MMDB's usual home); cispeps honour their model_num. +inline void Manager::_load_metadata() { + link_pool.clear(); linkr_pool.clear(); cispep_pool.clear(); helix_pool.clear(); + sheet_pool.clear(); strand_pool.clear(); strandarr_pool.clear(); author_pool.clear(); + + // PDB title AUTHOR records (gemmi meta.authors) + title.author.data.clear(); + for (const std::string &au : st.meta.authors) { + author_pool.emplace_back(); + std::snprintf(author_pool.back().Line, sizeof(author_pool.back().Line), "%s", au.c_str()); + title.author.data.push_back(&author_pool.back()); + } + if (models.empty()) return; + + auto fill_ends = [](const gemmi::AtomAddress &a, ChainID &cid, ResName &rn, + int &seq, InsCode &ic, AtomName *an, AltLoc *al) { + std::snprintf(cid, sizeof(ChainID), "%s", a.chain_name.c_str()); + std::snprintf(rn, sizeof(ResName), "%s", a.res_id.name.c_str()); + seq = a.res_id.seqid.num.value; + ic[0] = (a.res_id.seqid.icode && a.res_id.seqid.icode != ' ') ? a.res_id.seqid.icode : '\0'; + ic[1] = '\0'; + if (an) std::snprintf(*an, sizeof(AtomName), "%s", a.atom_name.c_str()); + if (al) { (*al)[0] = a.altloc ? a.altloc : '\0'; (*al)[1] = '\0'; } + }; + + // --- LINK records (gemmi Connection) -> model 1 --- + Model *m1 = models[0]; + for (const gemmi::Connection &cn : st.connections) { + link_pool.emplace_back(); + Link &l = link_pool.back(); + fill_ends(cn.partner1, l.chainID1, l.resName1, l.seqNum1, l.insCode1, &l.atName1, &l.aloc1); + fill_ends(cn.partner2, l.chainID2, l.resName2, l.seqNum2, l.insCode2, &l.atName2, &l.aloc2); + l.dist = cn.reported_distance; + m1->_links.push_back(&l); + // a connection carrying a Refmac link id is also a LINKR record + if (!cn.link_id.empty()) { + linkr_pool.emplace_back(); + LinkR &lr = linkr_pool.back(); + std::snprintf(lr.linkRID, sizeof(lr.linkRID), "%s", cn.link_id.c_str()); + AtomName an; AltLoc al; + fill_ends(cn.partner1, lr.chainID1, lr.resName1, lr.seqNum1, lr.insCode1, &an, &al); + std::snprintf(lr.atName1, sizeof(AtomName), "%s", an); std::snprintf(lr.aloc1, sizeof(AltLoc), "%s", al); + fill_ends(cn.partner2, lr.chainID2, lr.resName2, lr.seqNum2, lr.insCode2, &an, &al); + std::snprintf(lr.atName2, sizeof(AtomName), "%s", an); std::snprintf(lr.aloc2, sizeof(AltLoc), "%s", al); + lr.dist = cn.reported_distance; + m1->_linkrs.push_back(&lr); + } + } + + // --- CISPEP records (gemmi CisPep) -> model by model_num (default 1) --- + for (const gemmi::CisPep &cp : st.cispeps) { + int mnum = cp.model_num > 0 ? cp.model_num : 1; + Model *mw = GetModel(mnum); + if (!mw) mw = m1; + cispep_pool.emplace_back(); + CisPep &c = cispep_pool.back(); + InsCode ic1, ic2; int s1, s2; + fill_ends(cp.partner_c, c.chainID1, c.pep1, s1, ic1, nullptr, nullptr); + fill_ends(cp.partner_n, c.chainID2, c.pep2, s2, ic2, nullptr, nullptr); + c.seqNum1 = s1; std::snprintf(c.icode1, sizeof(InsCode), "%s", ic1); + c.seqNum2 = s2; std::snprintf(c.icode2, sizeof(InsCode), "%s", ic2); + c.modNum = mnum; + if (!std::isnan(cp.reported_angle)) c.measure = cp.reported_angle; + mw->_cispeps.push_back(&c); + } + + // --- HELIX records (gemmi Helix) -> model 1 --- + for (const gemmi::Helix &gh : st.helices) { + helix_pool.emplace_back(); + Helix &h = helix_pool.back(); + AtomName an; AltLoc al; + fill_ends(gh.start, h.initChainID, h.initResName, h.initSeqNum, h.initICode, &an, &al); + fill_ends(gh.end, h.endChainID, h.endResName, h.endSeqNum, h.endICode, &an, &al); + h.helixClass = (int) gh.pdb_helix_class; + h.length = gh.length; + h.serNum = (int) helix_pool.size(); + m1->helices.AddData(&h); + } + + // --- SHEET / STRAND records (gemmi Sheet) -> model 1 --- + if (!st.sheets.empty()) { + m1->sheets.nSheets = (int) st.sheets.size(); + m1->_sheet_ptrs.assign(st.sheets.size(), nullptr); // backs Sheets::sheet (Sheet**) + for (size_t is = 0; is < st.sheets.size(); ++is) { + const gemmi::Sheet &gs = st.sheets[is]; + sheet_pool.emplace_back(); + Sheet &sh = sheet_pool.back(); + std::snprintf(sh.sheetID, sizeof(sh.sheetID), "%s", gs.name.c_str()); + sh.nStrands = (int) gs.strands.size(); + strandarr_pool.emplace_back(); + std::vector &sarr = strandarr_pool.back(); + sarr.reserve(gs.strands.size()); + for (const gemmi::Sheet::Strand &gst : gs.strands) { + strand_pool.emplace_back(); + Strand &str = strand_pool.back(); + AtomName an; AltLoc al; + fill_ends(gst.start, str.initChainID, str.initResName, str.initSeqNum, str.initICode, &an, &al); + fill_ends(gst.end, str.endChainID, str.endResName, str.endSeqNum, str.endICode, &an, &al); + std::snprintf(str.sheetID, sizeof(str.sheetID), "%s", gs.name.c_str()); + str.strandNo = (int) sarr.size() + 1; + str.sense = gst.sense; + sarr.push_back(&str); + } + sh.strand = sarr.data(); + m1->_sheet_ptrs[is] = &sh; + } + m1->sheets.sheet = m1->_sheet_ptrs.data(); + } +} + +// ---- Manager::PutAtom (hierarchy insertion) ---- +inline int Manager::PutAtom(int index, PAtom A, int serNum) { + if (!A) return 0; + Residue *src = A->res; + // ensure a model exists (Coot calls PutAtom on a fresh, empty Manager) + Model *mw = models.empty() ? nullptr : models[0]; + if (!mw) { + st.models.emplace_back(1); + mw = newModel(); mw->mgr = this; mw->mi = 0; + models.push_back(mw); + } + // find or create the chain implied by the source atom's chain + std::string cid = (src && src->chain) ? src->chain->g().name : std::string("A"); + Chain *cw = mw->GetChain(cid.c_str()); + if (!cw) cw = mw->CreateChain(cid.c_str()); + // find or create the residue implied by (seqNum, insCode) + int seq = src ? src->g().seqid.num.value : 0; + char ic = src ? src->g().seqid.icode : ' '; + char icn = ic ? ic : ' '; + Residue *rw = nullptr; + for (Residue *r : cw->residues) { + gemmi::Residue &gr = r->g(); + if (gr.seqid.num.value == seq && (gr.seqid.icode ? gr.seqid.icode : ' ') == icn) { rw = r; break; } + } + if (!rw) { + gemmi::Residue gr; + gr.name = src ? src->g().name : std::string("UNK"); + gr.seqid.num = seq; + gr.seqid.icode = icn; + rw = cw->AddResidue(*this, gr); + rw->_load_id(); + } + // append a copy of the atom's gemmi backing + register it in the flat tables + Atom *aw = rw->AddAtom(*this, A->g()); + aw->WhatIsSet = A->WhatIsSet; aw->Het = A->Het; + std::memcpy(aw->segID, A->segID, sizeof aw->segID); + aw->g().serial = serNum ? serNum : (index > 0 ? index : (int)all_atoms.size() + 1); + rw->_sync_atom(); + all_atoms.push_back(aw); mw->all_atoms.push_back(aw); + return (int)all_atoms.size(); // 1-based position (GetAtomI(pos) returns aw) } // ---- selection matching ---- @@ -1262,20 +1581,30 @@ inline bool altMatch(cpstr list, char alt) { inline void Manager::Select(int selHnd, SELECTION_TYPE sType, int iModel, cpstr Chains, int ResNo1, cpstr Ins1, int ResNo2, cpstr Ins2, cpstr RNames, cpstr ANames, cpstr Elements, cpstr altLocs, SELECTION_KEY selKey) { - (void)Ins1; (void)Ins2; // insertion-code range filtering: TODO (rare in Coot) Selection &sel = selections[selHnd - 1]; if (sel.type == STYPE_UNDEFINED) sel.type = sType; std::vector oldA = sel.atoms; std::vector oldR = sel.residues; + std::vector oldC = sel.chains; - std::vector mAtoms; std::vector mResidues; + std::vector mAtoms; std::vector mResidues; std::vector mChains; for (Model *mw : models) { if (iModel > 0 && mw->GetSerNum() != iModel) continue; for (Chain *cw : mw->chains) { if (!detail::inList(Chains, cw->g().name)) continue; + bool anyResidue = false; for (Residue *rw : cw->residues) { int sn = rw->g().seqid.num.value; - if (ResNo1 != ANY_RES && sn < ResNo1) continue; - if (ResNo2 != ANY_RES && sn > ResNo2) continue; + char ric = rw->g().seqid.icode ? rw->g().seqid.icode : ' '; + // (seqNum, insCode) range: an explicit insCode only constrains the + // boundary residue; blank/"*" includes every insCode at that seqNum. + if (ResNo1 != ANY_RES) { + if (sn < ResNo1) continue; + if (sn == ResNo1 && Ins1 && Ins1[0] && std::strcmp(Ins1, "*") && ric < Ins1[0]) continue; + } + if (ResNo2 != ANY_RES) { + if (sn > ResNo2) continue; + if (sn == ResNo2 && Ins2 && Ins2[0] && std::strcmp(Ins2, "*") && ric > Ins2[0]) continue; + } if (!detail::inList(RNames, rw->g().name)) continue; bool anyAtom = false; for (Atom *aw : rw->atoms) { @@ -1285,8 +1614,12 @@ inline void Manager::Select(int selHnd, SELECTION_TYPE sType, int iModel, anyAtom = true; if (sType == STYPE_ATOM) mAtoms.push_back(aw); } + if (anyAtom) anyResidue = true; if (anyAtom && sType == STYPE_RESIDUE) mResidues.push_back(rw); } + // STYPE_CHAIN: a chain matching the chain filter (and, if given, having a + // residue that passes the residue/atom filters) is selected whole. + if (sType == STYPE_CHAIN && anyResidue) mChains.push_back(cw); } } auto combine = [&](auto &cur, auto &matched) { @@ -1302,10 +1635,13 @@ inline void Manager::Select(int selHnd, SELECTION_TYPE sType, int iModel, }; if (sType == STYPE_ATOM) combine(sel.atoms, mAtoms); else if (sType == STYPE_RESIDUE) combine(sel.residues, mResidues); + else if (sType == STYPE_CHAIN) combine(sel.chains, mChains); for (Atom *a : oldA) a->_setInSel(selHnd, false); for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); for (Residue *r : oldR) r->_setInSel(selHnd, false); for (Residue *r : sel.residues) r->_setInSel(selHnd, true); + for (Chain *c : oldC) c->_setInSel(selHnd, false); + for (Chain *c : sel.chains) c->_setInSel(selHnd, true); } // select-from-selection: combine selHnd2's contents into selHnd1 @@ -1346,8 +1682,9 @@ inline void Manager::SelectAtom(int selHnd, PAtom atom, SELECTION_KEY sKey, bool } } -// Pragmatic CID parser: "/model/chain/seqNum1(-seqNum2)/atom" (best-effort; -// strips (resname)/[element]/:altloc suffixes). TODO: full MMDB CID grammar. +// Pragmatic CID parser: "/model/chain/seqNum1[.ins1]-seqNum2[.ins2]/atom" +// (best-effort; strips (resname)/[element]/:altloc suffixes; parses insertion +// codes after '.'). Not the full MMDB CID grammar but covers Coot's usage. inline void Manager::Select(int selHnd, SELECTION_TYPE sType, cpstr CID, SELECTION_KEY sKey) { std::string s = CID ? CID : ""; @@ -1367,15 +1704,22 @@ inline void Manager::Select(int selHnd, SELECTION_TYPE sType, cpstr CID, if (!m.empty() && m != "*" && m != "0") iModel = atoi(m.c_str()); std::string chains = tok(1).empty() ? "*" : tok(1); int r1 = ANY_RES, r2 = ANY_RES; + std::string ins1 = "*", ins2 = "*"; + // split "num[.ins]" into number + insertion code + auto parse_resid = [](const std::string &v, int &num, std::string &ins) { + size_t dot = v.find('.'); + num = atoi(v.substr(0, dot).c_str()); + ins = (dot == std::string::npos) ? std::string() : v.substr(dot + 1); + }; std::string rr = strip(tok(2), "("); // drop (resname) if (!rr.empty() && rr != "*") { size_t dash = rr.find('-', rr[0] == '-' ? 1 : 0); - if (dash == std::string::npos) { r1 = r2 = atoi(rr.c_str()); } - else { r1 = atoi(rr.substr(0, dash).c_str()); r2 = atoi(rr.substr(dash + 1).c_str()); } + if (dash == std::string::npos) { parse_resid(rr, r1, ins1); r2 = r1; ins2 = ins1; } + else { parse_resid(rr.substr(0, dash), r1, ins1); parse_resid(rr.substr(dash + 1), r2, ins2); } } std::string anames = strip(strip(tok(3), "["), ":"); // drop [element]/:altloc if (anames.empty()) anames = "*"; - Select(selHnd, sType, iModel, chains.c_str(), r1, "*", r2, "*", "*", + Select(selHnd, sType, iModel, chains.c_str(), r1, ins1.c_str(), r2, ins2.c_str(), "*", anames.c_str(), "*", "*", sKey); } @@ -1442,8 +1786,20 @@ inline Atom::Atom(Residue *r) { if (r) r->AddAtom(this); } inline Residue::Residue(Chain *c) { if (c) c->AddResidue(this); } inline Chain::Chain(Model *m, const ChainID id) { if (m) m->AddChain(this); SetChainID(id); } +// peptide-bond distance threshold for backbone C-N (a real bond is ~1.33 A). +inline bool Residue::isNTerminus() { + if (!chain || ri <= 0) return true; // first (or detached) residue + const gemmi::Atom *N = g().get_n(); + const gemmi::Atom *prevC = chain->residues[ri - 1]->g().get_c(); + if (!N || !prevC) return true; // missing backbone -> terminus + return N->pos.dist(prevC->pos) > 1.7; // not bonded to previous C +} inline bool Residue::isCTerminus() { - return chain && ri == (int)chain->residues.size() - 1; + if (!chain || ri < 0 || ri >= (int)chain->residues.size() - 1) return true; // last/detached + const gemmi::Atom *C = g().get_c(); + const gemmi::Atom *nextN = chain->residues[ri + 1]->g().get_n(); + if (!C || !nextN) return true; + return C->pos.dist(nextN->pos) > 1.7; // not bonded to next N } inline Model *Residue::GetModel() { return chain ? chain->model : nullptr; } diff --git a/mmdb-shim/src/contacts.cc b/mmdb-shim/src/contacts.cc index ef6a4780b8..4fa42b1417 100644 --- a/mmdb-shim/src/contacts.cc +++ b/mmdb-shim/src/contacts.cc @@ -7,11 +7,56 @@ #include #include +#include +#include #include +#include namespace mmdb { namespace { +bool seqNeglect(Atom *a, Atom *b, int seqDist); // defined below + +// apply an MMDB 4x4 (rot+trans) to a position (symmetry transform of a contact set) +gemmi::Position xform(pmat44 T, const gemmi::Position &p) { + const mat44 &m = *T; + return gemmi::Position(m[0][0]*p.x + m[0][1]*p.y + m[0][2]*p.z + m[0][3], + m[1][0]*p.x + m[1][1]*p.y + m[1][2]*p.z + m[1][3], + m[2][0]*p.x + m[2][1]*p.y + m[2][2]*p.z + m[2][3]); +} + +// Contacts between A1 and a TMatrix-transformed second set (positions tp) via a +// uniform grid — used when SeekContacts is given a symmetry operator. selfSkip +// suppresses an atom pairing with its own untransformed self at ~zero distance. +void contacts_transformed(PPAtom A1, int n1, PPAtom A2, const std::vector &tp, + realtype d1, realtype d2, int seqDist, long group, + bool selfSkip, std::vector &found) { + double bin = d2 > 0 ? d2 : 1.0, d1s = d1 * d1, d2s = d2 * d2; + auto cellof = [&](const gemmi::Position &p) { + return std::make_tuple((int)std::floor(p.x / bin), (int)std::floor(p.y / bin), + (int)std::floor(p.z / bin)); + }; + std::map, std::vector> grid; + for (int j = 0; j < (int)tp.size(); ++j) grid[cellof(tp[j])].push_back(j); + for (int i = 0; i < n1; ++i) { + const gemmi::Position &pi = A1[i]->g().pos; + int cx, cy, cz; std::tie(cx, cy, cz) = cellof(pi); + for (int dx = -1; dx <= 1; ++dx) + for (int dy = -1; dy <= 1; ++dy) + for (int dz = -1; dz <= 1; ++dz) { + auto it = grid.find(std::make_tuple(cx + dx, cy + dy, cz + dz)); + if (it == grid.end()) continue; + for (int j : it->second) { + if (selfSkip && A1[i] == A2[j]) continue; + double ds = pi.dist_sq(tp[j]); + if (ds < d1s || ds > d2s) continue; + if (seqNeglect(A1[i], A2[j], seqDist)) continue; + found.push_back({i, j, group, std::sqrt(ds)}); + } + } + } +} + bool seqNeglect(Atom *a, Atom *b, int seqDist) { if (seqDist <= 0) return false; if (a->res->chain != b->res->chain) return false; @@ -70,8 +115,15 @@ void Manager::SelectNeighbours(int selHnd, SELECTION_TYPE sType, PPAtom atoms, void Manager::SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, realtype d2, int seqDist, PContact &contact, int &ncontacts, int /*maxlen*/, - pmat44 /*TMatrix*/, long group) { + pmat44 TMatrix, long group) { std::vector found; + if (TMatrix && n1 > 0 && n2 > 0) { // contacts against a symmetry-transformed A2 + std::vector tp(n2); + for (int j = 0; j < n2; ++j) tp[j] = xform(TMatrix, A2[j]->g().pos); + contacts_transformed(A1, n1, A2, tp, d1, d2, seqDist, group, /*selfSkip=*/false, found); + alloc_contacts(found, contact, ncontacts); + return; + } if (n1 > 0 && n2 > 0) { Model *mw = A1[0]->res->chain->model; // NeighborSearch is per-model gemmi::NeighborSearch ns(mw->g(), st.cell, d2); @@ -98,8 +150,15 @@ void Manager::SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, void Manager::SeekContacts(PPAtom A, int n, realtype d1, realtype d2, int seqDist, PContact &contact, int &ncontacts, int /*maxlen*/, - pmat44 /*TMatrix*/, long group) { + pmat44 TMatrix, long group) { std::vector found; + if (TMatrix && n > 0) { // self-contacts against the symmetry-transformed set + std::vector tp(n); + for (int i = 0; i < n; ++i) tp[i] = xform(TMatrix, A[i]->g().pos); + contacts_transformed(A, n, A, tp, d1, d2, seqDist, group, /*selfSkip=*/true, found); + alloc_contacts(found, contact, ncontacts); + return; + } if (n > 0) { Model *mw = A[0]->res->chain->model; gemmi::NeighborSearch ns(mw->g(), st.cell, d2); diff --git a/mmdb-shim/src/io.cc b/mmdb-shim/src/io.cc index 17356fa34c..0873ef7376 100644 --- a/mmdb-shim/src/io.cc +++ b/mmdb-shim/src/io.cc @@ -15,15 +15,18 @@ namespace mmdb { -// Rebuild the wrapper tree from a freshly loaded gemmi::Structure. We do NOT run -// gemmi's setup_entities()/subchain splitting — MMDB parity wants the raw chains -// as they appear in the file. +// Rebuild the wrapper tree from a freshly loaded gemmi::Structure. gemmi's PDB/ +// mmCIF readers split a single author chain into polymer/ligand/water parts that +// share the chain name; MMDB keeps one chain per chain ID. For MMDB chain-count +// parity we merge those parts back (Structure::merge_chain_parts), so Coot sees +// one mmdb::Chain per chain ID, as it does with real MMDB. ERROR_CODE Manager::ReadPDBASCII(cpstr fname) { try { st = gemmi::read_pdb_file(fname); } catch (const std::exception &) { return Error_CantOpenFile; } + st.merge_chain_parts(); build_from_gemmi(); return Error_NoError; } @@ -34,6 +37,7 @@ ERROR_CODE Manager::ReadCoorFile(cpstr fname) { } catch (const std::exception &) { return Error_CantOpenFile; } + st.merge_chain_parts(); build_from_gemmi(); return Error_NoError; } From 9183e172357726f775b956cafc8febcf34ae31c5 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Wed, 22 Jul 2026 10:08:36 +0100 Subject: [PATCH 08/23] Updated stubbed functions and formatted implementations --- mmdb-shim/include/mmdb2/_graph_impl.hh | 711 ++-- mmdb-shim/include/mmdb2/_mmcif_impl.hh | 1263 +++---- mmdb-shim/include/mmdb2/_shim_impl.hh | 4232 +++++++++++++----------- mmdb-shim/src/contacts.cc | 336 +- mmdb-shim/src/io.cc | 96 +- 5 files changed, 3711 insertions(+), 2927 deletions(-) diff --git a/mmdb-shim/include/mmdb2/_graph_impl.hh b/mmdb-shim/include/mmdb2/_graph_impl.hh index 1815c14096..9f53df25cf 100644 --- a/mmdb-shim/include/mmdb2/_graph_impl.hh +++ b/mmdb-shim/include/mmdb2/_graph_impl.hh @@ -23,333 +23,444 @@ #include namespace mmdb { -namespace math { + namespace math { -// ---- constants (mmdb_math_graph.h) -------------------------------------- -enum GRAPH_BOND { BOND_SINGLE = 1, BOND_DOUBLE = 2, BOND_AROMATIC = 3, BOND_TRIPLE = 4 }; -enum GRAPH_RC { MKGRAPH_Ok = 0, MKGRAPH_NoAtoms = -1, - MKGRAPH_ChangedAltLoc = 1, MKGRAPH_MaxOccupancy = 2 }; -enum GRAPH_MATCH_FLAG { GMF_UniqueMatch = 0x00000001, GMF_NoCombinations = 0x00000002 }; -enum VERTEX_EXT_TYPE { EXTTYPE_Ignore = 0, EXTTYPE_Equal = 1, EXTTYPE_AND = 2, - EXTTYPE_OR = 3, EXTTYPE_XOR = 4, EXTTYPE_NotEqual = 5, - EXTTYPE_NotAND = 6, EXTTYPE_NotOR = 7 }; + // ---- constants (mmdb_math_graph.h) -------------------------------------- + enum GRAPH_BOND { BOND_SINGLE = 1, + BOND_DOUBLE = 2, + BOND_AROMATIC = 3, + BOND_TRIPLE = 4 }; + enum GRAPH_RC { MKGRAPH_Ok = 0, + MKGRAPH_NoAtoms = -1, + MKGRAPH_ChangedAltLoc = 1, + MKGRAPH_MaxOccupancy = 2 }; + enum GRAPH_MATCH_FLAG { GMF_UniqueMatch = 0x00000001, + GMF_NoCombinations = 0x00000002 }; + enum VERTEX_EXT_TYPE { EXTTYPE_Ignore = 0, + EXTTYPE_Equal = 1, + EXTTYPE_AND = 2, + EXTTYPE_OR = 3, + EXTTYPE_XOR = 4, + EXTTYPE_NotEqual = 5, + EXTTYPE_NotAND = 6, + EXTTYPE_NotOR = 7 }; -namespace gdetail { - inline std::string trim(cpstr s) { - std::string t(s ? s : ""); - size_t a = t.find_first_not_of(" \t"), b = t.find_last_not_of(" \t"); - return a == std::string::npos ? std::string() : t.substr(a, b - a + 1); - } - inline int bond_from_string(cpstr s) { - std::string t = trim(s); - for (auto &c : t) c = (char) std::tolower((unsigned char) c); - if (t == "single" || t == "sing" || t == "1") return BOND_SINGLE; - if (t == "double" || t == "doub" || t == "2") return BOND_DOUBLE; - if (t == "aromatic" || t == "arom" || t == "ar") return BOND_AROMATIC; - if (t == "triple" || t == "trip" || t == "3") return BOND_TRIPLE; - return BOND_SINGLE; - } -} + namespace gdetail { + inline std::string trim(cpstr s) { + std::string t(s ? s : ""); + size_t a = t.find_first_not_of(" \t"), b = t.find_last_not_of(" \t"); + return a == std::string::npos ? std::string() : t.substr(a, b - a + 1); + } + inline int bond_from_string(cpstr s) { + std::string t = trim(s); + for (auto &c : t) c = (char)std::tolower((unsigned char)c); + if (t == "single" || t == "sing" || t == "1") return BOND_SINGLE; + if (t == "double" || t == "doub" || t == "2") return BOND_DOUBLE; + if (t == "aromatic" || t == "arom" || t == "ar") return BOND_AROMATIC; + if (t == "triple" || t == "trip" || t == "3") return BOND_TRIPLE; + return BOND_SINGLE; + } + } // namespace gdetail -// ========================================================================= -// Vertex — a graph node (atom). `type` encodes element (atomic number) so -// GetType() equality means "same element". -// ========================================================================= -class Vertex { - public: - int type = 0, type_ext = 0, property = 0, nBonds = 0, id = 0, user_id = 0; - std::string name; + // ========================================================================= + // Vertex — a graph node (atom). `type` encodes element (atomic number) so + // GetType() equality means "same element". + // ========================================================================= + class Vertex { + public: + int type = 0, type_ext = 0, property = 0, nBonds = 0, id = 0, user_id = 0; + std::string name; - Vertex() {} - Vertex(cpstr chem_elem) { SetVertex(chem_elem); } - Vertex(cpstr chem_elem, cpstr vname) { SetVertex(chem_elem); name = vname ? vname : ""; } - Vertex(int vtype, cpstr vname) { type = vtype; name = vname ? vname : ""; } - explicit Vertex(int vtype) { type = vtype; } + Vertex() {} + Vertex(cpstr chem_elem) { SetVertex(chem_elem); } + Vertex(cpstr chem_elem, cpstr vname) { + SetVertex(chem_elem); + name = vname ? vname : ""; + } + Vertex(int vtype, cpstr vname) { + type = vtype; + name = vname ? vname : ""; + } + explicit Vertex(int vtype) { type = vtype; } - void SetVertex(cpstr chem_elem) { - type = (int) gemmi::Element(gdetail::trim(chem_elem).c_str()).atomic_number(); - } - void SetVertex(int vtype, cpstr vname) { type = vtype; name = vname ? vname : ""; } - void SetVertex(int vtype) { type = vtype; } - void SetName(cpstr vname) { name = vname ? vname : ""; } - void SetType(int t) { type = t; } - void SetTypeExt(int t) { type_ext = t; } - void SaveType() { property = type; } - void RestoreType() { type = property; } - void SetUserID(int u) { user_id = u; } - cpstr GetName() { return name.c_str(); } - int GetType() { return type; } - int GetTypeExt() { return type_ext; } - int GetNBonds() { return nBonds; } - int GetUserID() { return user_id; } // 0-based atom index (see MakeVertexIDs/MakeGraph) - void Print(int /*PKey*/ = 0) {} -}; -typedef Vertex *PVertex; typedef Vertex **PPVertex; + void SetVertex(cpstr chem_elem) { + type = (int)gemmi::Element(gdetail::trim(chem_elem).c_str()).atomic_number(); + } + void SetVertex(int vtype, cpstr vname) { + type = vtype; + name = vname ? vname : ""; + } + void SetVertex(int vtype) { type = vtype; } + void SetName(cpstr vname) { name = vname ? vname : ""; } + void SetType(int t) { type = t; } + void SetTypeExt(int t) { type_ext = t; } + void SaveType() { property = type; } + void RestoreType() { type = property; } + void SetUserID(int u) { user_id = u; } + cpstr GetName() { return name.c_str(); } + int GetType() { return type; } + int GetTypeExt() { return type_ext; } + int GetNBonds() { return nBonds; } + int GetUserID() { return user_id; } // 0-based atom index (see MakeVertexIDs/MakeGraph) + void Print(int /*PKey*/ = 0) {} + }; + typedef Vertex *PVertex; + typedef Vertex **PPVertex; -// ========================================================================= -// Edge — a graph connection (bond). v1/v2 are 1-indexed vertex numbers. -// ========================================================================= -class Edge { - public: - int v1 = 0, v2 = 0, type = 0, property = 0; + // ========================================================================= + // Edge — a graph connection (bond). v1/v2 are 1-indexed vertex numbers. + // ========================================================================= + class Edge { + public: + int v1 = 0, v2 = 0, type = 0, property = 0; - Edge() {} - Edge(int vx1, int vx2, int btype) { v1 = vx1; v2 = vx2; type = btype; } - Edge(int vx1, int vx2, cpstr btype) { v1 = vx1; v2 = vx2; type = gdetail::bond_from_string(btype); } + Edge() {} + Edge(int vx1, int vx2, int btype) { + v1 = vx1; + v2 = vx2; + type = btype; + } + Edge(int vx1, int vx2, cpstr btype) { + v1 = vx1; + v2 = vx2; + type = gdetail::bond_from_string(btype); + } - void SetEdge(int vx1, int vx2, int btype) { v1 = vx1; v2 = vx2; type = btype; } - void SetEdge(int vx1, int vx2, cpstr btype) { v1 = vx1; v2 = vx2; type = gdetail::bond_from_string(btype); } - void SetType(int t) { type = t; } - int GetVertex1() { return v1; } - int GetVertex2() { return v2; } - int GetType() { return type; } - void Print(int /*PKey*/ = 0) {} -}; -typedef Edge *PEdge; typedef Edge **PPEdge; + void SetEdge(int vx1, int vx2, int btype) { + v1 = vx1; + v2 = vx2; + type = btype; + } + void SetEdge(int vx1, int vx2, cpstr btype) { + v1 = vx1; + v2 = vx2; + type = gdetail::bond_from_string(btype); + } + void SetType(int t) { type = t; } + int GetVertex1() { return v1; } + int GetVertex2() { return v2; } + int GetType() { return type; } + void Print(int /*PKey*/ = 0) {} + }; + typedef Edge *PEdge; + typedef Edge **PPEdge; -// ========================================================================= -// Graph — vertices + edges + adjacency matrix (built by Build()). -// Owns the Vertex/Edge objects handed to AddVertex/AddEdge (mmdb semantics). -// ========================================================================= -class Graph { - public: - std::string gname; - std::vector V; // owned; 1-indexed via GetVertex - std::vector E; // owned - std::vector> adj; // (n+1)x(n+1), 1-indexed; adj[i][j]=bond type or 0 + // ========================================================================= + // Graph — vertices + edges + adjacency matrix (built by Build()). + // Owns the Vertex/Edge objects handed to AddVertex/AddEdge (mmdb semantics). + // ========================================================================= + class Graph { + public: + std::string gname; + std::vector V; // owned; 1-indexed via GetVertex + std::vector E; // owned + std::vector> adj; // (n+1)x(n+1), 1-indexed; adj[i][j]=bond type or 0 - Graph() {} - ~Graph() { for (auto *p : V) delete p; for (auto *e : E) delete e; } - Graph(const Graph &) = delete; - Graph &operator=(const Graph &) = delete; + Graph() {} + ~Graph() { + for (auto *p : V) delete p; + for (auto *e : E) delete e; + } + Graph(const Graph &) = delete; + Graph &operator=(const Graph &) = delete; - void SetName(cpstr n) { gname = n ? n : ""; } - pstr GetName() { return (pstr) gname.c_str(); } - void AddVertex(PVertex v) { if (v) V.push_back(v); } - void AddEdge(PEdge e) { if (e) E.push_back(e); } - int GetNofVertices() { return (int) V.size(); } - int GetNofEdges() { return (int) E.size(); } - PVertex GetVertex(int i) { return (i >= 1 && i <= (int) V.size()) ? V[i - 1] : nullptr; } - PEdge GetEdge(int i) { return (i >= 1 && i <= (int) E.size()) ? E[i - 1] : nullptr; } - void GetVertices(PPVertex &v, int &n) { v = V.data(); n = (int) V.size(); } - void GetEdges(PPEdge &e, int &n) { e = E.data(); n = (int) E.size(); } - // number vertices; user_id = 0-based position so `residue->atom[V->GetUserID()]` - // (Coot's manual make_graph path) indexes the residue's 0-based atom table. - void MakeVertexIDs() { for (int i = 0; i < (int) V.size(); ++i) { V[i]->id = i + 1; V[i]->user_id = i; } } - void Print() {} - void Print1() {} - void MakeSymmetryRelief(bool /*noCO2*/) {} // type_ext modifiers — low priority, no-op - void IdentifyRings() {} // " " - void IdentifyConnectedComponents() {} + void SetName(cpstr n) { gname = n ? n : ""; } + pstr GetName() { return (pstr)gname.c_str(); } + void AddVertex(PVertex v) { + if (v) V.push_back(v); + } + void AddEdge(PEdge e) { + if (e) E.push_back(e); + } + int GetNofVertices() { return (int)V.size(); } + int GetNofEdges() { return (int)E.size(); } + PVertex GetVertex(int i) { return (i >= 1 && i <= (int)V.size()) ? V[i - 1] : nullptr; } + PEdge GetEdge(int i) { return (i >= 1 && i <= (int)E.size()) ? E[i - 1] : nullptr; } + void GetVertices(PPVertex &v, int &n) { + v = V.data(); + n = (int)V.size(); + } + void GetEdges(PPEdge &e, int &n) { + e = E.data(); + n = (int)E.size(); + } + // number vertices; user_id = 0-based position so `residue->atom[V->GetUserID()]` + // (Coot's manual make_graph path) indexes the residue's 0-based atom table. + void MakeVertexIDs() { + for (int i = 0; i < (int)V.size(); ++i) { + V[i]->id = i + 1; + V[i]->user_id = i; + } + } + void Print() {} + void Print1() {} + void MakeSymmetryRelief(bool /*noCO2*/) {} // type_ext modifiers — low priority, no-op + void IdentifyRings() {} // " " + void IdentifyConnectedComponents() {} - // adjacency matrix; bondOrder=false collapses all bonds to 1 (connectivity only) - int Build(bool bondOrder) { - int n = (int) V.size(); - adj.assign(n + 1, std::vector(n + 1, 0)); - for (Edge *e : E) - if (e->v1 >= 1 && e->v1 <= n && e->v2 >= 1 && e->v2 <= n) { - int t = bondOrder ? (e->type > 0 ? e->type : 1) : 1; - adj[e->v1][e->v2] = t; adj[e->v2][e->v1] = t; - } - for (int i = 1; i <= n; ++i) { - int b = 0; for (int j = 1; j <= n; ++j) if (adj[i][j]) ++b; - V[i - 1]->nBonds = b; - } - return 0; - } - - int MakeGraph(PPAtom atom, int nAtoms); // build from atoms (distance bonds) - int MakeGraph(PResidue R, cpstr altLoc = nullptr); -}; -typedef Graph *PGraph; + // adjacency matrix; bondOrder=false collapses all bonds to 1 (connectivity only) + int Build(bool bondOrder) { + int n = (int)V.size(); + adj.assign(n + 1, std::vector(n + 1, 0)); + for (Edge *e : E) + if (e->v1 >= 1 && e->v1 <= n && e->v2 >= 1 && e->v2 <= n) { + int t = bondOrder ? (e->type > 0 ? e->type : 1) : 1; + adj[e->v1][e->v2] = t; + adj[e->v2][e->v1] = t; + } + for (int i = 1; i <= n; ++i) { + int b = 0; + for (int j = 1; j <= n; ++j) + if (adj[i][j]) ++b; + V[i - 1]->nBonds = b; + } + return 0; + } -// ========================================================================= -// GraphMatch — maximum common (induced) subgraph via branch-and-bound. -// ========================================================================= -class GraphMatch { - public: - struct Match { std::vector f1, f2; }; // 1-indexed vertex numbers - std::vector matches; - int maxMatch = 0; - int maxNofMatches = 1000000; - bool stopOnMax = false; - int timeLimit = 0; // seconds; 0 = no limit - word flags = 0; - bool Stop = false; - // stable 1-indexed ivector storage for GetMatch (freed with this object) - std::vector> fv1, fv2; + int MakeGraph(PPAtom atom, int nAtoms); // build from atoms (distance bonds) + int MakeGraph(PResidue R, cpstr altLoc = nullptr); + }; + typedef Graph *PGraph; - void SetFlag(word f) { flags |= f; } - void RemoveFlag(word f) { flags &= ~f; } - void SetMaxNofMatches(int m, bool stopOnMaxN) { maxNofMatches = m > 0 ? m : 1; stopOnMax = stopOnMaxN; } - void SetTimeLimit(int t = 0) { timeLimit = t; } - int GetNofMatches() { return (int) matches.size(); } - int GetMaxMatchSize() { return maxMatch; } - bool GetStopSignal() { return Stop; } - void Reset() { matches.clear(); fv1.clear(); fv2.clear(); maxMatch = 0; } - void PrintMatches() {} + // ========================================================================= + // GraphMatch — maximum common (induced) subgraph via branch-and-bound. + // ========================================================================= + class GraphMatch { + public: + struct Match { + std::vector f1, f2; + }; // 1-indexed vertex numbers + std::vector matches; + int maxMatch = 0; + int maxNofMatches = 1000000; + bool stopOnMax = false; + int timeLimit = 0; // seconds; 0 = no limit + word flags = 0; + bool Stop = false; + // stable 1-indexed ivector storage for GetMatch (freed with this object) + std::vector> fv1, fv2; - void MatchGraphs(PGraph Gh1, PGraph Gh2, int minMatch, bool vertexType = true, - VERTEX_EXT_TYPE vertexExt = EXTTYPE_Ignore); - void GetMatch(int MatchNo, ivector &FV1, ivector &FV2, int &nv, realtype &p1, realtype &p2); -}; -typedef GraphMatch *PGraphMatch; + void SetFlag(word f) { flags |= f; } + void RemoveFlag(word f) { flags &= ~f; } + void SetMaxNofMatches(int m, bool stopOnMaxN) { + maxNofMatches = m > 0 ? m : 1; + stopOnMax = stopOnMaxN; + } + void SetTimeLimit(int t = 0) { timeLimit = t; } + int GetNofMatches() { return (int)matches.size(); } + int GetMaxMatchSize() { return maxMatch; } + bool GetStopSignal() { return Stop; } + void Reset() { + matches.clear(); + fv1.clear(); + fv2.clear(); + maxMatch = 0; + } + void PrintMatches() {} -// ---- MatchGraphs: branch-and-bound maximum common induced subgraph ------- -inline void GraphMatch::MatchGraphs(PGraph g1, PGraph g2, int minMatch, - bool vertexType, VERTEX_EXT_TYPE vertexExt) { - Reset(); Stop = false; - int n1 = g1->GetNofVertices(), n2 = g2->GetNofVertices(); - if (n1 == 0 || n2 == 0) return; - if ((int) g1->adj.size() != n1 + 1) g1->Build(false); - if ((int) g2->adj.size() != n2 + 1) g2->Build(false); - const std::vector> &A1 = g1->adj, &A2 = g2->adj; + void MatchGraphs(PGraph Gh1, PGraph Gh2, int minMatch, bool vertexType = true, + VERTEX_EXT_TYPE vertexExt = EXTTYPE_Ignore); + void GetMatch(int MatchNo, ivector &FV1, ivector &FV2, int &nv, realtype &p1, realtype &p2); + }; + typedef GraphMatch *PGraphMatch; - auto t0 = std::chrono::steady_clock::now(); - auto timed_out = [&]() -> bool { - if (timeLimit <= 0) return false; - if (std::chrono::duration_cast( - std::chrono::steady_clock::now() - t0).count() >= timeLimit) { Stop = true; return true; } - return false; - }; + // ---- MatchGraphs: branch-and-bound maximum common induced subgraph ------- + inline void GraphMatch::MatchGraphs(PGraph g1, PGraph g2, int minMatch, + bool vertexType, VERTEX_EXT_TYPE vertexExt) { + Reset(); + Stop = false; + int n1 = g1->GetNofVertices(), n2 = g2->GetNofVertices(); + if (n1 == 0 || n2 == 0) return; + if ((int)g1->adj.size() != n1 + 1) g1->Build(false); + if ((int)g2->adj.size() != n2 + 1) g2->Build(false); + const std::vector> &A1 = g1->adj, &A2 = g2->adj; - std::vector> cur; // matched (g1,g2) 1-indexed pairs - std::vector used2(n2 + 1, 0); - std::vector>> best; + auto t0 = std::chrono::steady_clock::now(); + auto timed_out = [&]() -> bool { + if (timeLimit <= 0) return false; + if (std::chrono::duration_cast( + std::chrono::steady_clock::now() - t0) + .count() >= timeLimit) { + Stop = true; + return true; + } + return false; + }; - auto compatible = [&](int i1, int i2) -> bool { - if (vertexType && g1->V[i1 - 1]->type != g2->V[i2 - 1]->type) return false; - if (vertexExt == EXTTYPE_Equal && g1->V[i1 - 1]->type_ext != g2->V[i2 - 1]->type_ext) return false; - for (const auto &pr : cur) // preserve edges (incl. absence) + bond type - if (A1[i1][pr.first] != A2[i2][pr.second]) return false; - return true; - }; + std::vector> cur; // matched (g1,g2) 1-indexed pairs + std::vector used2(n2 + 1, 0); + std::vector>> best; - std::function rec = [&](int idx) { - if (Stop || timed_out()) return; - // bound: best achievable from here can't exceed cur + remaining g1 vertices - if ((int) cur.size() + (n1 - idx + 1) < maxMatch) return; - if (idx > n1) { - int sz = (int) cur.size(); - if (sz >= minMatch && sz >= maxMatch) { - if (sz > maxMatch) { maxMatch = sz; best.clear(); } - if ((int) best.size() < maxNofMatches) best.push_back(cur); - else if (stopOnMax) Stop = true; - } - return; - } - for (int i2 = 1; i2 <= n2 && !Stop; ++i2) { // Option A: map g1[idx] - if (used2[i2] || !compatible(idx, i2)) continue; - cur.push_back({idx, i2}); used2[i2] = 1; - rec(idx + 1); - used2[i2] = 0; cur.pop_back(); - } - if (!Stop) rec(idx + 1); // Option B: skip g1[idx] - }; - rec(1); + auto compatible = [&](int i1, int i2) -> bool { + if (vertexType && g1->V[i1 - 1]->type != g2->V[i2 - 1]->type) return false; + if (vertexExt == EXTTYPE_Equal && g1->V[i1 - 1]->type_ext != g2->V[i2 - 1]->type_ext) return false; + for (const auto &pr : cur) // preserve edges (incl. absence) + bond type + if (A1[i1][pr.first] != A2[i2][pr.second]) return false; + return true; + }; - for (auto &m : best) { - Match mm; - for (auto &pr : m) { mm.f1.push_back(pr.first); mm.f2.push_back(pr.second); } - matches.push_back(std::move(mm)); - } -} + std::function rec = [&](int idx) { + if (Stop || timed_out()) return; + // bound: best achievable from here can't exceed cur + remaining g1 vertices + if ((int)cur.size() + (n1 - idx + 1) < maxMatch) return; + if (idx > n1) { + int sz = (int)cur.size(); + if (sz >= minMatch && sz >= maxMatch) { + if (sz > maxMatch) { + maxMatch = sz; + best.clear(); + } + if ((int)best.size() < maxNofMatches) + best.push_back(cur); + else if (stopOnMax) + Stop = true; + } + return; + } + for (int i2 = 1; i2 <= n2 && !Stop; ++i2) { // Option A: map g1[idx] + if (used2[i2] || !compatible(idx, i2)) continue; + cur.push_back({idx, i2}); + used2[i2] = 1; + rec(idx + 1); + used2[i2] = 0; + cur.pop_back(); + } + if (!Stop) rec(idx + 1); // Option B: skip g1[idx] + }; + rec(1); -inline void GraphMatch::GetMatch(int MatchNo, ivector &FV1, ivector &FV2, - int &nv, realtype &p1, realtype &p2) { - if (MatchNo < 0 || MatchNo >= (int) matches.size()) { FV1 = FV2 = nullptr; nv = 0; p1 = p2 = 0; return; } - if ((int) fv1.size() != (int) matches.size()) { fv1.resize(matches.size()); fv2.resize(matches.size()); } - Match &m = matches[MatchNo]; - nv = (int) m.f1.size(); - std::vector &a = fv1[MatchNo]; std::vector &b = fv2[MatchNo]; - a.assign(nv + 1, 0); b.assign(nv + 1, 0); // 1-indexed: [1..nv] valid - for (int i = 0; i < nv; ++i) { a[i + 1] = m.f1[i]; b[i + 1] = m.f2[i]; } - FV1 = a.data(); FV2 = b.data(); - p1 = p2 = (realtype) nv; -} - -// ---- MakeGraph from atoms (distance-based bonds) ------------------------- -inline int Graph::MakeGraph(PPAtom atom, int nAtoms) { - for (auto *p : V) delete p; for (auto *e : E) delete e; - V.clear(); E.clear(); adj.clear(); - if (nAtoms <= 0) return MKGRAPH_NoAtoms; - for (int i = 0; i < nAtoms; ++i) { - Vertex *v = new Vertex(atom[i]->GetElementName(), atom[i]->GetAtomName()); - v->user_id = i; // 0-based atom index for atom-table lookup - V.push_back(v); - } - // covalent-ish bonds by distance (< 1.9 A) — gemmi has no residue bond table - for (int i = 0; i < nAtoms; ++i) - for (int j = i + 1; j < nAtoms; ++j) { - double dx = atom[i]->x() - atom[j]->x(); - double dy = atom[i]->y() - atom[j]->y(); - double dz = atom[i]->z() - atom[j]->z(); - if (dx * dx + dy * dy + dz * dz < 1.9 * 1.9) - E.push_back(new Edge(i + 1, j + 1, BOND_SINGLE)); - } - return MKGRAPH_Ok; -} -inline int Graph::MakeGraph(PResidue R, cpstr /*altLoc*/) { - if (!R) return MKGRAPH_NoAtoms; - PPAtom a = nullptr; int n = 0; - R->GetAtomTable(a, n); - return MakeGraph(a, n); -} + for (auto &m : best) { + Match mm; + for (auto &pr : m) { + mm.f1.push_back(pr.first); + mm.f2.push_back(pr.second); + } + matches.push_back(std::move(mm)); + } + } -// ========================================================================= -// Alignment — global (Needleman-Wunsch) sequence alignment (mmdb_math_align.h). -// Coot uses it to align a model sequence to a target and read back the gapped -// strings + score (for mutation/indel detection, api/coot-molecule.cc). -// -// NOTE on prefer-gemmi: gemmi DOES provide sequence alignment (align.hpp / -// seqalign.hpp), but only over a substitution-scoring matrix. MMDB's aligner — -// which Coot's mutation detection was tuned against — uses simple identity -// scoring (match=1 / mismatch=0 / linear gap). Swapping in gemmi's scorer would -// change which residues are called mutations vs. indels, i.e. it would NOT -// reproduce the MMDB baseline this shim exists to preserve. So this stays a -// faithful re-creation of MMDB's *specific* simple-scoring global aligner — -// the exact form gemmi does not offer — rather than a gratuitous reimplementation. -// ========================================================================= -class Alignment { - public: - std::string _s, _t; // aligned (gapped) sequences - realtype VAchieved = 0; // alignment score + inline void GraphMatch::GetMatch(int MatchNo, ivector &FV1, ivector &FV2, + int &nv, realtype &p1, realtype &p2) { + if (MatchNo < 0 || MatchNo >= (int)matches.size()) { + FV1 = FV2 = nullptr; + nv = 0; + p1 = p2 = 0; + return; + } + if ((int)fv1.size() != (int)matches.size()) { + fv1.resize(matches.size()); + fv2.resize(matches.size()); + } + Match &m = matches[MatchNo]; + nv = (int)m.f1.size(); + std::vector &a = fv1[MatchNo]; + std::vector &b = fv2[MatchNo]; + a.assign(nv + 1, 0); + b.assign(nv + 1, 0); // 1-indexed: [1..nv] valid + for (int i = 0; i < nv; ++i) { + a[i + 1] = m.f1[i]; + b[i + 1] = m.f2[i]; + } + FV1 = a.data(); + FV2 = b.data(); + p1 = p2 = (realtype)nv; + } - void Align(cpstr S, cpstr T, realtype /*VGap*/ = 0.0, realtype VSpace = -1.0) { - std::string a(S ? S : ""), b(T ? T : ""); - int n = (int) a.size(), m = (int) b.size(); - const realtype MATCH = 1.0, MIS = 0.0, GAP = VSpace != 0.0 ? VSpace : -1.0; - std::vector> D(n + 1, std::vector(m + 1, 0.0)); - for (int i = 1; i <= n; ++i) D[i][0] = D[i - 1][0] + GAP; - for (int j = 1; j <= m; ++j) D[0][j] = D[0][j - 1] + GAP; - for (int i = 1; i <= n; ++i) - for (int j = 1; j <= m; ++j) { - realtype diag = D[i - 1][j - 1] + (a[i - 1] == b[j - 1] ? MATCH : MIS); - realtype up = D[i - 1][j] + GAP, left = D[i][j - 1] + GAP; - D[i][j] = std::max(diag, std::max(up, left)); + // ---- MakeGraph from atoms (distance-based bonds) ------------------------- + inline int Graph::MakeGraph(PPAtom atom, int nAtoms) { + for (auto *p : V) delete p; + for (auto *e : E) delete e; + V.clear(); + E.clear(); + adj.clear(); + if (nAtoms <= 0) return MKGRAPH_NoAtoms; + for (int i = 0; i < nAtoms; ++i) { + Vertex *v = new Vertex(atom[i]->GetElementName(), atom[i]->GetAtomName()); + v->user_id = i; // 0-based atom index for atom-table lookup + V.push_back(v); + } + // covalent-ish bonds by distance (< 1.9 A) — gemmi has no residue bond table + for (int i = 0; i < nAtoms; ++i) + for (int j = i + 1; j < nAtoms; ++j) { + double dx = atom[i]->x() - atom[j]->x(); + double dy = atom[i]->y() - atom[j]->y(); + double dz = atom[i]->z() - atom[j]->z(); + if (dx * dx + dy * dy + dz * dz < 1.9 * 1.9) + E.push_back(new Edge(i + 1, j + 1, BOND_SINGLE)); + } + return MKGRAPH_Ok; } - VAchieved = D[n][m]; - std::string as, bs; // traceback - int i = n, j = m; - while (i > 0 || j > 0) { - if (i > 0 && j > 0 && - D[i][j] == D[i - 1][j - 1] + (a[i - 1] == b[j - 1] ? MATCH : MIS)) { - as += a[i - 1]; bs += b[j - 1]; --i; --j; - } else if (i > 0 && D[i][j] == D[i - 1][j] + GAP) { - as += a[i - 1]; bs += '-'; --i; - } else { - as += '-'; bs += b[j - 1]; --j; + inline int Graph::MakeGraph(PResidue R, cpstr /*altLoc*/) { + if (!R) return MKGRAPH_NoAtoms; + PPAtom a = nullptr; + int n = 0; + R->GetAtomTable(a, n); + return MakeGraph(a, n); } - } - std::reverse(as.begin(), as.end()); std::reverse(bs.begin(), bs.end()); - _s = as; _t = bs; - } - pstr GetAlignedS() { return (pstr) _s.c_str(); } - pstr GetAlignedT() { return (pstr) _t.c_str(); } - realtype GetScore() { return VAchieved; } -}; -} // namespace math + // ========================================================================= + // Alignment — global (Needleman-Wunsch) sequence alignment (mmdb_math_align.h). + // Coot uses it to align a model sequence to a target and read back the gapped + // strings + score (for mutation/indel detection, api/coot-molecule.cc). + // + // NOTE on prefer-gemmi: gemmi DOES provide sequence alignment (align.hpp / + // seqalign.hpp), but only over a substitution-scoring matrix. MMDB's aligner — + // which Coot's mutation detection was tuned against — uses simple identity + // scoring (match=1 / mismatch=0 / linear gap). Swapping in gemmi's scorer would + // change which residues are called mutations vs. indels, i.e. it would NOT + // reproduce the MMDB baseline this shim exists to preserve. So this stays a + // faithful re-creation of MMDB's *specific* simple-scoring global aligner — + // the exact form gemmi does not offer — rather than a gratuitous reimplementation. + // ========================================================================= + class Alignment { + public: + std::string _s, _t; // aligned (gapped) sequences + realtype VAchieved = 0; // alignment score + + void Align(cpstr S, cpstr T, realtype /*VGap*/ = 0.0, realtype VSpace = -1.0) { + std::string a(S ? S : ""), b(T ? T : ""); + int n = (int)a.size(), m = (int)b.size(); + const realtype MATCH = 1.0, MIS = 0.0, GAP = VSpace != 0.0 ? VSpace : -1.0; + std::vector> D(n + 1, std::vector(m + 1, 0.0)); + for (int i = 1; i <= n; ++i) D[i][0] = D[i - 1][0] + GAP; + for (int j = 1; j <= m; ++j) D[0][j] = D[0][j - 1] + GAP; + for (int i = 1; i <= n; ++i) + for (int j = 1; j <= m; ++j) { + realtype diag = D[i - 1][j - 1] + (a[i - 1] == b[j - 1] ? MATCH : MIS); + realtype up = D[i - 1][j] + GAP, left = D[i][j - 1] + GAP; + D[i][j] = std::max(diag, std::max(up, left)); + } + VAchieved = D[n][m]; + std::string as, bs; // traceback + int i = n, j = m; + while (i > 0 || j > 0) { + if (i > 0 && j > 0 && + D[i][j] == D[i - 1][j - 1] + (a[i - 1] == b[j - 1] ? MATCH : MIS)) { + as += a[i - 1]; + bs += b[j - 1]; + --i; + --j; + } else if (i > 0 && D[i][j] == D[i - 1][j] + GAP) { + as += a[i - 1]; + bs += '-'; + --i; + } else { + as += '-'; + bs += b[j - 1]; + --j; + } + } + std::reverse(as.begin(), as.end()); + std::reverse(bs.begin(), bs.end()); + _s = as; + _t = bs; + } + pstr GetAlignedS() { return (pstr)_s.c_str(); } + pstr GetAlignedT() { return (pstr)_t.c_str(); } + realtype GetScore() { return VAchieved; } + }; + + } // namespace math } // namespace mmdb #endif // COOT_MMDB_SHIM_GRAPH_IMPL_HH diff --git a/mmdb-shim/include/mmdb2/_mmcif_impl.hh b/mmdb-shim/include/mmdb2/_mmcif_impl.hh index 85d33e97e1..35b7933b5e 100644 --- a/mmdb-shim/include/mmdb2/_mmcif_impl.hh +++ b/mmdb-shim/include/mmdb2/_mmcif_impl.hh @@ -11,8 +11,8 @@ #define COOT_MMDB_SHIM_MMCIF_IMPL_HH #include -#include // gemmi::cif::read_file -#include // gemmi::cif::write_cif_to_stream +#include // gemmi::cif::read_file +#include // gemmi::cif::write_cif_to_stream #include #include @@ -22,580 +22,691 @@ #include namespace mmdb { -namespace mmcif { - -// ---- return codes (mirror mmdb_mmcif_.h) -------------------------------- -enum { - CIFRC_Loop = 2, - CIFRC_Structure = 1, - CIFRC_Ok = 0, - CIFRC_StructureNoTag = -1, - CIFRC_LoopNoTag = -2, - CIFRC_NoCategory = -3, - CIFRC_WrongFormat = -4, - CIFRC_NoTag = -5, - CIFRC_NotAStructure = -6, - CIFRC_NotALoop = -7, - CIFRC_WrongIndex = -8, - CIFRC_NoField = -9, - CIFRC_Created = -12, - CIFRC_CantOpenFile = -13, - CIFRC_NoDataLine = -14, - CIFRC_NoData = -15 -}; - -// ---- file flags ---------------------------------------------------------- -enum { - CIFFL_PrintWarnings = 0x00000001, - CIFFL_StopOnWarnings = 0x00000002, - CIFFL_SuggestCategories = 0x00000004, - CIFFL_SuggestTags = 0x00000008 -}; - -enum MMCIF_ITEM { - MMCIF_None = 0, MMCIF_Struct = 1, MMCIF_Loop = 2, - MMCIF_Data = 3, MMCIF_Category = 4 -}; - -class Loop; -class Struct; -class Category; -class Data; -class File; -typedef Loop *PLoop; -typedef Struct *PStruct; -typedef Category *PCategory; -typedef Data *PData; -typedef File *PFile; - -namespace detail { - // MMDB category names have no trailing dot; gemmi wants "_cat." — normalise - // to WITH-dot internally so full tag = cat + subtag. - inline std::string with_dot(const char *cat) { - std::string s(cat ? cat : ""); - if (s.empty() || s.back() != '.') s += '.'; - return s; - } - inline std::string strip_dot(const std::string &s) { - if (!s.empty() && s.back() == '.') return s.substr(0, s.size() - 1); - return s; - } -} - -// ========================================================================= -// Category — just a named handle (Coot uses GetCategoryName / GetCategoryID) -// ========================================================================= -class Category { - public: - std::string cat; // WITH trailing dot - MMCIF_ITEM kind = MMCIF_Category; - std::deque sret; - Category() {} - pstr GetCategoryName() { - sret.push_back(detail::strip_dot(cat)); - return (pstr) sret.back().c_str(); - } - MMCIF_ITEM GetCategoryID() { return kind; } -}; - -// ========================================================================= -// Loop -// ========================================================================= -class Loop { - public: - Data *owner = nullptr; // null for a bare `new Loop` - std::string cat; // WITH trailing dot - gemmi::cif::Loop *direct = nullptr; // FindLoop binds the gemmi loop directly - bool write_mode = false; - // write buffer (row-major); sub-tags only (no category prefix) - std::vector wtags; - std::vector> wrows; - // storage for borrowed pstr returns (Coot never frees these) - std::deque sret; - - Loop() {} - - gemmi::cif::Loop *gloop() const; // read loop, or nullptr (defined after Data) - - int GetLoopLength(); - int GetNofTags(); - pstr GetTag(int tagNo); - pstr GetField(int rowNo, int tagNo); - - pstr GetString (cpstr TName, int nrow, int &RC); - int GetReal (realtype &R, cpstr TName, int nrow, bool Remove = false); - int GetInteger (int &I, cpstr TName, int nrow, bool Remove = false); - - void AddLoopTag (cpstr T, bool Remove = true) { (void) Remove; wcol(T, true); } - void PutString (cpstr S, cpstr T, int nrow) { wput(T, nrow, S ? S : "."); } - void PutInteger (int I, cpstr T, int nrow) { wput(T, nrow, std::to_string(I)); } - void PutReal (realtype R, cpstr T, int nrow, int prec = 8) { - char b[64]; std::snprintf(b, sizeof b, "%.*f", prec, (double) R); wput(T, nrow, b); - } - void PutReal (realtype R, cpstr T, int nrow, cpstr /*format*/) { PutReal(R, T, nrow, 8); } - - // write helpers - int wcol(cpstr T, bool create); - void wput(cpstr T, int nrow, const std::string &val); - void flush(gemmi::cif::Block &b); -}; - -inline int Loop::wcol(cpstr T, bool create) { - for (size_t i = 0; i < wtags.size(); ++i) - if (wtags[i] == T) return (int) i; - if (!create) return -1; - wtags.push_back(T); - for (auto &row : wrows) row.resize(wtags.size()); - return (int) wtags.size() - 1; -} - -inline void Loop::wput(cpstr T, int nrow, const std::string &val) { - write_mode = true; - int col = wcol(T, true); - if (nrow < 0) nrow = 0; - while ((int) wrows.size() <= nrow) wrows.emplace_back(wtags.size()); - wrows[nrow][col] = val; -} - -inline void Loop::flush(gemmi::cif::Block &b) { - if (wtags.empty()) return; - gemmi::cif::Loop &gl = b.init_mmcif_loop(cat, wtags); // tags become cat+subtag - gl.values.clear(); - gl.values.reserve(wrows.size() * wtags.size()); - for (auto &row : wrows) - for (size_t c = 0; c < wtags.size(); ++c) { - const std::string &v = c < row.size() ? row[c] : std::string(); - gl.values.push_back(v.empty() ? "." : gemmi::cif::quote(v)); - } -} - -inline int Loop::GetLoopLength() { - gemmi::cif::Loop *g = gloop(); - return g ? (int) g->length() : (int) wrows.size(); -} -inline int Loop::GetNofTags() { - gemmi::cif::Loop *g = gloop(); - return g ? (int) g->width() : (int) wtags.size(); -} - -// ========================================================================= -// Struct (single-value category = a set of tag/value pairs) -// ========================================================================= -class Struct { - public: - Data *owner = nullptr; - std::string cat; // WITH trailing dot - bool write_mode = false; - std::vector> wpairs; - std::deque sret; - - Struct() {} - - pstr GetCategoryName() { - sret.push_back(detail::strip_dot(cat)); - return (pstr) sret.back().c_str(); - } - - int GetNofTags(); - pstr GetTag(int tagNo); - pstr GetField(int tagNo); - pstr GetString (cpstr TName, int &RC); - int GetReal (realtype &R, cpstr TName, bool Remove = false); - int GetInteger (int &I, cpstr TName, bool Remove = false); - - void PutString (cpstr S, cpstr TName, bool /*Concatenate*/ = false) { - write_mode = true; wpairs.emplace_back(TName, S ? S : "."); - } - void PutReal (realtype R, cpstr TName, int prec = 8) { - char b[64]; std::snprintf(b, sizeof b, "%.*f", prec, (double) R); - write_mode = true; wpairs.emplace_back(TName, b); - } - void PutReal (realtype R, cpstr TName, cpstr /*format*/) { PutReal(R, TName, 8); } - void PutInteger (int I, cpstr TName) { - write_mode = true; wpairs.emplace_back(TName, std::to_string(I)); - } - - std::vector collect_tags(); // read: sub-tags present in block - void flush(gemmi::cif::Block &b); -}; - -// ========================================================================= -// Data (a data_ block) -// ========================================================================= -class Data { - public: - gemmi::cif::Document *doc = nullptr; // resolve block by INDEX (blocks vector reallocs) - size_t idx = 0; - std::unique_ptr owned_doc; // for a standalone `new Data()` - - std::deque loops; - std::deque structs; - std::deque cats_pool; - std::unordered_map loop_by_cat; - std::unordered_map struct_by_cat; - std::vector cat_names; // WITH dot - bool cats_built = false; - std::deque sret; - - Data() {} - - gemmi::cif::Block &blk() { return doc->blocks[idx]; } - - // standalone read (Coot: `Data d; d.ReadMMCIFData(fname)`) — own a Document and - // point at its first block. Used for small-molecule CIFs. - int SetFlag(int /*flag*/) { return 0; } // parse flags are gemmi-internal — no-op - int ReadMMCIFData(cpstr fname) { - try { owned_doc.reset(new gemmi::cif::Document(gemmi::cif::read_file(fname ? fname : ""))); } - catch (const std::exception &) { return CIFRC_CantOpenFile; } - if (owned_doc->blocks.empty()) return CIFRC_NoDataLine; - doc = owned_doc.get(); idx = 0; cats_built = false; - return CIFRC_Ok; - } - // find the loop containing tags[0] (a null-terminated tag array; core-CIF flat - // tags). Binds the gemmi loop directly (cat="" so GetString uses full tags). - // Coot passes both `pstr[]` and `const char*[]`, so accept cpstr. - PLoop FindLoop(cpstr *tags) { - if (!tags || !tags[0]) return nullptr; - gemmi::cif::Loop *gl = blk().find_loop(tags[0]).get_loop(); - if (!gl) return nullptr; - loops.emplace_back(); - Loop &l = loops.back(); - l.owner = this; l.cat = ""; l.direct = gl; - return &l; - } - PLoop FindLoop(pstr *tags) { return FindLoop((cpstr *) tags); } - - void build_cats() { - if (cats_built) return; - cat_names = blk().get_mmcif_category_names(); // returns WITH trailing dot - cats_built = true; - } - - pstr GetDataName() { - sret.push_back(blk().name); - return (pstr) sret.back().c_str(); - } - void GetDataName(pstr &dname, bool /*Remove*/ = false) { - sret.push_back(blk().name); - dname = (pstr) sret.back().c_str(); - } - void PutDataName(cpstr dname) { blk().name = dname ? dname : ""; } - - int GetNumberOfCategories() { build_cats(); return (int) cat_names.size(); } - - PCategory GetCategory(int categoryNo) { - build_cats(); - if (categoryNo < 0 || (size_t) categoryNo >= cat_names.size()) return nullptr; - cats_pool.emplace_back(); - Category &c = cats_pool.back(); - c.cat = cat_names[categoryNo]; - gemmi::cif::Table t = blk().find_mmcif_category(c.cat); - c.kind = t.get_loop() ? MMCIF_Loop : MMCIF_Struct; - return &c; - } - - PLoop GetLoop(cpstr CName) { - std::string key = detail::with_dot(CName); - auto it = loop_by_cat.find(key); - if (it != loop_by_cat.end()) return it->second; - if (!blk().find_mmcif_category(key).get_loop()) return nullptr; // absent or a struct - loops.emplace_back(); - Loop &l = loops.back(); - l.owner = this; l.cat = key; l.write_mode = false; - loop_by_cat[key] = &l; - return &l; - } - - PStruct GetStructure(cpstr CName) { - std::string key = detail::with_dot(CName); - auto it = struct_by_cat.find(key); - if (it != struct_by_cat.end()) return it->second; - if (!blk().has_mmcif_category(key)) return nullptr; - if (blk().find_mmcif_category(key).get_loop()) return nullptr; // it's a loop - structs.emplace_back(); - Struct &s = structs.back(); - s.owner = this; s.cat = key; s.write_mode = false; - struct_by_cat[key] = &s; - return &s; - } - - int GetLoopLength(cpstr CName) { - PLoop l = GetLoop(CName); - return l ? l->GetLoopLength() : CIFRC_NoCategory; - } - - // full mmCIF tag from (CName, TName): if CName is empty, TName is already the - // full tag (small-molecule CIFs pass "" + "_cell_length_a"). - std::string full_tag(cpstr CName, cpstr TName) { - std::string t = TName ? TName : ""; - return (CName && CName[0]) ? detail::with_dot(CName) + t : t; - } - // struct-style direct access (Data::GetString(CName, TName, RC) etc.) - pstr GetString(cpstr CName, cpstr TName, int &RC) { - const std::string *v = blk().find_value(full_tag(CName, TName)); - if (!v) { RC = CIFRC_NoTag; return nullptr; } - RC = CIFRC_Ok; - if (gemmi::cif::is_null(*v)) return nullptr; - sret.push_back(gemmi::cif::as_string(*v)); - return (pstr) sret.back().c_str(); - } - // pstr& form: sets S to the value, returns a CIFRC code (Coot: ierr += ...) - int GetString(pstr &S, cpstr CName, cpstr TName, bool /*Remove*/ = false) { - int rc = 0; - S = GetString(CName, TName, rc); - return rc; - } - int GetReal(realtype &R, cpstr CName, cpstr TName, bool /*Remove*/ = false) { - R = 0; - const std::string *v = blk().find_value(full_tag(CName, TName)); - if (!v) return CIFRC_NoTag; - if (gemmi::cif::is_null(*v)) return CIFRC_NoData; - try { R = std::stod(gemmi::cif::as_string(*v)); } catch (...) { return CIFRC_WrongFormat; } - return CIFRC_Ok; - } - int GetInteger(int &I, cpstr CName, cpstr TName, bool /*Remove*/ = false) { - I = 0; - const std::string *v = blk().find_value(full_tag(CName, TName)); - if (!v) return CIFRC_NoTag; - if (gemmi::cif::is_null(*v)) return CIFRC_NoData; - try { I = std::stoi(gemmi::cif::as_string(*v)); } catch (...) { return CIFRC_WrongFormat; } - return CIFRC_Ok; - } - - int AddLoop(cpstr CName, PLoop &cifLoop) { - std::string key = detail::with_dot(CName); - auto it = loop_by_cat.find(key); - if (it != loop_by_cat.end()) { cifLoop = it->second; return CIFRC_Ok; } - loops.emplace_back(); - Loop &l = loops.back(); - l.owner = this; l.cat = key; l.write_mode = true; - loop_by_cat[key] = &l; - cifLoop = &l; - return CIFRC_Created; - } - int AddStructure(cpstr CName, PStruct &cifStruct) { - std::string key = detail::with_dot(CName); - auto it = struct_by_cat.find(key); - if (it != struct_by_cat.end()) { cifStruct = it->second; return CIFRC_Ok; } - structs.emplace_back(); - Struct &s = structs.back(); - s.owner = this; s.cat = key; s.write_mode = true; - struct_by_cat[key] = &s; - cifStruct = &s; - return CIFRC_Created; - } - - void flush() { - for (auto &l : loops) if (l.write_mode) l.flush(blk()); - for (auto &s : structs) if (s.write_mode) s.flush(blk()); - } -}; - -// ---- Loop methods that need a complete Data ----------------------------- -inline gemmi::cif::Loop *Loop::gloop() const { - if (direct) return direct; // FindLoop-bound (core CIF) - if (write_mode || !owner) return nullptr; - return owner->blk().find_mmcif_category(cat).get_loop(); -} - -inline pstr Loop::GetString(cpstr TName, int nrow, int &RC) { - gemmi::cif::Loop *g = gloop(); - if (!g) { RC = CIFRC_NotALoop; return nullptr; } - int col = g->find_tag(cat + TName); - if (col < 0) { RC = CIFRC_NoTag; return nullptr; } - if (nrow < 0 || (size_t) nrow >= g->length()) { RC = CIFRC_WrongIndex; return nullptr; } - const std::string &raw = g->val(nrow, col); - RC = CIFRC_Ok; - if (gemmi::cif::is_null(raw)) return nullptr; - sret.push_back(gemmi::cif::as_string(raw)); - return (pstr) sret.back().c_str(); -} -inline int Loop::GetReal(realtype &R, cpstr TName, int nrow, bool /*Remove*/) { - R = 0; - gemmi::cif::Loop *g = gloop(); - if (!g) return CIFRC_NotALoop; - int col = g->find_tag(cat + TName); - if (col < 0) return CIFRC_NoTag; - if (nrow < 0 || (size_t) nrow >= g->length()) return CIFRC_WrongIndex; - const std::string &raw = g->val(nrow, col); - if (gemmi::cif::is_null(raw)) return CIFRC_NoData; - try { R = std::stod(gemmi::cif::as_string(raw)); } catch (...) { return CIFRC_WrongFormat; } - return CIFRC_Ok; -} -inline int Loop::GetInteger(int &I, cpstr TName, int nrow, bool /*Remove*/) { - I = 0; - gemmi::cif::Loop *g = gloop(); - if (!g) return CIFRC_NotALoop; - int col = g->find_tag(cat + TName); - if (col < 0) return CIFRC_NoTag; - if (nrow < 0 || (size_t) nrow >= g->length()) return CIFRC_WrongIndex; - const std::string &raw = g->val(nrow, col); - if (gemmi::cif::is_null(raw)) return CIFRC_NoData; - try { I = std::stoi(gemmi::cif::as_string(raw)); } catch (...) { return CIFRC_WrongFormat; } - return CIFRC_Ok; -} -inline pstr Loop::GetTag(int tagNo) { - gemmi::cif::Loop *g = gloop(); - if (!g) { if (tagNo < 0 || (size_t) tagNo >= wtags.size()) return nullptr; - sret.push_back(wtags[tagNo]); return (pstr) sret.back().c_str(); } - if (tagNo < 0 || (size_t) tagNo >= g->tags.size()) return nullptr; - std::string t = g->tags[tagNo]; - if (t.size() > cat.size() && t.compare(0, cat.size(), cat) == 0) t = t.substr(cat.size()); - sret.push_back(t); - return (pstr) sret.back().c_str(); -} -inline pstr Loop::GetField(int rowNo, int tagNo) { - gemmi::cif::Loop *g = gloop(); - if (!g) return nullptr; - if (tagNo < 0 || (size_t) tagNo >= g->width()) return nullptr; - if (rowNo < 0 || (size_t) rowNo >= g->length()) return nullptr; - const std::string &raw = g->val(rowNo, tagNo); - if (gemmi::cif::is_null(raw)) return nullptr; - sret.push_back(gemmi::cif::as_string(raw)); - return (pstr) sret.back().c_str(); -} - -// ---- Struct methods that need a complete Data --------------------------- -inline std::vector Struct::collect_tags() { - std::vector out; - if (!owner) return out; - for (const gemmi::cif::Item &it : owner->blk().items) - if (it.type == gemmi::cif::ItemType::Pair && - it.pair[0].compare(0, cat.size(), cat) == 0) - out.push_back(it.pair[0].substr(cat.size())); - return out; -} -inline int Struct::GetNofTags() { return (int) collect_tags().size(); } -inline pstr Struct::GetTag(int tagNo) { - std::vector t = collect_tags(); - if (tagNo < 0 || (size_t) tagNo >= t.size()) return nullptr; - sret.push_back(t[tagNo]); - return (pstr) sret.back().c_str(); -} -inline pstr Struct::GetField(int tagNo) { - std::vector t = collect_tags(); - if (tagNo < 0 || (size_t) tagNo >= t.size()) return nullptr; - int rc = 0; - return GetString(t[tagNo].c_str(), rc); -} -inline pstr Struct::GetString(cpstr TName, int &RC) { - if (!owner) { RC = CIFRC_NoTag; return nullptr; } - const std::string *v = owner->blk().find_value(cat + TName); - if (!v) { RC = CIFRC_NoTag; return nullptr; } - RC = CIFRC_Ok; - if (gemmi::cif::is_null(*v)) return nullptr; - sret.push_back(gemmi::cif::as_string(*v)); - return (pstr) sret.back().c_str(); -} -inline int Struct::GetReal(realtype &R, cpstr TName, bool /*Remove*/) { - R = 0; - if (!owner) return CIFRC_NoTag; - const std::string *v = owner->blk().find_value(cat + TName); - if (!v) return CIFRC_NoTag; - if (gemmi::cif::is_null(*v)) return CIFRC_NoData; - try { R = std::stod(gemmi::cif::as_string(*v)); } catch (...) { return CIFRC_WrongFormat; } - return CIFRC_Ok; -} -inline int Struct::GetInteger(int &I, cpstr TName, bool /*Remove*/) { - I = 0; - if (!owner) return CIFRC_NoTag; - const std::string *v = owner->blk().find_value(cat + TName); - if (!v) return CIFRC_NoTag; - if (gemmi::cif::is_null(*v)) return CIFRC_NoData; - try { I = std::stoi(gemmi::cif::as_string(*v)); } catch (...) { return CIFRC_WrongFormat; } - return CIFRC_Ok; -} -inline void Struct::flush(gemmi::cif::Block &b) { - for (auto &tv : wpairs) - b.set_pair(cat + tv.first, gemmi::cif::quote(tv.second)); -} - -// ========================================================================= -// File (a whole CIF document) -// ========================================================================= -class File { - public: - gemmi::cif::Document doc; - std::deque datas; - std::deque sret; - - File() {} - - void rebuild() { - datas.clear(); - for (size_t i = 0; i < doc.blocks.size(); ++i) { - datas.emplace_back(); - datas.back().doc = &doc; - datas.back().idx = i; - } - } - - int ReadMMCIFFile(cpstr FName, int /*flags*/ = 0) { - try { doc = gemmi::cif::read_file(FName ? FName : ""); } - catch (const std::exception &) { return CIFRC_CantOpenFile; } - rebuild(); - return CIFRC_Ok; - } - - int WriteMMCIFFile(cpstr FName, int /*flags*/ = 0) { - for (auto &d : datas) d.flush(); - std::ofstream os(FName ? FName : ""); - if (!os) return CIFRC_CantOpenFile; - gemmi::cif::write_cif_to_stream(os, doc, gemmi::cif::WriteOptions()); - return 0; - } - - int GetNofData() { return (int) datas.size(); } - int GetNumberOfData() { return (int) datas.size(); } - - PData GetCIFData(int dataNo) { - if (dataNo < 0 || (size_t) dataNo >= datas.size()) return nullptr; - return &datas[dataNo]; - } - PData GetCIFData(cpstr name) { - std::string n(name ? name : ""); - for (auto &d : datas) - if (d.blk().name == n) return &d; - return nullptr; - } - - int AddCIFData(cpstr name) { - std::string n(name ? name : ""); - if (doc.find_block(n)) return CIFRC_Ok; - doc.add_new_block(n); - // index-based Data wrappers survive blocks-vector reallocation, so just - // append one for the new block (do NOT rebuild — that would drop buffered - // write state of earlier Data objects). - datas.emplace_back(); - datas.back().doc = &doc; - datas.back().idx = doc.blocks.size() - 1; - return CIFRC_Created; - } -}; - -// ---- free helpers -------------------------------------------------------- -inline pstr GetCIFMessage(pstr buffer, int rc) { - const char *m = "unknown mmCIF return code"; - switch (rc) { - case CIFRC_Ok: m = "no errors"; break; - case CIFRC_NoCategory: m = "category not found"; break; - case CIFRC_NoTag: m = "tag not found"; break; - case CIFRC_NoField: m = "field not found"; break; - case CIFRC_WrongFormat: m = "wrong value format"; break; - case CIFRC_WrongIndex: m = "row index out of range"; break; - case CIFRC_NotALoop: m = "category is not a loop"; break; - case CIFRC_NotAStructure: m = "category is not a structure"; break; - case CIFRC_NoData: m = "no data"; break; - case CIFRC_CantOpenFile: m = "cannot open file"; break; - case CIFRC_NoDataLine: m = "no data_ line"; break; - case CIFRC_Created: m = "category created"; break; - default: break; - } - std::strcpy(buffer, m); - return buffer; -} - -} // namespace mmcif + namespace mmcif { + + // ---- return codes (mirror mmdb_mmcif_.h) -------------------------------- + enum { + CIFRC_Loop = 2, + CIFRC_Structure = 1, + CIFRC_Ok = 0, + CIFRC_StructureNoTag = -1, + CIFRC_LoopNoTag = -2, + CIFRC_NoCategory = -3, + CIFRC_WrongFormat = -4, + CIFRC_NoTag = -5, + CIFRC_NotAStructure = -6, + CIFRC_NotALoop = -7, + CIFRC_WrongIndex = -8, + CIFRC_NoField = -9, + CIFRC_Created = -12, + CIFRC_CantOpenFile = -13, + CIFRC_NoDataLine = -14, + CIFRC_NoData = -15 + }; + + // ---- file flags ---------------------------------------------------------- + enum { + CIFFL_PrintWarnings = 0x00000001, + CIFFL_StopOnWarnings = 0x00000002, + CIFFL_SuggestCategories = 0x00000004, + CIFFL_SuggestTags = 0x00000008 + }; + + enum MMCIF_ITEM { + MMCIF_None = 0, + MMCIF_Struct = 1, + MMCIF_Loop = 2, + MMCIF_Data = 3, + MMCIF_Category = 4 + }; + + class Loop; + class Struct; + class Category; + class Data; + class File; + typedef Loop *PLoop; + typedef Struct *PStruct; + typedef Category *PCategory; + typedef Data *PData; + typedef File *PFile; + + namespace detail { + // MMDB category names have no trailing dot; gemmi wants "_cat." — normalise + // to WITH-dot internally so full tag = cat + subtag. + inline std::string with_dot(const char *cat) { + std::string s(cat ? cat : ""); + if (s.empty() || s.back() != '.') s += '.'; + return s; + } + inline std::string strip_dot(const std::string &s) { + if (!s.empty() && s.back() == '.') return s.substr(0, s.size() - 1); + return s; + } + } // namespace detail + + // ========================================================================= + // Category — just a named handle (Coot uses GetCategoryName / GetCategoryID) + // ========================================================================= + class Category { + public: + std::string cat; // WITH trailing dot + MMCIF_ITEM kind = MMCIF_Category; + std::deque sret; + Category() {} + pstr GetCategoryName() { + sret.push_back(detail::strip_dot(cat)); + return (pstr)sret.back().c_str(); + } + MMCIF_ITEM GetCategoryID() { return kind; } + }; + + // ========================================================================= + // Loop + // ========================================================================= + class Loop { + public: + Data *owner = nullptr; // null for a bare `new Loop` + std::string cat; // WITH trailing dot + gemmi::cif::Loop *direct = nullptr; // FindLoop binds the gemmi loop directly + bool write_mode = false; + // write buffer (row-major); sub-tags only (no category prefix) + std::vector wtags; + std::vector> wrows; + // storage for borrowed pstr returns (Coot never frees these) + std::deque sret; + + Loop() {} + + gemmi::cif::Loop *gloop() const; // read loop, or nullptr (defined after Data) + + int GetLoopLength(); + int GetNofTags(); + pstr GetTag(int tagNo); + pstr GetField(int rowNo, int tagNo); + + pstr GetString(cpstr TName, int nrow, int &RC); + int GetReal(realtype &R, cpstr TName, int nrow, bool Remove = false); + int GetInteger(int &I, cpstr TName, int nrow, bool Remove = false); + + void AddLoopTag(cpstr T, bool Remove = true) { + (void)Remove; + wcol(T, true); + } + void PutString(cpstr S, cpstr T, int nrow) { wput(T, nrow, S ? S : "."); } + void PutInteger(int I, cpstr T, int nrow) { wput(T, nrow, std::to_string(I)); } + void PutReal(realtype R, cpstr T, int nrow, int prec = 8) { + char b[64]; + std::snprintf(b, sizeof b, "%.*f", prec, (double)R); + wput(T, nrow, b); + } + void PutReal(realtype R, cpstr T, int nrow, cpstr /*format*/) { PutReal(R, T, nrow, 8); } + + // write helpers + int wcol(cpstr T, bool create); + void wput(cpstr T, int nrow, const std::string &val); + void flush(gemmi::cif::Block &b); + }; + + inline int Loop::wcol(cpstr T, bool create) { + for (size_t i = 0; i < wtags.size(); ++i) + if (wtags[i] == T) return (int)i; + if (!create) return -1; + wtags.push_back(T); + for (auto &row : wrows) row.resize(wtags.size()); + return (int)wtags.size() - 1; + } + + inline void Loop::wput(cpstr T, int nrow, const std::string &val) { + write_mode = true; + int col = wcol(T, true); + if (nrow < 0) nrow = 0; + while ((int)wrows.size() <= nrow) wrows.emplace_back(wtags.size()); + wrows[nrow][col] = val; + } + + inline void Loop::flush(gemmi::cif::Block &b) { + if (wtags.empty()) return; + gemmi::cif::Loop &gl = b.init_mmcif_loop(cat, wtags); // tags become cat+subtag + gl.values.clear(); + gl.values.reserve(wrows.size() * wtags.size()); + for (auto &row : wrows) + for (size_t c = 0; c < wtags.size(); ++c) { + const std::string &v = c < row.size() ? row[c] : std::string(); + gl.values.push_back(v.empty() ? "." : gemmi::cif::quote(v)); + } + } + + inline int Loop::GetLoopLength() { + gemmi::cif::Loop *g = gloop(); + return g ? (int)g->length() : (int)wrows.size(); + } + inline int Loop::GetNofTags() { + gemmi::cif::Loop *g = gloop(); + return g ? (int)g->width() : (int)wtags.size(); + } + + // ========================================================================= + // Struct (single-value category = a set of tag/value pairs) + // ========================================================================= + class Struct { + public: + Data *owner = nullptr; + std::string cat; // WITH trailing dot + bool write_mode = false; + std::vector> wpairs; + std::deque sret; + + Struct() {} + + pstr GetCategoryName() { + sret.push_back(detail::strip_dot(cat)); + return (pstr)sret.back().c_str(); + } + + int GetNofTags(); + pstr GetTag(int tagNo); + pstr GetField(int tagNo); + pstr GetString(cpstr TName, int &RC); + int GetReal(realtype &R, cpstr TName, bool Remove = false); + int GetInteger(int &I, cpstr TName, bool Remove = false); + + void PutString(cpstr S, cpstr TName, bool /*Concatenate*/ = false) { + write_mode = true; + wpairs.emplace_back(TName, S ? S : "."); + } + void PutReal(realtype R, cpstr TName, int prec = 8) { + char b[64]; + std::snprintf(b, sizeof b, "%.*f", prec, (double)R); + write_mode = true; + wpairs.emplace_back(TName, b); + } + void PutReal(realtype R, cpstr TName, cpstr /*format*/) { PutReal(R, TName, 8); } + void PutInteger(int I, cpstr TName) { + write_mode = true; + wpairs.emplace_back(TName, std::to_string(I)); + } + + std::vector collect_tags(); // read: sub-tags present in block + void flush(gemmi::cif::Block &b); + }; + + // ========================================================================= + // Data (a data_ block) + // ========================================================================= + class Data { + public: + gemmi::cif::Document *doc = nullptr; // resolve block by INDEX (blocks vector reallocs) + size_t idx = 0; + std::unique_ptr owned_doc; // for a standalone `new Data()` + + std::deque loops; + std::deque structs; + std::deque cats_pool; + std::unordered_map loop_by_cat; + std::unordered_map struct_by_cat; + std::vector cat_names; // WITH dot + bool cats_built = false; + std::deque sret; + + Data() {} + + gemmi::cif::Block &blk() { return doc->blocks[idx]; } + + // standalone read (Coot: `Data d; d.ReadMMCIFData(fname)`) — own a Document and + // point at its first block. Used for small-molecule CIFs. + int SetFlag(int /*flag*/) { return 0; } // parse flags are gemmi-internal — no-op + int ReadMMCIFData(cpstr fname) { + try { + owned_doc.reset(new gemmi::cif::Document(gemmi::cif::read_file(fname ? fname : ""))); + } catch (const std::exception &) { + return CIFRC_CantOpenFile; + } + if (owned_doc->blocks.empty()) return CIFRC_NoDataLine; + doc = owned_doc.get(); + idx = 0; + cats_built = false; + return CIFRC_Ok; + } + // find the loop containing tags[0] (a null-terminated tag array; core-CIF flat + // tags). Binds the gemmi loop directly (cat="" so GetString uses full tags). + // Coot passes both `pstr[]` and `const char*[]`, so accept cpstr. + PLoop FindLoop(cpstr *tags) { + if (!tags || !tags[0]) return nullptr; + gemmi::cif::Loop *gl = blk().find_loop(tags[0]).get_loop(); + if (!gl) return nullptr; + loops.emplace_back(); + Loop &l = loops.back(); + l.owner = this; + l.cat = ""; + l.direct = gl; + return &l; + } + PLoop FindLoop(pstr *tags) { return FindLoop((cpstr *)tags); } + + void build_cats() { + if (cats_built) return; + cat_names = blk().get_mmcif_category_names(); // returns WITH trailing dot + cats_built = true; + } + + pstr GetDataName() { + sret.push_back(blk().name); + return (pstr)sret.back().c_str(); + } + void GetDataName(pstr &dname, bool /*Remove*/ = false) { + sret.push_back(blk().name); + dname = (pstr)sret.back().c_str(); + } + void PutDataName(cpstr dname) { blk().name = dname ? dname : ""; } + + int GetNumberOfCategories() { + build_cats(); + return (int)cat_names.size(); + } + + PCategory GetCategory(int categoryNo) { + build_cats(); + if (categoryNo < 0 || (size_t)categoryNo >= cat_names.size()) return nullptr; + cats_pool.emplace_back(); + Category &c = cats_pool.back(); + c.cat = cat_names[categoryNo]; + gemmi::cif::Table t = blk().find_mmcif_category(c.cat); + c.kind = t.get_loop() ? MMCIF_Loop : MMCIF_Struct; + return &c; + } + + PLoop GetLoop(cpstr CName) { + std::string key = detail::with_dot(CName); + auto it = loop_by_cat.find(key); + if (it != loop_by_cat.end()) return it->second; + if (!blk().find_mmcif_category(key).get_loop()) return nullptr; // absent or a struct + loops.emplace_back(); + Loop &l = loops.back(); + l.owner = this; + l.cat = key; + l.write_mode = false; + loop_by_cat[key] = &l; + return &l; + } + + PStruct GetStructure(cpstr CName) { + std::string key = detail::with_dot(CName); + auto it = struct_by_cat.find(key); + if (it != struct_by_cat.end()) return it->second; + if (!blk().has_mmcif_category(key)) return nullptr; + if (blk().find_mmcif_category(key).get_loop()) return nullptr; // it's a loop + structs.emplace_back(); + Struct &s = structs.back(); + s.owner = this; + s.cat = key; + s.write_mode = false; + struct_by_cat[key] = &s; + return &s; + } + + int GetLoopLength(cpstr CName) { + PLoop l = GetLoop(CName); + return l ? l->GetLoopLength() : CIFRC_NoCategory; + } + + // full mmCIF tag from (CName, TName): if CName is empty, TName is already the + // full tag (small-molecule CIFs pass "" + "_cell_length_a"). + std::string full_tag(cpstr CName, cpstr TName) { + std::string t = TName ? TName : ""; + return (CName && CName[0]) ? detail::with_dot(CName) + t : t; + } + // struct-style direct access (Data::GetString(CName, TName, RC) etc.) + pstr GetString(cpstr CName, cpstr TName, int &RC) { + const std::string *v = blk().find_value(full_tag(CName, TName)); + if (!v) { + RC = CIFRC_NoTag; + return nullptr; + } + RC = CIFRC_Ok; + if (gemmi::cif::is_null(*v)) return nullptr; + sret.push_back(gemmi::cif::as_string(*v)); + return (pstr)sret.back().c_str(); + } + // pstr& form: sets S to the value, returns a CIFRC code (Coot: ierr += ...) + int GetString(pstr &S, cpstr CName, cpstr TName, bool /*Remove*/ = false) { + int rc = 0; + S = GetString(CName, TName, rc); + return rc; + } + int GetReal(realtype &R, cpstr CName, cpstr TName, bool /*Remove*/ = false) { + R = 0; + const std::string *v = blk().find_value(full_tag(CName, TName)); + if (!v) return CIFRC_NoTag; + if (gemmi::cif::is_null(*v)) return CIFRC_NoData; + try { + R = std::stod(gemmi::cif::as_string(*v)); + } catch (...) { + return CIFRC_WrongFormat; + } + return CIFRC_Ok; + } + int GetInteger(int &I, cpstr CName, cpstr TName, bool /*Remove*/ = false) { + I = 0; + const std::string *v = blk().find_value(full_tag(CName, TName)); + if (!v) return CIFRC_NoTag; + if (gemmi::cif::is_null(*v)) return CIFRC_NoData; + try { + I = std::stoi(gemmi::cif::as_string(*v)); + } catch (...) { + return CIFRC_WrongFormat; + } + return CIFRC_Ok; + } + + int AddLoop(cpstr CName, PLoop &cifLoop) { + std::string key = detail::with_dot(CName); + auto it = loop_by_cat.find(key); + if (it != loop_by_cat.end()) { + cifLoop = it->second; + return CIFRC_Ok; + } + loops.emplace_back(); + Loop &l = loops.back(); + l.owner = this; + l.cat = key; + l.write_mode = true; + loop_by_cat[key] = &l; + cifLoop = &l; + return CIFRC_Created; + } + int AddStructure(cpstr CName, PStruct &cifStruct) { + std::string key = detail::with_dot(CName); + auto it = struct_by_cat.find(key); + if (it != struct_by_cat.end()) { + cifStruct = it->second; + return CIFRC_Ok; + } + structs.emplace_back(); + Struct &s = structs.back(); + s.owner = this; + s.cat = key; + s.write_mode = true; + struct_by_cat[key] = &s; + cifStruct = &s; + return CIFRC_Created; + } + + void flush() { + for (auto &l : loops) + if (l.write_mode) l.flush(blk()); + for (auto &s : structs) + if (s.write_mode) s.flush(blk()); + } + }; + + // ---- Loop methods that need a complete Data ----------------------------- + inline gemmi::cif::Loop *Loop::gloop() const { + if (direct) return direct; // FindLoop-bound (core CIF) + if (write_mode || !owner) return nullptr; + return owner->blk().find_mmcif_category(cat).get_loop(); + } + + inline pstr Loop::GetString(cpstr TName, int nrow, int &RC) { + gemmi::cif::Loop *g = gloop(); + if (!g) { + RC = CIFRC_NotALoop; + return nullptr; + } + int col = g->find_tag(cat + TName); + if (col < 0) { + RC = CIFRC_NoTag; + return nullptr; + } + if (nrow < 0 || (size_t)nrow >= g->length()) { + RC = CIFRC_WrongIndex; + return nullptr; + } + const std::string &raw = g->val(nrow, col); + RC = CIFRC_Ok; + if (gemmi::cif::is_null(raw)) return nullptr; + sret.push_back(gemmi::cif::as_string(raw)); + return (pstr)sret.back().c_str(); + } + inline int Loop::GetReal(realtype &R, cpstr TName, int nrow, bool /*Remove*/) { + R = 0; + gemmi::cif::Loop *g = gloop(); + if (!g) return CIFRC_NotALoop; + int col = g->find_tag(cat + TName); + if (col < 0) return CIFRC_NoTag; + if (nrow < 0 || (size_t)nrow >= g->length()) return CIFRC_WrongIndex; + const std::string &raw = g->val(nrow, col); + if (gemmi::cif::is_null(raw)) return CIFRC_NoData; + try { + R = std::stod(gemmi::cif::as_string(raw)); + } catch (...) { + return CIFRC_WrongFormat; + } + return CIFRC_Ok; + } + inline int Loop::GetInteger(int &I, cpstr TName, int nrow, bool /*Remove*/) { + I = 0; + gemmi::cif::Loop *g = gloop(); + if (!g) return CIFRC_NotALoop; + int col = g->find_tag(cat + TName); + if (col < 0) return CIFRC_NoTag; + if (nrow < 0 || (size_t)nrow >= g->length()) return CIFRC_WrongIndex; + const std::string &raw = g->val(nrow, col); + if (gemmi::cif::is_null(raw)) return CIFRC_NoData; + try { + I = std::stoi(gemmi::cif::as_string(raw)); + } catch (...) { + return CIFRC_WrongFormat; + } + return CIFRC_Ok; + } + inline pstr Loop::GetTag(int tagNo) { + gemmi::cif::Loop *g = gloop(); + if (!g) { + if (tagNo < 0 || (size_t)tagNo >= wtags.size()) return nullptr; + sret.push_back(wtags[tagNo]); + return (pstr)sret.back().c_str(); + } + if (tagNo < 0 || (size_t)tagNo >= g->tags.size()) return nullptr; + std::string t = g->tags[tagNo]; + if (t.size() > cat.size() && t.compare(0, cat.size(), cat) == 0) t = t.substr(cat.size()); + sret.push_back(t); + return (pstr)sret.back().c_str(); + } + inline pstr Loop::GetField(int rowNo, int tagNo) { + gemmi::cif::Loop *g = gloop(); + if (!g) return nullptr; + if (tagNo < 0 || (size_t)tagNo >= g->width()) return nullptr; + if (rowNo < 0 || (size_t)rowNo >= g->length()) return nullptr; + const std::string &raw = g->val(rowNo, tagNo); + if (gemmi::cif::is_null(raw)) return nullptr; + sret.push_back(gemmi::cif::as_string(raw)); + return (pstr)sret.back().c_str(); + } + + // ---- Struct methods that need a complete Data --------------------------- + inline std::vector Struct::collect_tags() { + std::vector out; + if (!owner) return out; + for (const gemmi::cif::Item &it : owner->blk().items) + if (it.type == gemmi::cif::ItemType::Pair && + it.pair[0].compare(0, cat.size(), cat) == 0) + out.push_back(it.pair[0].substr(cat.size())); + return out; + } + inline int Struct::GetNofTags() { return (int)collect_tags().size(); } + inline pstr Struct::GetTag(int tagNo) { + std::vector t = collect_tags(); + if (tagNo < 0 || (size_t)tagNo >= t.size()) return nullptr; + sret.push_back(t[tagNo]); + return (pstr)sret.back().c_str(); + } + inline pstr Struct::GetField(int tagNo) { + std::vector t = collect_tags(); + if (tagNo < 0 || (size_t)tagNo >= t.size()) return nullptr; + int rc = 0; + return GetString(t[tagNo].c_str(), rc); + } + inline pstr Struct::GetString(cpstr TName, int &RC) { + if (!owner) { + RC = CIFRC_NoTag; + return nullptr; + } + const std::string *v = owner->blk().find_value(cat + TName); + if (!v) { + RC = CIFRC_NoTag; + return nullptr; + } + RC = CIFRC_Ok; + if (gemmi::cif::is_null(*v)) return nullptr; + sret.push_back(gemmi::cif::as_string(*v)); + return (pstr)sret.back().c_str(); + } + inline int Struct::GetReal(realtype &R, cpstr TName, bool /*Remove*/) { + R = 0; + if (!owner) return CIFRC_NoTag; + const std::string *v = owner->blk().find_value(cat + TName); + if (!v) return CIFRC_NoTag; + if (gemmi::cif::is_null(*v)) return CIFRC_NoData; + try { + R = std::stod(gemmi::cif::as_string(*v)); + } catch (...) { + return CIFRC_WrongFormat; + } + return CIFRC_Ok; + } + inline int Struct::GetInteger(int &I, cpstr TName, bool /*Remove*/) { + I = 0; + if (!owner) return CIFRC_NoTag; + const std::string *v = owner->blk().find_value(cat + TName); + if (!v) return CIFRC_NoTag; + if (gemmi::cif::is_null(*v)) return CIFRC_NoData; + try { + I = std::stoi(gemmi::cif::as_string(*v)); + } catch (...) { + return CIFRC_WrongFormat; + } + return CIFRC_Ok; + } + inline void Struct::flush(gemmi::cif::Block &b) { + for (auto &tv : wpairs) + b.set_pair(cat + tv.first, gemmi::cif::quote(tv.second)); + } + + // ========================================================================= + // File (a whole CIF document) + // ========================================================================= + class File { + public: + gemmi::cif::Document doc; + std::deque datas; + std::deque sret; + + File() {} + + void rebuild() { + datas.clear(); + for (size_t i = 0; i < doc.blocks.size(); ++i) { + datas.emplace_back(); + datas.back().doc = &doc; + datas.back().idx = i; + } + } + + int ReadMMCIFFile(cpstr FName, int /*flags*/ = 0) { + try { + doc = gemmi::cif::read_file(FName ? FName : ""); + } catch (const std::exception &) { + return CIFRC_CantOpenFile; + } + rebuild(); + return CIFRC_Ok; + } + + int WriteMMCIFFile(cpstr FName, int /*flags*/ = 0) { + for (auto &d : datas) d.flush(); + std::ofstream os(FName ? FName : ""); + if (!os) return CIFRC_CantOpenFile; + gemmi::cif::write_cif_to_stream(os, doc, gemmi::cif::WriteOptions()); + return 0; + } + + int GetNofData() { return (int)datas.size(); } + int GetNumberOfData() { return (int)datas.size(); } + + PData GetCIFData(int dataNo) { + if (dataNo < 0 || (size_t)dataNo >= datas.size()) return nullptr; + return &datas[dataNo]; + } + PData GetCIFData(cpstr name) { + std::string n(name ? name : ""); + for (auto &d : datas) + if (d.blk().name == n) return &d; + return nullptr; + } + + int AddCIFData(cpstr name) { + std::string n(name ? name : ""); + if (doc.find_block(n)) return CIFRC_Ok; + doc.add_new_block(n); + // index-based Data wrappers survive blocks-vector reallocation, so just + // append one for the new block (do NOT rebuild — that would drop buffered + // write state of earlier Data objects). + datas.emplace_back(); + datas.back().doc = &doc; + datas.back().idx = doc.blocks.size() - 1; + return CIFRC_Created; + } + }; + + // ---- free helpers -------------------------------------------------------- + inline pstr GetCIFMessage(pstr buffer, int rc) { + const char *m = "unknown mmCIF return code"; + switch (rc) { + case CIFRC_Ok: + m = "no errors"; + break; + case CIFRC_NoCategory: + m = "category not found"; + break; + case CIFRC_NoTag: + m = "tag not found"; + break; + case CIFRC_NoField: + m = "field not found"; + break; + case CIFRC_WrongFormat: + m = "wrong value format"; + break; + case CIFRC_WrongIndex: + m = "row index out of range"; + break; + case CIFRC_NotALoop: + m = "category is not a loop"; + break; + case CIFRC_NotAStructure: + m = "category is not a structure"; + break; + case CIFRC_NoData: + m = "no data"; + break; + case CIFRC_CantOpenFile: + m = "cannot open file"; + break; + case CIFRC_NoDataLine: + m = "no data_ line"; + break; + case CIFRC_Created: + m = "category created"; + break; + default: + break; + } + std::strcpy(buffer, m); + return buffer; + } + + } // namespace mmcif } // namespace mmdb #endif // COOT_MMDB_SHIM_MMCIF_IMPL_HH diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh index 5bac6a7b6c..5bb82f2ab0 100644 --- a/mmdb-shim/include/mmdb2/_shim_impl.hh +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -12,7 +12,7 @@ #include #include -#include // space-group / symmetry operators +#include // space-group / symmetry operators #include #include @@ -29,1855 +29,2391 @@ namespace mmdb { -// ---- basic MMDB scalar/typedefs (real MMDB: mmdb_mattype.h / mmdb_defs.h) ---- -typedef double realtype; -typedef char *pstr; -typedef const char *cpstr; -typedef unsigned short word; -typedef char AtomName[20]; -typedef char ResName[20]; -typedef char InsCode[10]; -typedef char ChainID[10]; -typedef char Element[10]; -typedef char AltLoc[20]; -typedef char SegID[10]; -typedef char LinkRID[20]; // Refmac link ID -typedef unsigned char byte; // mmdb_mattype.h -typedef int *ivector; // mmdb_mattype.h 1-based vectors/matrices -typedef realtype *rvector; -typedef ivector *imatrix; -typedef rvector *rmatrix; -typedef char maxMMDBName[40]; - -// WhatIsSet mask flags (mmdb_atom.h ASET_FLAG) -enum ASET_FLAG { - ASET_Coordinates = 0x00000001, ASET_Occupancy = 0x00000002, - ASET_tempFactor = 0x00000004, ASET_CoordSigma = 0x00000010, - ASET_OccSigma = 0x00000020, ASET_tFacSigma = 0x00000040, - ASET_Charge = 0x00000080, ASET_Anis_tFac = 0x00000100, - ASET_Anis_tFSigma = 0x00001000, ASET_All = 0x000FFFFF -}; - -// vector/matrix types (mmdb_defs.h) — plain fixed-size arrays of realtype -typedef realtype vect3[3]; -typedef realtype vect4[4]; -typedef vect3 mat33[3]; // realtype[3][3] -typedef vect4 mat44[4]; // realtype[4][4] -typedef mat44 *pmat44; -typedef mat44 &rmat44; - -enum ERROR_CODE { - Error_NoError = 0, - Error_CantOpenFile = 12, // matches real MMDB's value - Error_GeneralError1 = 1 -}; - -// ---- UDData (user-defined data) — real MMDB values (mmdb_uddata.h) ---- -enum UDR_TYPE { UDR_ATOM = 0, UDR_RESIDUE = 1, UDR_CHAIN = 2, UDR_MODEL = 3, - UDR_HIERARCHY = 4 }; -enum UDDATA_CODE { UDDATA_Ok = 0, UDDATA_WrongHandle = -1, - UDDATA_WrongUDRType = -2, UDDATA_NoData = -3 }; - -// ---- Selection (real MMDB values: mmdb_selmngr.h) ---- -enum SELECTION_TYPE { STYPE_INVALID = -1, STYPE_UNDEFINED = 0, STYPE_ATOM = 1, - STYPE_RESIDUE = 2, STYPE_CHAIN = 3, STYPE_MODEL = 4 }; -enum SELECTION_KEY { SKEY_NEW = 0, SKEY_OR = 1, SKEY_AND = 2, SKEY_XOR = 3, - SKEY_CLR = 4, SKEY_XAND = 100 }; -inline const long int MinInt4 = -2147483647; -inline const long int MaxInt4 = 2147483647; -inline const int ANY_RES = -2147483647; // real MMDB: extern const == MinInt4 -inline const double Pi = 3.14159265358979323846; - -// PDB/CIF read flags (mmdb_io_file.h). Values are arbitrary distinct bits — the -// shim's SetFlag is a no-op, so only distinctness matters for Coot's bit ops. -enum MMDB_READ_FLAG { - MMDBF_AutoSerials = 0x00000001, - MMDBF_IgnoreDuplSeqNum = 0x00000002, - MMDBF_IgnoreBlankLines = 0x00000004, - MMDBF_IgnoreRemarks = 0x00000008, - MMDBF_IgnoreHash = 0x00000010, - MMDBF_IgnoreNonCoorPDBErrors = 0x00000020, - MMDBF_PrintCIFWarnings = 0x00000040, - MMDBF_All = 0x0000FFFF -}; -enum MMDB_FCM { MMDBFCM_None = 0, MMDBFCM_All = 1, MMDBFCM_Coord = 2, - MMDBFCM_Cryst = 4, MMDBFCM_SC = 8 }; -typedef int COPY_MASK; // Coot uses `COPY_MASK cm = MMDBFCM_All` + bit arithmetic - -// Per-object UDData slots + selection membership bits. Each registered UDData -// handle maps to a (type,kind,slot); the object stores contiguous vectors -// indexed by slot. `_inSel[selHnd-1]` = is this object in selection selHnd -// (maintained by Manager::Select/SelectSphere/DeleteSelection). -struct UDStore { - std::vector _udi; - std::vector _udr; - std::vector _uds; - std::vector _inSel; - bool isInSelection(int selHnd) const { - return selHnd >= 1 && selHnd <= (int)_inSel.size() && _inSel[selHnd - 1]; - } - void _setInSel(int selHnd, bool v) { - if ((int)_inSel.size() < selHnd) _inSel.resize(selHnd, false); - _inSel[selHnd - 1] = v; - } -}; - -class Atom; class Residue; class Chain; class Model; class Manager; -typedef Atom *PAtom; typedef Atom **PPAtom; -typedef Residue *PResidue; typedef Residue **PPResidue; -typedef Chain *PChain; typedef Chain **PPChain; -typedef Model *PModel; typedef Model **PPModel; -typedef Manager *PManager; typedef Manager **PPManager; - -struct Contact { int id1, id2; long group; realtype dist; }; -typedef Contact *PContact; - -// base for records held in MMDB containers (Title compound/author, LINK, …) -class ContainerClass { public: virtual ~ContainerClass() {} }; -typedef ContainerClass *PContainerClass; - -// LINK record. Public data members mirror real MMDB (Coot reads them directly). -// Populated from gemmi Structure::connections on load (Manager::_load_metadata); -// Coot-created links are appended via Model::AddLink. -class Link : public ContainerClass { -public: - AtomName atName1{}, atName2{}; - AltLoc aloc1{}, aloc2{}; - ResName resName1{}, resName2{}; - ChainID chainID1{}, chainID2{}; - InsCode insCode1{}, insCode2{}; - int seqNum1 = 0, seqNum2 = 0; - int s1 = 1, i1 = 0, j1 = 0, k1 = 0; // symmetry id of 1st atom - int s2 = 1, i2 = 0, j2 = 0, k2 = 0; // symmetry id of 2nd atom - realtype dist = 0; - void Copy(PContainerClass o) { if (auto *l = dynamic_cast(o)) *this = *l; } -}; -typedef Link *PLink; typedef Link **PPLink; - -// Refmac LINK record (mmdb_model.h LinkR). Public members mirror real MMDB; -// populated from gemmi Connections carrying a link_id (Manager::_load_metadata). -class LinkR { -public: - LinkRID linkRID{}; - AtomName atName1{}, atName2{}; - AltLoc aloc1{}, aloc2{}; - ResName resName1{}, resName2{}; - ChainID chainID1{}, chainID2{}; - int seqNum1 = 0, seqNum2 = 0; - InsCode insCode1{}, insCode2{}; - realtype dist = 0; -}; -typedef LinkR *PLinkR; typedef LinkR **PPLinkR; - -// CIS-peptide record (mmdb_model.h CisPep). Public members mirror real MMDB; -// populated from gemmi Structure::cispeps on load (Manager::_load_metadata). -class CisPep { -public: - int serNum = 0; - ResName pep1{}; - ChainID chainID1{}; - int seqNum1 = 0; - InsCode icode1{}; - ResName pep2{}; - ChainID chainID2{}; - int seqNum2 = 0; - InsCode icode2{}; - int modNum = 0; - realtype measure = 0; -}; -typedef CisPep *PCisPep; - -// Container of LINK records (mmdb_model.h LinkContainer). Minimal: Coot only -// declares `empty_links_container()` returning one by value; never dereferenced. -class LinkContainer { -public: - std::vector data; - int Length() { return (int)data.size(); } - PContainerClass GetContainerClass(int i) { return (i >= 0 && i < (int)data.size()) ? data[i] : nullptr; } -}; -typedef LinkContainer *PLinkContainer; - -// PDB title records (mmdb_title.h). Coot subclasses Manager & Title to reach the -// COMPND/AUTHOR line containers. The AUTHOR container is filled from gemmi -// meta.authors on load and the TITLE string comes from Structure::get_info -// ("_struct.title"); COMPND/JRNL have no structured gemmi home, so those -// containers stay empty. -class Compound : public ContainerClass { public: char Line[256] = {0}; }; -typedef Compound *PCompound; -class Author : public ContainerClass { public: char Line[256] = {0}; }; -typedef Author *PAuthor; -class Journal : public ContainerClass { public: char Line[256] = {0}; }; -typedef Journal *PJournal; -class TitleContainer { -public: - std::vector data; - int Length() { return (int)data.size(); } - PContainerClass GetContainerClass(int i) { - return (i >= 0 && i < (int)data.size()) ? data[i] : nullptr; - } -}; -class Title { -public: - TitleContainer compound, author, journal; // public so Coot's access_title can reach them - TitleContainer *GetCompound() { return &compound; } // real Title exposes these - TitleContainer *GetAuthor() { return &author; } // publicly; access_title - TitleContainer *GetJournal() { return &journal; } // inherits GetJournal() -}; - -// gzip mode flag (mmdb_io_file.h). Minimal mmdb::io — the shim does I/O via gemmi, -// so only this compression-mode enum is provided (Coot passes it to write calls). -namespace io { enum GZ_MODE { GZM_NONE = 0, GZM_CHECK = 1, GZM_ENFORCE = 2 }; } - -// initialise a 4x4 matrix to identity (mmdb_mattype.h Mat4Init) -inline void Mat4Init(mat44 &A) { - for (int i = 0; i < 4; ++i) - for (int j = 0; j < 4; ++j) A[i][j] = (i == j) ? 1.0 : 0.0; -} - -// Orthogonal symmetry transformation for operator Nop (0-based) + integer cell -// shifts, from a gemmi cell + space group. The op acts in fractional space; we -// conjugate it with the cell frac<->orth transforms so TMatrix maps orthogonal -// coordinates directly (MMDB semantics). Returns 0 on success, 1 if there is no -// usable space group / the operator is out of range. Shared by Manager and Cryst. -inline int gemmi_sym_tmatrix(const gemmi::UnitCell &cell, const std::string &sg_name, - mat44 &TMatrix, int Nop, int a, int b, int c) { - Mat4Init(TMatrix); - const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(sg_name); - if (!sg || !cell.is_crystal()) return 1; - gemmi::GroupOps gops = sg->operations(); - if (Nop < 0 || Nop >= (int) gops.order()) return 1; - int i = 0; gemmi::Op op; - for (gemmi::Op o : gops) { if (i++ == Nop) { op = o; break; } } - gemmi::Transform sym{ gemmi::rot_as_mat33(op), - gemmi::tran_as_vec3(op) + gemmi::Vec3(a, b, c) }; - gemmi::Transform t = cell.orth.combine(sym).combine(cell.frac); - for (int r = 0; r < 3; ++r) { - for (int cc = 0; cc < 3; ++cc) TMatrix[r][cc] = t.mat.a[r][cc]; - TMatrix[r][3] = t.vec.at(r); - } - return 0; -} - -// Crystal/symmetry record (mmdb_cryst.h). Holds a gemmi cell + space-group name -// and computes symmetry through the shared helper — same result as Manager for a -// populated Cryst (Manager is the usual live symmetry path). -class Cryst { public: - gemmi::UnitCell cell; - std::string spaceGroup; - virtual ~Cryst() {} - int GetTMatrix(mat44 &T, int Nop, int a, int b, int c) { - return gemmi_sym_tmatrix(cell, spaceGroup, T, Nop, a, b, c); - } - int GetNumberOfSymOps() { - const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(spaceGroup); - return sg ? (int) sg->operations().order() : 0; - } - pstr GetSymOp(int Nop) { - const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(spaceGroup); - if (!sg) return nullptr; - int i = 0; - for (gemmi::Op op : sg->operations()) - if (i++ == Nop) { _symop_buf = op.triplet(); return (pstr) _symop_buf.c_str(); } - return nullptr; - } -private: - std::string _symop_buf; -}; -typedef Cryst *PCryst; - -// mmdb::math graph-matching subsystem — full classes defined in _graph_impl.hh -// (included at end of this file, after Atom/Residue are complete). Only the -// Alignment class (unused by the cootapi build) stays a forward decl. -namespace math { class Alignment; } - -struct AtomBond { PAtom atom = nullptr; int order = 0; }; -typedef AtomBond *PAtomBond; typedef AtomBond **PPAtomBond; - -struct AtomStat { // selection coordinate statistics (mmdb_atom.h) - int nAtoms = 0; - realtype xmin = 0, ymin = 0, zmin = 0, xmax = 0, ymax = 0, zmax = 0; - realtype xm = 0, ym = 0, zm = 0; // coordinate means (centroid) - realtype GetMaxSize() { - realtype dx = xmax - xmin, dy = ymax - ymin, dz = zmax - zmin; - return dx > dy ? (dx > dz ? dx : dz) : (dy > dz ? dy : dz); - } -}; -typedef AtomStat &RAtomStat; - -// secondary-structure element codes (mmdb_tables.h) -enum SSE_CODE { SSE_None = 0, SSE_Strand = 1, SSE_Bulge = 2, SSE_3Turn = 3, - SSE_4Turn = 4, SSE_5Turn = 5, SSE_Helix = 6 }; - -// PDBCleanup flags (mmdb_root.h) — bit flags OR'd into PDBCleanup(word) -// misc return-code / sort-key enums (mmdb_cryst.h / mmdb_selmngr.h / mmdb_tables.h) -enum { SYMOP_Ok = 0, SYMOP_NoLibFile = -1, SYMOP_UnknownSpaceGroup = -2 }; -enum { SSERC_Ok = 0, SSERC_noResidues = 1 }; -enum { SORT_CHAIN_ChainID_Asc = 0, SORT_CHAIN_ChainID_Desc = 1 }; -enum { CNSORT_OFF = 0, CNSORT_1INC = 1, CNSORT_1DEC = 2, CNSORT_2INC = 3, CNSORT_2DEC = 4 }; - -enum PDB_CLEAN_FLAG { - PDBCLEAN_ATNAME = 0x00000001, - PDBCLEAN_TER = 0x00000002, - PDBCLEAN_CHAIN = 0x00000004, - PDBCLEAN_CHAIN_STRONG = 0x00000008, - PDBCLEAN_ALTCODE = 0x00000010, - PDBCLEAN_ALTCODE_STRONG = 0x00000020, - PDBCLEAN_SERIAL = 0x00000040, - PDBCLEAN_SEQNUM = 0x00000080, - PDBCLEAN_INDEX = 0x00000800, - PDBCLEAN_ELEMENT = 0x00001000, - PDBCLEAN_ELEMENT_STRONG = 0x00002000 -}; - -// SS records — public-member structs. Model::GetNumberOf{Helices,Sheets} are -// populated from gemmi Structure::{helices,sheets} on load (_load_metadata) and -// also fillable by Coot's own SS computation via the access_model subclass. -class Helix { public: - ChainID initChainID{}, endChainID{}; int initSeqNum = 0, endSeqNum = 0, serNum = 0, helixClass = 0, length = 0; - ResName initResName{}, endResName{}; InsCode initICode{}, endICode{}; char helixID[20]{}, comment[80]{}; -}; -class Strand { public: - ChainID initChainID{}, endChainID{}; int initSeqNum = 0, endSeqNum = 0, strandNo = 0, sense = 0; - ResName initResName{}, endResName{}; InsCode initICode{}, endICode{}; char sheetID[20]{}; -}; -class Sheet { public: int nStrands = 0; Strand **strand = nullptr; char sheetID[20]{}; }; -class Sheets { public: int nSheets = 0; Sheet **sheet = nullptr; }; // filled from gemmi in _load_metadata -typedef Helix *PHelix; typedef Strand *PStrand; typedef Sheet *PSheet; typedef Sheets *PSheets; -// container of helices (Model.helices); Coot's access_model subclass fills it. -class Helices { public: std::vector data; void AddData(PHelix h) { if (h) data.push_back(h); } int nHelices = 0; }; - -// container of symmetry operators (mmdb_symop.h SymOps). Coot fills it from a -// space group; ops are xyz-triplet strings. -class SymOps { - std::vector ops; - std::deque buf; -public: - int AddSymOp(cpstr xyz) { ops.push_back(xyz ? xyz : ""); return 0; } - int GetNofSymOps() { return (int)ops.size(); } - pstr GetSymOp(int n) { - if (n < 0 || n >= (int)ops.size()) return nullptr; - buf.push_back(ops[n]); return (pstr) buf.back().c_str(); - } - void FreeMemory() { ops.clear(); } -}; - -[[noreturn]] inline void unimpl(const char *w) { - throw std::logic_error(std::string("mmdb-shim: unimplemented: ") + w); -} - -// ---- free functions (mmdb_tables.h / mmdb_mattype.h) ---- -inline void InitMatType() {} // real MMDB inits static matrix-type tables; no-op here -inline cpstr GetErrorDescription(ERROR_CODE ec) { - switch (ec) { - case Error_NoError: return "no error"; - case Error_CantOpenFile: return "cannot open file"; - default: return "MMDB error"; - } -} -inline realtype getVdWaalsRadius(cpstr element) { - return gemmi::Element(element ? element : "X").vdw_r(); -} - -// UDData helpers (defined after Manager); each class forwards with its UDR type. -int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int v); -int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype v); -int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, cpstr v); -int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int &v); -int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype &v); -int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, pstr &v); - -// =========================================================================== -class Atom : public UDStore { -public: - Manager *mgr = nullptr; - Residue *res = nullptr; // parent; null => detached (use _local) - int ai = 0; // cached index within parent residue's atoms - bool alive = true; - gemmi::Atom _local; // backing store while detached (see g() resolvers) - int Het = 0; // heteroatom flag (MMDB public field; Coot sets it) - int Ter = 0; // chain-terminator flag (gemmi has none -> always 0) - word WhatIsSet = 0; // ASET_* mask; ASET_Anis_tFac set on load if aniso present - AtomName label_atom_id{}; // mmcif label_atom_id (shim-owned; Coot sets on build) - - Atom() = default; - explicit Atom(Residue *r); // construct + add to residue (out-of-line) - - gemmi::Atom &g() const; // resolve to live gemmi (defined after Manager) - - // --- rewritten field accessors (pure B) --- - // Scalar fields -> reference-returning accessors, so a uniform `->field`-> - // `->field()` rewrite covers both reads and writes. (occ/b_iso/charge are - // narrower than realtype in gemmi, so those refs are float/schar-typed — the - // rare take-address-of-realtype sites surface at Coot build time.) - // non-const (writable ref) + const (by value) overloads, so reads work on a - // `const mmdb::Atom` and writes work through `->x() = v` on a non-const one. - realtype &x() { return g().pos.x; } realtype x() const { return g().pos.x; } - realtype &y() { return g().pos.y; } realtype y() const { return g().pos.y; } - realtype &z() { return g().pos.z; } realtype z() const { return g().pos.z; } - float &occupancy() { return g().occ; } float occupancy() const { return g().occ; } - float &tempFactor() { return g().b_iso; } float tempFactor() const { return g().b_iso; } - signed char &charge() { return g().charge; } signed char charge() const { return g().charge; } - int &serNum() { return g().serial; } int serNum() const { return g().serial; } - // altLoc is a char[] (C-string) in MMDB; gemmi stores a single char. Return a - // buffer-backed C-string ("" when unset) so strcmp/strcpy-style code works. - // The non-const overload returns a WRITABLE buffer so `strncpy(at->altLoc(),..)` - // compiles; the buffer's first char is pushed back into gemmi by Residue::AddAtom - // (the buffer is refreshed from gemmi on entry, so reads stay correct). - pstr altLoc() { _altloc_buf[0] = g().altloc; _altloc_buf[1] = '\0'; return _altloc_buf; } - const char *altLoc() const { _altloc_buf[0] = g().altloc; _altloc_buf[1] = '\0'; return _altloc_buf; } - void set_occupancy(realtype v) { g().occ = (float)v; } - void set_tempFactor(realtype v) { g().b_iso = (float)v; } - void set_altLoc(char c) { g().altloc = c; } - void SetCharge(realtype ch) { g().charge = (signed char) ch; } - // coordinate/occupancy/B ESDs (MMDB public fields) — gemmi has none, so shim- - // owned; reference-returning so the rewritten `->sigX` covers reads and writes. - float &sigX() { return _sigx; } float &sigY() { return _sigy; } - float &sigZ() { return _sigz; } float &sigOcc() { return _sigocc; } - float &sigTemp() { return _sigtemp; } - bool isMetal() const { return gemmi::Element(g().element).is_metal(); } - // anisotropic B tensor — gemmi's SMat33 aniso. Reference-returning so the - // rewritten `->u11` covers both reads and writes. The mutable accessor marks the - // tensor present (ASET_Anis_tFac) so a write (e.g. SHELX import) sets the flag as - // real MMDB does. Const reads never set it; a non-const read over-approximates, - // which is harmless — the PDB/mmCIF writer emits ANISOU on the actual values. - float &u11() { WhatIsSet |= ASET_Anis_tFac; return g().aniso.u11; } - float &u22() { WhatIsSet |= ASET_Anis_tFac; return g().aniso.u22; } - float &u33() { WhatIsSet |= ASET_Anis_tFac; return g().aniso.u33; } - float &u12() { WhatIsSet |= ASET_Anis_tFac; return g().aniso.u12; } - float &u13() { WhatIsSet |= ASET_Anis_tFac; return g().aniso.u13; } - float &u23() { WhatIsSet |= ASET_Anis_tFac; return g().aniso.u23; } - float u11() const { return g().aniso.u11; } float u22() const { return g().aniso.u22; } - float u33() const { return g().aniso.u33; } float u12() const { return g().aniso.u12; } - float u13() const { return g().aniso.u13; } float u23() const { return g().aniso.u23; } - // bonds — not modelled yet (gemmi connections); report none. - int GetNBonds() { return 0; } - void GetBonds(PAtomBond &atomBond, int &n) { atomBond = nullptr; n = 0; } - int AddBond(PAtom /*a*/, int /*order*/, int /*nAdd*/ = 1) { return 0; } - SegID segID{}; // shim-owned (gemmi has no segID); MMDB public char[] field - - // --- method surface (hot subset; rest stubbed) --- - pstr GetAtomName() const; // aligned name, MMDB semantics (const: called on const Atom) - void SetAtomName(const AtomName aName); - pstr GetElementName(); - void SetElementName(const Element elName); - pstr GetChainID(); - int GetSeqNum(); - pstr GetInsCode(); - pstr GetResName(); - Residue *&GetResidue() { return res; } // ref: rewritten `->residue` is assignable - void SetResidue(Residue *r) { res = r; } - Chain *GetChain(); // out-of-line (needs complete Residue/Chain) - Model *GetModel(); // out-of-line - int GetModelNum(); - // residue-delegating accessors (bound by the Python API); out-of-line. - pstr GetLabelCompID(); pstr GetLabelAsymID(); - int GetLabelSeqID(); int GetLabelEntityID(); - int GetResidueNo(); int GetSSEType(); - bool isSolvent(); bool isNTerminus(); bool isCTerminus(); - bool isTer() const { return false; } // gemmi has no TER atoms; see notes - void SetCoordinates(realtype xx, realtype yy, realtype zz, - realtype occ, realtype tF); - int GetIndex(); - void MakeTer() { Ter = 1; } // mark as chain terminator - pstr GetAtomID(pstr S); // "/mdl/chain/seq(res).ins/name[elem]:alt" (out-of-line) - int GetUDData(int h, pstr &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } - // copy another atom's data into this one (mmdb Atom::Copy — no hierarchy refs) - void Copy(PAtom a) { - g() = a->g(); - Het = a->Het; WhatIsSet = a->WhatIsSet; - std::memcpy(segID, a->segID, sizeof segID); - } - // apply a 4x4 (rot+trans) or 3x3+vec to the coordinates (mmdb Atom::Transform) - void Transform(const mat44 &tm) { - gemmi::Position &p = g().pos; double x = p.x, y = p.y, z = p.z; - p.x = tm[0][0]*x + tm[0][1]*y + tm[0][2]*z + tm[0][3]; - p.y = tm[1][0]*x + tm[1][1]*y + tm[1][2]*z + tm[1][3]; - p.z = tm[2][0]*x + tm[2][1]*y + tm[2][2]*z + tm[2][3]; - } - void Transform(const mat33 &tm, vect3 &v) { - gemmi::Position &p = g().pos; double x = p.x, y = p.y, z = p.z; - p.x = tm[0][0]*x + tm[0][1]*y + tm[0][2]*z + v[0]; - p.y = tm[1][0]*x + tm[1][1]*y + tm[1][2]*z + v[1]; - p.z = tm[2][0]*x + tm[2][1]*y + tm[2][2]*z + v[2]; - } - // UDData - int PutUDData(int h, int v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } - int PutUDData(int h, realtype v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } - int PutUDData(int h, cpstr v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } - int GetUDData(int h, int &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } - int GetUDData(int h, realtype &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } - -private: - friend class Residue; // AddAtom pushes the strncpy'd altLoc buffer to gemmi - mutable AtomName _name_buf{}; Element _elem_buf{}; mutable char _altloc_buf[4]{}; - float _sigx = 0, _sigy = 0, _sigz = 0, _sigocc = 0, _sigtemp = 0; -}; - -// =========================================================================== -class Residue : public UDStore { -public: - Manager *mgr = nullptr; - Chain *chain = nullptr; // parent; null => detached (use _local) - int ri = 0; - bool alive = true; - gemmi::Residue _local; // backing store while detached - std::vector atoms; // canonical child wrappers == PPAtom table - PPAtom atom = nullptr; // MMDB public atom-table field; kept = atoms.data() - int nAtoms = 0; // MMDB public field; kept = atoms.size() - void _sync_atom() { atom = atoms.data(); nAtoms = (int)atoms.size(); } - // mmcif label_* (shim-owned; Coot sets when building dictionary residues) - ResName label_comp_id{}; ChainID label_asym_id{}; int label_seq_id = 0, label_entity_id = 0; - pstr GetLabelCompID() { return label_comp_id; } - pstr GetLabelAsymID() { return label_asym_id; } - int GetLabelSeqID() { return label_seq_id; } - int GetLabelEntityID() { return label_entity_id; } - int GetResidueNo() { return ri; } // 0-based index within its chain - int GetNofAltLocations() { // distinct non-blank altLocs - std::set a; for (Atom *at : atoms) { char c = at->g().altloc; if (c && c != ' ') a.insert(c); } - return a.empty() ? 1 : (int) a.size(); - } - // sugar / modified-residue classification via gemmi's tabulated residues. - bool isSugar() { - gemmi::ResidueKind k = gemmi::find_tabulated_residue(g().name).kind; - return k == gemmi::ResidueKind::PYR || k == gemmi::ResidueKind::KET; - } - // MMDB isModRes reflects PDB MODRES records (a non-standard, modified form of a - // standard residue). gemmi has no per-residue MODRES flag on the model tree, so - // approximate: an amino/nucleic residue whose one-letter code is lower-case - // (gemmi marks non-standard monomers that way). Water/ligands are excluded. - bool isModRes() { - const gemmi::ResidueInfo ri = gemmi::find_tabulated_residue(g().name); - return ri.found() && !ri.is_standard() && - (ri.is_amino_acid() || ri.is_nucleic_acid()); - } - - Residue() = default; - explicit Residue(Chain *c); // construct + add to chain (out-of-line) - - // MMDB public char-array fields. Coot reads `residue->name` and writes - // `strncpy(residue->insCode,..)`. Kept as the interface: synced gemmi->buffer on - // load (_load_id, in build_from_gemmi) and buffer->gemmi at the adopt point - // (_store_id, in Chain::Add/InsResidue). SetResName/SetResID keep both in step. - ResName name{}; - InsCode insCode{}; - void _load_id() { - std::snprintf(name, sizeof name, "%s", g().name.c_str()); - insCode[0] = g().seqid.icode && g().seqid.icode != ' ' ? g().seqid.icode : '\0'; - insCode[1] = '\0'; - } - void _store_id() { - g().name = name; - g().seqid.icode = insCode[0] ? insCode[0] : ' '; - } - - gemmi::Residue &g() const; - - int GetNumberOfAtoms() { return (int)atoms.size(); } - int GetNumberOfAtoms(bool /*countTers*/) { return (int)atoms.size(); } - PAtom GetAtom(int atomNo) { - return (atomNo >= 0 && atomNo < (int)atoms.size()) ? atoms[atomNo] : nullptr; - } - PAtom GetAtom(const AtomName aname, const Element elname = nullptr, - const AltLoc aloc = nullptr); - void GetAtomTable(PPAtom &atomTable, int &n) { atomTable = atoms.data(); n = (int)atoms.size(); } - PAtom AddAtom(Manager &m, gemmi::Atom a); // append: O(1) - // Adopt a detached atom (Coot's `new mmdb::Atom` idiom). Copies the atom's - // local gemmi into this residue's gemmi (detached or bound, via g()) and - // rebinds the wrapper. Pushes the strncpy'd altLoc buffer back into gemmi. - int AddAtom(PAtom atm) { - g().atoms.push_back(atm->_local); - atm->res = this; atm->mgr = mgr; atm->ai = (int)atoms.size(); - if (atm->_altloc_buf[0]) g().atoms[atm->ai].altloc = atm->_altloc_buf[0]; - atoms.push_back(atm); - _sync_atom(); - return 0; - } - void DeleteAtom(int pos); - void TrimAtomTable() {} // compact after deletions — shim keeps them in sync - - pstr GetResName(); - void SetResName(const ResName n) { - g().name = n ? n : ""; - std::snprintf(name, sizeof name, "%s", n ? n : ""); - } - void SetResID(const ResName resName, int seqNo, const InsCode ic) { - g().name = resName ? resName : ""; - g().seqid.num.value = seqNo; - g().seqid.icode = (ic && ic[0]) ? ic[0] : ' '; - std::snprintf(name, sizeof name, "%s", resName ? resName : ""); - insCode[0] = (ic && ic[0]) ? ic[0] : '\0'; insCode[1] = '\0'; - } - int &GetSeqNum(); // writable (rewrite maps `->seqNum` reads and writes) - pstr GetInsCode(); - pstr GetChainID(); - int GetModelNum(); - int &GetIndex() { return ri; } // ref: rewritten `->index` is assignable - Chain *GetChain() { return chain; } - Model *GetModel(); // out-of-line (Chain incomplete here) - // terminus tests — peptide-bond-aware: N-terminus if no preceding residue's C is - // within bonding distance of this N, C-terminus if this C bonds no following N - // (out-of-line: need Chain + backbone atom geometry). - bool isNTerminus(); - bool isCTerminus(); - pstr GetResidueID(pstr S) { // "seqnum(name):inscode" - if (S) std::snprintf(S, 100, "%d(%s):%s", GetSeqNum(), name, insCode); - return S; - } - Residue *next = nullptr; // MMDB has this; wired lazily if needed - int SSE = SSE_None; // secondary-structure element (shim-owned public field) - bool isAminoacid() { return gemmi::find_tabulated_residue(g().name).is_amino_acid(); } - bool isNucleotide() { return gemmi::find_tabulated_residue(g().name).is_nucleic_acid(); } - bool isDNARNA() { return isNucleotide(); } - bool isSolvent() { return gemmi::find_tabulated_residue(g().name).is_water(); } - // UDData - int PutUDData(int h, int v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } - int PutUDData(int h, realtype v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } - int PutUDData(int h, cpstr v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } - int GetUDData(int h, int &v) { return ud_get(mgr, UDR_RESIDUE, *this, h, v); } - int GetUDData(int h, realtype &v) { return ud_get(mgr, UDR_RESIDUE, *this, h, v); } - -private: - ResName _resname_buf{}; InsCode _inscode_buf{}; -}; - -// =========================================================================== -class Chain : public UDStore { -public: - Manager *mgr = nullptr; - Model *model = nullptr; // parent; null => detached (use _local) - int ci = 0; - bool alive = true; - gemmi::Chain _local; // backing store while detached - std::vector residues; - - gemmi::Chain &g() const; - - int GetNumberOfResidues() { return (int)residues.size(); } - PResidue GetResidue(int resNo) { - return (resNo >= 0 && resNo < (int)residues.size()) ? residues[resNo] : nullptr; - } - // find by (seqNum, insCode) — MMDB's 2-arg overload - PResidue GetResidue(int seqNum, const InsCode insCode) { - char ic = (insCode && insCode[0]) ? insCode[0] : ' '; - for (Residue *r : residues) { - gemmi::Residue &gr = r->g(); - char ric = gr.seqid.icode ? gr.seqid.icode : ' '; - if (gr.seqid.num.value == seqNum && ric == ic) return r; - } - return nullptr; - } - void GetResidueTable(PPResidue &t, int &n) { t = residues.data(); n = (int)residues.size(); } - // delete residue at index: erase gemmi + wrapper, reindex the tail - void DeleteResidue(int resNo) { - if (resNo < 0 || resNo >= (int)residues.size()) return; - g().residues.erase(g().residues.begin() + resNo); - residues.erase(residues.begin() + resNo); - for (int k = resNo; k < (int)residues.size(); ++k) residues[k]->ri = k; - } - void TrimResidueTable() {} // compact after deletions — shim stays in sync - void DeleteResidue(int seqNum, const InsCode ic) { // by (seqNum, insCode) - PResidue r = GetResidue(seqNum, ic); - if (r) DeleteResidue(r->ri); - } - pstr GetChainID(); - pstr GetChainID(pstr buf) { if (buf) std::snprintf(buf, sizeof(ChainID), "%s", g().name.c_str()); return buf; } - Manager *GetCoordHierarchy() { return mgr; } // parent manager - void SetChainID(const ChainID id) { g().name = id ? id : ""; } - Chain() = default; - Chain(Model *m, const ChainID id); // construct + add to model (out-of-line) - void Copy(PChain src); // deep-copy subtree (out-of-line: needs Manager) - // Reorder residues (and their gemmi backing) ascending by (seqNum, insCode), - // MMDB's default. Keeps the wrapper vector and gemmi vector in lock-step and - // re-indexes ri. sortKey variants beyond ascending-by-number are uncommon in - // Coot and treated as the default. - void SortResidues(int /*sortKey*/ = 0) { - int n = (int)residues.size(); - if (n < 2) return; - std::vector ord(n); - for (int i = 0; i < n; ++i) ord[i] = i; - gemmi::Chain &gc = g(); - std::stable_sort(ord.begin(), ord.end(), [&](int a, int b) { - const gemmi::Residue &ra = gc.residues[a], &rb = gc.residues[b]; - if (ra.seqid.num.value != rb.seqid.num.value) return ra.seqid.num.value < rb.seqid.num.value; - char ia = ra.seqid.icode ? ra.seqid.icode : ' ', ib = rb.seqid.icode ? rb.seqid.icode : ' '; - return ia < ib; - }); - std::vector gnew; gnew.reserve(n); - std::vector wnew; wnew.reserve(n); - for (int k = 0; k < n; ++k) { gnew.push_back(std::move(gc.residues[ord[k]])); wnew.push_back(residues[ord[k]]); } - gc.residues = std::move(gnew); - residues = std::move(wnew); - for (int k = 0; k < n; ++k) residues[k]->ri = k; - } - bool isAminoacidChain(); // defined out-of-line (needs Residue predicates) - bool isNucleotideChain(); - bool isSolventChain(); - PResidue AddResidue(Manager &m, gemmi::Residue r); // append - PResidue InsResidue(Manager &m, int pos, gemmi::Residue r); - // Adopt a detached residue (its atom wrappers already point at it, so they - // ride along once its gemmi is copied in and the wrapper is rebound). - int AddResidue(PResidue res) { - res->_store_id(); // push name/insCode buffers into gemmi - g().residues.push_back(res->g()); // res detached -> its _local (with atoms) - res->chain = this; res->mgr = mgr; res->ri = (int)residues.size(); - residues.push_back(res); - return 0; - } - int InsResidue(PResidue res, int pos) { - if (pos < 0) pos = 0; - if (pos > (int)residues.size()) pos = (int)residues.size(); - res->_store_id(); - g().residues.insert(g().residues.begin() + pos, res->g()); - res->chain = this; res->mgr = mgr; res->ri = pos; - residues.insert(residues.begin() + pos, res); - for (int k = pos + 1; k < (int)residues.size(); ++k) residues[k]->ri = k; - return 0; - } - -private: - ChainID _chainid_buf{}; -}; - -// =========================================================================== -class Model : public UDStore { -public: - Manager *mgr = nullptr; // null => detached (use _local) - int mi = 0; // 0-based internal; GetModel is 1-based externally - gemmi::Model _local{1}; // backing store while detached (gemmi Model num is int) - std::vector chains; - - gemmi::Model &g() const; - - int GetNumberOfChains() { return (int)chains.size(); } - PChain GetChain(int chainNo) { - return (chainNo >= 0 && chainNo < (int)chains.size()) ? chains[chainNo] : nullptr; - } - PChain GetChain(const ChainID chID); - // Adopt a detached chain (Coot's `new mmdb::Chain` idiom): copy its local - // gemmi (with any residues/atoms) into this model and rebind, cascading mgr - // to the sub-tree that was built while detached (mgr was null). - int AddChain(PChain chn) { - g().chains.push_back(chn->g()); - chn->model = this; chn->mgr = mgr; chn->ci = (int)chains.size(); - chains.push_back(chn); - for (Residue *r : chn->residues) { - r->mgr = mgr; - for (Atom *a : r->atoms) a->mgr = mgr; - } - return 0; - } - int GetSerNum() { return mi + 1; } - // delete chain at index: erase gemmi + wrapper, reindex the tail - void DeleteChain(int chainNo) { - if (chainNo < 0 || chainNo >= (int)chains.size()) return; - g().chains.erase(g().chains.begin() + chainNo); - chains.erase(chains.begin() + chainNo); - for (int k = chainNo; k < (int)chains.size(); ++k) chains[k]->ci = k; - } - void DeleteChain(const ChainID chainID) { - for (int i = 0; i < (int)chains.size(); ++i) - if (chains[i]->g().name == (chainID ? chainID : "")) { DeleteChain(i); return; } - } - void GetChainTable(PPChain &t, int &n) { t = chains.data(); n = (int)chains.size(); } - std::vector all_atoms; // flat, filled by build_from_gemmi - PPAtom GetAllAtoms() { return all_atoms.data(); } - int GetNumberOfAtoms() { return (int)all_atoms.size(); } - int GetNumberOfAtoms(bool /*countTers*/) { return (int)all_atoms.size(); } - // Secondary-structure assignment: mocked. gemmi's DSSP has its SS prediction - // disabled upstream ("commented out ... wasn't correct anyway"), so there is no - // gemmi-backed SS to forward to. Return the non-OK code so callers treat SS as - // unavailable rather than trusting a bogus assignment. (residue SSE stays None.) - int CalcSecStructure(bool /*flag*/) { return SSERC_noResidues; } - // LINK records — gemmi-loaded (Manager::_load_metadata) plus Coot-created ones - // (AddLink) stored here; GetLink is 1-based like MMDB. - std::vector _links; - int GetNumberOfLinks() { return (int)_links.size(); } - PLink GetLink(int i) { return (i >= 1 && i <= (int)_links.size()) ? _links[i - 1] : nullptr; } - void AddLink(PLink link) { if (link) _links.push_back(link); } - // Refmac LINKR records — gemmi Connections that carry a link_id (_load_metadata). - std::vector _linkrs; - int GetNumberOfLinkRs() { return (int)_linkrs.size(); } - PLinkR GetLinkR(int i) { return (i >= 1 && i <= (int)_linkrs.size()) ? _linkrs[i - 1] : nullptr; } - void AddLinkR(PLinkR lr) { if (lr) _linkrs.push_back(lr); } - std::vector _cispeps; - int GetNumberOfCisPeps() { return (int)_cispeps.size(); } - PCisPep GetCisPep(int i) { return (i >= 1 && i <= (int)_cispeps.size()) ? _cispeps[i - 1] : nullptr; } - void AddCisPep(PCisPep cp) { if (cp) _cispeps.push_back(cp); } - void RemoveCisPeps() { _cispeps.clear(); } - // secondary structure. Records live in `helices`/`sheets` below, populated - // either from gemmi on load (build_from_gemmi) or by Coot's own SS computation - // via the access_model subclass (which reaches these public members directly). - // 1-based indexing to match MMDB. - int GetNumberOfHelices() { return (int)helices.data.size(); } - PHelix GetHelix(int i) { return (i >= 1 && i <= (int)helices.data.size()) ? helices.data[i - 1] : nullptr; } - int GetNumberOfSheets() { return sheets.nSheets; } - PSheet GetSheet(int i) { return (i >= 1 && i <= sheets.nSheets && sheets.sheet) ? sheets.sheet[i - 1] : nullptr; } - Sheets sheets; // SS records (gemmi-backed on load; access_model fills) - Helices helices; // " " " - std::vector _sheet_ptrs; // backing array for sheets.sheet (gemmi load) - PSheets GetSheets() { return &sheets; } - int GetModelID() { return mi + 1; } - pstr GetModelID(pstr buf) { if (buf) std::snprintf(buf, 16, "%d", mi + 1); return buf; } - int CalcSecStructure(int /*flag*/, int /*selHnd*/) { return SSERC_noResidues; } // mocked; see bool overload - void Copy(PModel src); // deep-copy subtree (out-of-line) - Manager *GetCoordHierarchy() { return mgr; } // parent manager - int GetNumberOfResidues() { - int n = 0; for (Chain *c : chains) n += c->GetNumberOfResidues(); return n; - } - LinkContainer _linkc; - PLinkContainer GetLinks() { - _linkc.data.assign(_links.begin(), _links.end()); return &_linkc; - } - void RemoveLinks() { _links.clear(); } - // Reorder chains (and gemmi backing) by chain ID. sortKey selects ascending - // (default) or descending; other MMDB sort keys collapse to ID order. - void SortChains(int sortKey = 0) { - int n = (int)chains.size(); - if (n < 2) return; - bool desc = (sortKey == SORT_CHAIN_ChainID_Desc); - std::vector ord(n); - for (int i = 0; i < n; ++i) ord[i] = i; - gemmi::Model &gm = g(); - std::stable_sort(ord.begin(), ord.end(), [&](int a, int b) { - return desc ? (gm.chains[a].name > gm.chains[b].name) - : (gm.chains[a].name < gm.chains[b].name); - }); - std::vector gnew; gnew.reserve(n); - std::vector wnew; wnew.reserve(n); - for (int k = 0; k < n; ++k) { gnew.push_back(std::move(gm.chains[ord[k]])); wnew.push_back(chains[ord[k]]); } - gm.chains = std::move(gnew); - chains = std::move(wnew); - for (int k = 0; k < n; ++k) chains[k]->ci = k; - } - PChain CreateChain(const ChainID id); // add empty chain (out-of-line: needs Manager) - int GetNumberOfStrands(int sheetNo) { - PSheet s = GetSheet(sheetNo); return s ? s->nStrands : 0; - } - PStrand GetStrand(int sheetNo, int strandNo) { - PSheet s = GetSheet(sheetNo); - return (s && strandNo >= 1 && strandNo <= s->nStrands && s->strand) ? s->strand[strandNo - 1] : nullptr; - } -}; - -// =========================================================================== -class Manager { -public: - gemmi::Structure st; - // stable-address pools - std::deque atom_pool; - std::deque res_pool; - std::deque chain_pool; - std::deque model_pool; - std::vector models; - // stable-address pools for gemmi-derived metadata records (LINK / CISPEP / - // HELIX / SHEET). Filled by build_from_gemmi -> _load_metadata(); owned here so - // the Model containers can hold bare pointers into them. - std::deque link_pool; - std::deque linkr_pool; - std::deque cispep_pool; - std::deque helix_pool; - std::deque sheet_pool; - std::deque strand_pool; - std::deque> strandarr_pool; // backing for Sheet::strand (Strand**) - std::deque author_pool; // backing for title.author records - void _load_metadata(); // out-of-line: needs complete gemmi metadata types - - Atom *newAtom() { atom_pool.emplace_back(); return &atom_pool.back(); } - Residue *newRes() { res_pool.emplace_back(); return &res_pool.back(); } - Chain *newChain(){ chain_pool.emplace_back();return &chain_pool.back();} - Model *newModel(){ model_pool.emplace_back();return &model_pool.back();} - - int GetNumberOfModels() { return (int)models.size(); } - PModel GetModel(int modelNo) { // MMDB: 1 <= modelNo <= nModels - int i = modelNo - 1; - return (i >= 0 && i < (int)models.size()) ? models[i] : nullptr; - } - // per-model chain access (modelNo is 1-based, chainNo 0-based) — mmdb_coormngr.h - int GetNumberOfChains(int modelNo) { - PModel m = GetModel(modelNo); return m ? m->GetNumberOfChains() : 0; - } - PChain GetChain(int modelNo, int chainNo) { - PModel m = GetModel(modelNo); return m ? m->GetChain(chainNo) : nullptr; - } - // Re-index/renumber after edits. Sibling indices are kept in sync as the shim - // mutates (so PDBCLEAN_INDEX is implicit); PDBCLEAN_SERIAL renumbers atom serials - // 1..N in hierarchy order. Other clean flags are not needed by the shim. - word PDBCleanup(word CleanKey) { - if (CleanKey & (PDBCLEAN_SERIAL | PDBCLEAN_INDEX)) { - int s = 1; - for (Atom *a : all_atoms) a->g().serial = s++; - } - return 0; - } - - // PDB title records — Coot reaches `title` via an access_mol subclass; the - // TITLE string comes from gemmi (_struct.title), authors are filled on load. - Title title; - pstr GetStructureTitle(pstr T) { - if (T) std::strcpy(T, st.get_info("_struct.title").c_str()); // caller allocates (MMDB contract) - return T; - } - - // Orthogonal symmetry transformation for operator Nop (0-based) + cell shifts, - // via gemmi's space group + unit cell (shared helper). Returns 0 on success, - // nonzero if there is no usable space group / the operator is out of range. - int GetTMatrix(mat44 &TMatrix, int Nop, int cellshift_a, int cellshift_b, int cellshift_c) { - return gemmi_sym_tmatrix(st.cell, st.spacegroup_hm, TMatrix, Nop, - cellshift_a, cellshift_b, cellshift_c); - } - - void build_from_gemmi(); - - // adopt a detached model (Coot: `new mmdb::Model` -> AddChain… -> AddModel). - // Copy its local gemmi into st, rebind, cascade mgr through the sub-tree. - int AddModel(PModel mw) { - st.models.push_back(mw->g()); - mw->mgr = this; mw->mi = (int)models.size(); - models.push_back(mw); - for (Chain *cw : mw->chains) { - cw->mgr = this; - for (Residue *rw : cw->residues) { - rw->mgr = this; - for (Atom *aw : rw->atoms) { aw->mgr = this; all_atoms.push_back(aw); mw->all_atoms.push_back(aw); } - } - } - return 0; - } - - // clone another manager's structure (mmdb Manager::Copy(PManager, COPY_MASK)). - // Copies the whole gemmi Structure and rebuilds all wrappers — clean & correct. - void Copy(PManager m, int /*CopyMask*/) { if (m) { st = m->st; build_from_gemmi(); } } - - // ---- crystal cell & symmetry (gemmi UnitCell / SpaceGroup) ---- - std::string _sg_buf, _symop_buf; - void GetCell(realtype &a, realtype &b, realtype &c, realtype &al, realtype &be, - realtype &ga, realtype &vol, int &orthcode) { - const gemmi::UnitCell &u = st.cell; - a = u.a; b = u.b; c = u.c; al = u.alpha; be = u.beta; ga = u.gamma; - vol = u.volume; orthcode = 1; - } - void GetCell(realtype &a, realtype &b, realtype &c, realtype &al, realtype &be, - realtype &ga, realtype &vol) { int oc; GetCell(a,b,c,al,be,ga,vol,oc); } - void SetCell(realtype a, realtype b, realtype c, realtype al, realtype be, - realtype ga, int /*OrthCode*/ = 1) { st.cell.set(a, b, c, al, be, ga); } - void Orth2Frac(realtype x, realtype y, realtype z, realtype &u, realtype &v, realtype &w) { - gemmi::Fractional f = st.cell.fractionalize(gemmi::Position(x, y, z)); - u = f.x; v = f.y; w = f.z; - } - void Frac2Orth(realtype u, realtype v, realtype w, realtype &x, realtype &y, realtype &z) { - gemmi::Position p = st.cell.orthogonalize(gemmi::Fractional(u, v, w)); - x = p.x; y = p.y; z = p.z; - } - pstr GetSpaceGroup() { _sg_buf = st.spacegroup_hm; return (pstr) _sg_buf.c_str(); } - pstr GetSpaceGroupFix() { return GetSpaceGroup(); } - int SetSpaceGroup(cpstr sg) { st.spacegroup_hm = sg ? sg : ""; return 0; } - int GetNumberOfSymOps() { - const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(st.spacegroup_hm); - return sg ? (int) sg->operations().order() : 0; - } - pstr GetSymOp(int Nop) { - const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(st.spacegroup_hm); - if (!sg) return nullptr; - int i = 0; - for (gemmi::Op op : sg->operations()) { - if (i++ == Nop) { _symop_buf = op.triplet(); return (pstr) _symop_buf.c_str(); } - } - return nullptr; - } - - // ---- selection ---- - struct Selection { - SELECTION_TYPE type = STYPE_UNDEFINED; - std::vector atoms; - std::vector residues; - std::vector chains; - }; - std::vector selections; // handle is 1-based index - - int NewSelection() { selections.emplace_back(); return (int)selections.size(); } - void DeleteSelection(int selHnd) { - if (selHnd < 1 || selHnd > (int)selections.size()) return; - Selection &s = selections[selHnd - 1]; - for (Atom *a : s.atoms) a->_setInSel(selHnd, false); - for (Residue *r : s.residues) r->_setInSel(selHnd, false); - for (Chain *c : s.chains) c->_setInSel(selHnd, false); - s = Selection(); - } - void GetSelIndex(int selHnd, PPAtom &SelAtom, int &n) { - Selection &s = selections[selHnd - 1]; SelAtom = s.atoms.data(); n = (int)s.atoms.size(); - } - void GetSelIndex(int selHnd, PPResidue &SelRes, int &n) { - Selection &s = selections[selHnd - 1]; SelRes = s.residues.data(); n = (int)s.residues.size(); - } - void GetSelIndex(int selHnd, PPChain &SelChain, int &n) { - Selection &s = selections[selHnd - 1]; SelChain = s.chains.data(); n = (int)s.chains.size(); - } - // select atoms by serial-number range (iSer1..iSer2; 0,0 => all). - void SelectAtoms(int selHnd, int iSer1, int iSer2, SELECTION_KEY key) { - if (selHnd < 1 || selHnd > (int)selections.size()) return; - Selection &s = selections[selHnd - 1]; - std::vector pick; - for (Atom *a : all_atoms) { - int sn = a->g().serial; - if ((iSer1 == 0 && iSer2 == 0) || (sn >= iSer1 && sn <= iSer2)) pick.push_back(a); - } - if (key == SKEY_OR) { for (Atom *a : pick) if (!a->isInSelection(selHnd)) s.atoms.push_back(a); } - else { for (Atom *a : s.atoms) a->_setInSel(selHnd, false); s.atoms = pick; } - s.type = STYPE_ATOM; - for (Atom *a : s.atoms) a->_setInSel(selHnd, true); - } - - // full spatial+CID atom selection (mmdb_selmngr.h) — sphere around (x,y,z) with - // chain/resname/atomname/element filters ("!X" = exclusion, "*" = any). - void SelectAtoms(int selHnd, int /*iModel*/, cpstr Chains, int ResNo1, cpstr /*Ins1*/, - int ResNo2, cpstr /*Ins2*/, cpstr RNames, cpstr ANames, cpstr Elements, - cpstr /*altLocs*/, cpstr /*segIDs*/, cpstr /*charges*/, - realtype /*occ1*/, realtype /*occ2*/, realtype x, realtype y, realtype z, - realtype radius, SELECTION_KEY key) { - if (selHnd < 1 || selHnd > (int)selections.size()) return; - Selection &s = selections[selHnd - 1]; - // self-contained comma-list matcher ("*"=any, "!X"=exclude); `detail::` is - // declared after Manager, so don't depend on it in this inline body. - auto inlist = [](cpstr list, const std::string &v) -> bool { - if (!list || !*list || std::strcmp(list, "*") == 0) return true; - for (const char *p = list; *p; ) { - const char *c = std::strchr(p, ','); - std::string tok(p, c ? (size_t)(c - p) : std::strlen(p)); - size_t a = tok.find_first_not_of(' '), b = tok.find_last_not_of(' '); - tok = (a == std::string::npos) ? std::string() : tok.substr(a, b - a + 1); - if (tok == v) return true; - if (!c) break; p = c + 1; + // ---- basic MMDB scalar/typedefs (real MMDB: mmdb_mattype.h / mmdb_defs.h) ---- + typedef double realtype; + typedef char *pstr; + typedef const char *cpstr; + typedef unsigned short word; + typedef char AtomName[20]; + typedef char ResName[20]; + typedef char InsCode[10]; + typedef char ChainID[10]; + typedef char Element[10]; + typedef char AltLoc[20]; + typedef char SegID[10]; + typedef char LinkRID[20]; // Refmac link ID + typedef unsigned char byte; // mmdb_mattype.h + typedef int *ivector; // mmdb_mattype.h 1-based vectors/matrices + typedef realtype *rvector; + typedef ivector *imatrix; + typedef rvector *rmatrix; + typedef char maxMMDBName[40]; + + // WhatIsSet mask flags (mmdb_atom.h ASET_FLAG) + enum ASET_FLAG { + ASET_Coordinates = 0x00000001, + ASET_Occupancy = 0x00000002, + ASET_tempFactor = 0x00000004, + ASET_CoordSigma = 0x00000010, + ASET_OccSigma = 0x00000020, + ASET_tFacSigma = 0x00000040, + ASET_Charge = 0x00000080, + ASET_Anis_tFac = 0x00000100, + ASET_Anis_tFSigma = 0x00001000, + ASET_All = 0x000FFFFF + }; + + // vector/matrix types (mmdb_defs.h) — plain fixed-size arrays of realtype + typedef realtype vect3[3]; + typedef realtype vect4[4]; + typedef vect3 mat33[3]; // realtype[3][3] + typedef vect4 mat44[4]; // realtype[4][4] + typedef mat44 *pmat44; + typedef mat44 &rmat44; + + enum ERROR_CODE { + Error_NoError = 0, + Error_CantOpenFile = 12, // matches real MMDB's value + Error_GeneralError1 = 1 + }; + + // ---- UDData (user-defined data) — real MMDB values (mmdb_uddata.h) ---- + enum UDR_TYPE { UDR_ATOM = 0, + UDR_RESIDUE = 1, + UDR_CHAIN = 2, + UDR_MODEL = 3, + UDR_HIERARCHY = 4 }; + enum UDDATA_CODE { UDDATA_Ok = 0, + UDDATA_WrongHandle = -1, + UDDATA_WrongUDRType = -2, + UDDATA_NoData = -3 }; + + // ---- Selection (real MMDB values: mmdb_selmngr.h) ---- + enum SELECTION_TYPE { STYPE_INVALID = -1, + STYPE_UNDEFINED = 0, + STYPE_ATOM = 1, + STYPE_RESIDUE = 2, + STYPE_CHAIN = 3, + STYPE_MODEL = 4 }; + enum SELECTION_KEY { SKEY_NEW = 0, + SKEY_OR = 1, + SKEY_AND = 2, + SKEY_XOR = 3, + SKEY_CLR = 4, + SKEY_XAND = 100 }; + inline const long int MinInt4 = -2147483647; + inline const long int MaxInt4 = 2147483647; + inline const int ANY_RES = -2147483647; // real MMDB: extern const == MinInt4 + inline const double Pi = 3.14159265358979323846; + + // PDB/CIF read flags (mmdb_io_file.h). Values are arbitrary distinct bits — the + // shim's SetFlag is a no-op, so only distinctness matters for Coot's bit ops. + enum MMDB_READ_FLAG { + MMDBF_AutoSerials = 0x00000001, + MMDBF_IgnoreDuplSeqNum = 0x00000002, + MMDBF_IgnoreBlankLines = 0x00000004, + MMDBF_IgnoreRemarks = 0x00000008, + MMDBF_IgnoreHash = 0x00000010, + MMDBF_IgnoreNonCoorPDBErrors = 0x00000020, + MMDBF_PrintCIFWarnings = 0x00000040, + MMDBF_All = 0x0000FFFF + }; + enum MMDB_FCM { MMDBFCM_None = 0, + MMDBFCM_All = 1, + MMDBFCM_Coord = 2, + MMDBFCM_Cryst = 4, + MMDBFCM_SC = 8 }; + typedef int COPY_MASK; // Coot uses `COPY_MASK cm = MMDBFCM_All` + bit arithmetic + + // Per-object UDData slots + selection membership bits. Each registered UDData + // handle maps to a (type,kind,slot); the object stores contiguous vectors + // indexed by slot. `_inSel[selHnd-1]` = is this object in selection selHnd + // (maintained by Manager::Select/SelectSphere/DeleteSelection). + struct UDStore { + std::vector _udi; + std::vector _udr; + std::vector _uds; + std::vector _inSel; + bool isInSelection(int selHnd) const { + return selHnd >= 1 && selHnd <= (int)_inSel.size() && _inSel[selHnd - 1]; } + void _setInSel(int selHnd, bool v) { + if ((int)_inSel.size() < selHnd) _inSel.resize(selHnd, false); + _inSel[selHnd - 1] = v; + } + }; + + class Atom; + class Residue; + class Chain; + class Model; + class Manager; + typedef Atom *PAtom; + typedef Atom **PPAtom; + typedef Residue *PResidue; + typedef Residue **PPResidue; + typedef Chain *PChain; + typedef Chain **PPChain; + typedef Model *PModel; + typedef Model **PPModel; + typedef Manager *PManager; + typedef Manager **PPManager; + + struct Contact { + int id1, id2; + long group; + realtype dist; + }; + typedef Contact *PContact; + + // base for records held in MMDB containers (Title compound/author, LINK, …) + class ContainerClass { + public: + virtual ~ContainerClass() {} + }; + typedef ContainerClass *PContainerClass; + + // LINK record. Public data members mirror real MMDB (Coot reads them directly). + // Populated from gemmi Structure::connections on load (Manager::_load_metadata); + // Coot-created links are appended via Model::AddLink. + class Link : public ContainerClass { + public: + AtomName atName1{}, atName2{}; + AltLoc aloc1{}, aloc2{}; + ResName resName1{}, resName2{}; + ChainID chainID1{}, chainID2{}; + InsCode insCode1{}, insCode2{}; + int seqNum1 = 0, seqNum2 = 0; + int s1 = 1, i1 = 0, j1 = 0, k1 = 0; // symmetry id of 1st atom + int s2 = 1, i2 = 0, j2 = 0, k2 = 0; // symmetry id of 2nd atom + realtype dist = 0; + void Copy(PContainerClass o) { + if (auto *l = dynamic_cast(o)) *this = *l; + } + }; + typedef Link *PLink; + typedef Link **PPLink; + + // Refmac LINK record (mmdb_model.h LinkR). Public members mirror real MMDB; + // populated from gemmi Connections carrying a link_id (Manager::_load_metadata). + class LinkR { + public: + LinkRID linkRID{}; + AtomName atName1{}, atName2{}; + AltLoc aloc1{}, aloc2{}; + ResName resName1{}, resName2{}; + ChainID chainID1{}, chainID2{}; + int seqNum1 = 0, seqNum2 = 0; + InsCode insCode1{}, insCode2{}; + realtype dist = 0; + }; + typedef LinkR *PLinkR; + typedef LinkR **PPLinkR; + + // CIS-peptide record (mmdb_model.h CisPep). Public members mirror real MMDB; + // populated from gemmi Structure::cispeps on load (Manager::_load_metadata). + class CisPep { + public: + int serNum = 0; + ResName pep1{}; + ChainID chainID1{}; + int seqNum1 = 0; + InsCode icode1{}; + ResName pep2{}; + ChainID chainID2{}; + int seqNum2 = 0; + InsCode icode2{}; + int modNum = 0; + realtype measure = 0; + }; + typedef CisPep *PCisPep; + + // Container of LINK records (mmdb_model.h LinkContainer). Minimal: Coot only + // declares `empty_links_container()` returning one by value; never dereferenced. + class LinkContainer { + public: + std::vector data; + int Length() { return (int)data.size(); } + PContainerClass GetContainerClass(int i) { return (i >= 0 && i < (int)data.size()) ? data[i] : nullptr; } + }; + typedef LinkContainer *PLinkContainer; + + // PDB title records (mmdb_title.h). Coot subclasses Manager & Title to reach the + // COMPND/AUTHOR line containers. The AUTHOR container is filled from gemmi + // meta.authors on load and the TITLE string comes from Structure::get_info + // ("_struct.title"); COMPND/JRNL have no structured gemmi home, so those + // containers stay empty. + class Compound : public ContainerClass { + public: + char Line[256] = {0}; + }; + typedef Compound *PCompound; + class Author : public ContainerClass { + public: + char Line[256] = {0}; + }; + typedef Author *PAuthor; + class Journal : public ContainerClass { + public: + char Line[256] = {0}; + }; + typedef Journal *PJournal; + class TitleContainer { + public: + std::vector data; + int Length() { return (int)data.size(); } + PContainerClass GetContainerClass(int i) { + return (i >= 0 && i < (int)data.size()) ? data[i] : nullptr; + } + }; + class Title { + public: + TitleContainer compound, author, journal; // public so Coot's access_title can reach them + TitleContainer *GetCompound() { return &compound; } // real Title exposes these + TitleContainer *GetAuthor() { return &author; } // publicly; access_title + TitleContainer *GetJournal() { return &journal; } // inherits GetJournal() + }; + + // gzip mode flag (mmdb_io_file.h). Minimal mmdb::io — the shim does I/O via gemmi, + // so only this compression-mode enum is provided (Coot passes it to write calls). + namespace io { + enum GZ_MODE { GZM_NONE = 0, + GZM_CHECK = 1, + GZM_ENFORCE = 2 }; + } + + // initialise a 4x4 matrix to identity (mmdb_mattype.h Mat4Init) + inline void Mat4Init(mat44 &A) { + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 4; ++j) A[i][j] = (i == j) ? 1.0 : 0.0; + } + + // Orthogonal symmetry transformation for operator Nop (0-based) + integer cell + // shifts, from a gemmi cell + space group. The op acts in fractional space; we + // conjugate it with the cell frac<->orth transforms so TMatrix maps orthogonal + // coordinates directly (MMDB semantics). Returns 0 on success, 1 if there is no + // usable space group / the operator is out of range. Shared by Manager and Cryst. + inline int gemmi_sym_tmatrix(const gemmi::UnitCell &cell, const std::string &sg_name, + mat44 &TMatrix, int Nop, int a, int b, int c) { + Mat4Init(TMatrix); + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(sg_name); + if (!sg || !cell.is_crystal()) return 1; + gemmi::GroupOps gops = sg->operations(); + if (Nop < 0 || Nop >= (int)gops.order()) return 1; + int i = 0; + gemmi::Op op; + for (gemmi::Op o : gops) { + if (i++ == Nop) { + op = o; + break; + } + } + gemmi::Transform sym{gemmi::rot_as_mat33(op), + gemmi::tran_as_vec3(op) + gemmi::Vec3(a, b, c)}; + gemmi::Transform t = cell.orth.combine(sym).combine(cell.frac); + for (int r = 0; r < 3; ++r) { + for (int cc = 0; cc < 3; ++cc) TMatrix[r][cc] = t.mat.a[r][cc]; + TMatrix[r][3] = t.vec.at(r); + } + return 0; + } + + // Crystal/symmetry record (mmdb_cryst.h). Holds a gemmi cell + space-group name + // and computes symmetry through the shared helper — same result as Manager for a + // populated Cryst (Manager is the usual live symmetry path). + class Cryst { + public: + gemmi::UnitCell cell; + std::string spaceGroup; + virtual ~Cryst() {} + int GetTMatrix(mat44 &T, int Nop, int a, int b, int c) { + return gemmi_sym_tmatrix(cell, spaceGroup, T, Nop, a, b, c); + } + int GetNumberOfSymOps() { + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(spaceGroup); + return sg ? (int)sg->operations().order() : 0; + } + pstr GetSymOp(int Nop) { + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(spaceGroup); + if (!sg) return nullptr; + int i = 0; + for (gemmi::Op op : sg->operations()) + if (i++ == Nop) { + _symop_buf = op.triplet(); + return (pstr)_symop_buf.c_str(); + } + return nullptr; + } + + private: + std::string _symop_buf; + }; + typedef Cryst *PCryst; + + // mmdb::math graph-matching subsystem — full classes defined in _graph_impl.hh + // (included at end of this file, after Atom/Residue are complete). Only the + // Alignment class (unused by the cootapi build) stays a forward decl. + namespace math { + class Alignment; + } + + struct AtomBond { + PAtom atom = nullptr; + int order = 0; + }; + typedef AtomBond *PAtomBond; + typedef AtomBond **PPAtomBond; + + struct AtomStat { // selection coordinate statistics (mmdb_atom.h) + int nAtoms = 0; + realtype xmin = 0, ymin = 0, zmin = 0, xmax = 0, ymax = 0, zmax = 0; + realtype xm = 0, ym = 0, zm = 0; // coordinate means (centroid) + realtype GetMaxSize() { + realtype dx = xmax - xmin, dy = ymax - ymin, dz = zmax - zmin; + return dx > dy ? (dx > dz ? dx : dz) : (dy > dz ? dy : dz); + } + }; + typedef AtomStat &RAtomStat; + + // secondary-structure element codes (mmdb_tables.h) + enum SSE_CODE { SSE_None = 0, + SSE_Strand = 1, + SSE_Bulge = 2, + SSE_3Turn = 3, + SSE_4Turn = 4, + SSE_5Turn = 5, + SSE_Helix = 6 }; + + // PDBCleanup flags (mmdb_root.h) — bit flags OR'd into PDBCleanup(word) + // misc return-code / sort-key enums (mmdb_cryst.h / mmdb_selmngr.h / mmdb_tables.h) + enum { SYMOP_Ok = 0, + SYMOP_NoLibFile = -1, + SYMOP_UnknownSpaceGroup = -2 }; + enum { SSERC_Ok = 0, + SSERC_noResidues = 1 }; + enum { SORT_CHAIN_ChainID_Asc = 0, + SORT_CHAIN_ChainID_Desc = 1 }; + enum { CNSORT_OFF = 0, + CNSORT_1INC = 1, + CNSORT_1DEC = 2, + CNSORT_2INC = 3, + CNSORT_2DEC = 4 }; + + enum PDB_CLEAN_FLAG { + PDBCLEAN_ATNAME = 0x00000001, + PDBCLEAN_TER = 0x00000002, + PDBCLEAN_CHAIN = 0x00000004, + PDBCLEAN_CHAIN_STRONG = 0x00000008, + PDBCLEAN_ALTCODE = 0x00000010, + PDBCLEAN_ALTCODE_STRONG = 0x00000020, + PDBCLEAN_SERIAL = 0x00000040, + PDBCLEAN_SEQNUM = 0x00000080, + PDBCLEAN_INDEX = 0x00000800, + PDBCLEAN_ELEMENT = 0x00001000, + PDBCLEAN_ELEMENT_STRONG = 0x00002000 + }; + + // SS records — public-member structs. Model::GetNumberOf{Helices,Sheets} are + // populated from gemmi Structure::{helices,sheets} on load (_load_metadata) and + // also fillable by Coot's own SS computation via the access_model subclass. + class Helix { + public: + ChainID initChainID{}, endChainID{}; + int initSeqNum = 0, endSeqNum = 0, serNum = 0, helixClass = 0, length = 0; + ResName initResName{}, endResName{}; + InsCode initICode{}, endICode{}; + char helixID[20]{}, comment[80]{}; + }; + class Strand { + public: + ChainID initChainID{}, endChainID{}; + int initSeqNum = 0, endSeqNum = 0, strandNo = 0, sense = 0; + ResName initResName{}, endResName{}; + InsCode initICode{}, endICode{}; + char sheetID[20]{}; + }; + class Sheet { + public: + int nStrands = 0; + Strand **strand = nullptr; + char sheetID[20]{}; + }; + class Sheets { + public: + int nSheets = 0; + Sheet **sheet = nullptr; + }; // filled from gemmi in _load_metadata + typedef Helix *PHelix; + typedef Strand *PStrand; + typedef Sheet *PSheet; + typedef Sheets *PSheets; + // container of helices (Model.helices); Coot's access_model subclass fills it. + class Helices { + public: + std::vector data; + void AddData(PHelix h) { + if (h) data.push_back(h); + } + int nHelices = 0; + }; + + // container of symmetry operators (mmdb_symop.h SymOps). Coot fills it from a + // space group; ops are xyz-triplet strings. + class SymOps { + std::vector ops; + std::deque buf; + + public: + int AddSymOp(cpstr xyz) { + ops.push_back(xyz ? xyz : ""); + return 0; + } + int GetNofSymOps() { return (int)ops.size(); } + pstr GetSymOp(int n) { + if (n < 0 || n >= (int)ops.size()) return nullptr; + buf.push_back(ops[n]); + return (pstr)buf.back().c_str(); + } + void FreeMemory() { ops.clear(); } + }; + + [[noreturn]] inline void unimpl(const char *w) { + throw std::logic_error(std::string("mmdb-shim: unimplemented: ") + w); + } + + // ---- free functions (mmdb_tables.h / mmdb_mattype.h) ---- + inline void InitMatType() {} // real MMDB inits static matrix-type tables; no-op here + inline cpstr GetErrorDescription(ERROR_CODE ec) { + switch (ec) { + case Error_NoError: + return "no error"; + case Error_CantOpenFile: + return "cannot open file"; + default: + return "MMDB error"; + } + } + inline realtype getVdWaalsRadius(cpstr element) { + return gemmi::Element(element ? element : "X").vdw_r(); + } + + // UDData helpers (defined after Manager); each class forwards with its UDR type. + int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int v); + int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype v); + int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, cpstr v); + int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int &v); + int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype &v); + int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, pstr &v); + + // =========================================================================== + class Atom : public UDStore { + public: + Manager *mgr = nullptr; + Residue *res = nullptr; // parent; null => detached (use _local) + int ai = 0; // cached index within parent residue's atoms + bool alive = true; + gemmi::Atom _local; // backing store while detached (see g() resolvers) + int Het = 0; // heteroatom flag (MMDB public field; Coot sets it) + int Ter = 0; // chain-terminator flag (gemmi has none -> always 0) + word WhatIsSet = 0; // ASET_* mask; ASET_Anis_tFac set on load if aniso present + AtomName label_atom_id{}; // mmcif label_atom_id (shim-owned; Coot sets on build) + + Atom() = default; + explicit Atom(Residue *r); // construct + add to residue (out-of-line) + + gemmi::Atom &g() const; // resolve to live gemmi (defined after Manager) + + // --- rewritten field accessors (pure B) --- + // Scalar fields -> reference-returning accessors, so a uniform `->field`-> + // `->field()` rewrite covers both reads and writes. (occ/b_iso/charge are + // narrower than realtype in gemmi, so those refs are float/schar-typed — the + // rare take-address-of-realtype sites surface at Coot build time.) + // non-const (writable ref) + const (by value) overloads, so reads work on a + // `const mmdb::Atom` and writes work through `->x() = v` on a non-const one. + realtype &x() { return g().pos.x; } + realtype x() const { return g().pos.x; } + realtype &y() { return g().pos.y; } + realtype y() const { return g().pos.y; } + realtype &z() { return g().pos.z; } + realtype z() const { return g().pos.z; } + float &occupancy() { return g().occ; } + float occupancy() const { return g().occ; } + float &tempFactor() { return g().b_iso; } + float tempFactor() const { return g().b_iso; } + signed char &charge() { return g().charge; } + signed char charge() const { return g().charge; } + int &serNum() { return g().serial; } + int serNum() const { return g().serial; } + // altLoc is a char[] (C-string) in MMDB; gemmi stores a single char. Return a + // buffer-backed C-string ("" when unset) so strcmp/strcpy-style code works. + // The non-const overload returns a WRITABLE buffer so `strncpy(at->altLoc(),..)` + // compiles; the buffer's first char is pushed back into gemmi by Residue::AddAtom + // (the buffer is refreshed from gemmi on entry, so reads stay correct). + pstr altLoc() { + _altloc_buf[0] = g().altloc; + _altloc_buf[1] = '\0'; + return _altloc_buf; + } + const char *altLoc() const { + _altloc_buf[0] = g().altloc; + _altloc_buf[1] = '\0'; + return _altloc_buf; + } + void set_occupancy(realtype v) { g().occ = (float)v; } + void set_tempFactor(realtype v) { g().b_iso = (float)v; } + void set_altLoc(char c) { g().altloc = c; } + void SetCharge(realtype ch) { g().charge = (signed char)ch; } + // coordinate/occupancy/B ESDs (MMDB public fields) — gemmi has none, so shim- + // owned; reference-returning so the rewritten `->sigX` covers reads and writes. + float &sigX() { return _sigx; } + float &sigY() { return _sigy; } + float &sigZ() { return _sigz; } + float &sigOcc() { return _sigocc; } + float &sigTemp() { return _sigtemp; } + bool isMetal() const { return gemmi::Element(g().element).is_metal(); } + // anisotropic B tensor — gemmi's SMat33 aniso. Reference-returning so the + // rewritten `->u11` covers both reads and writes. The mutable accessor marks the + // tensor present (ASET_Anis_tFac) so a write (e.g. SHELX import) sets the flag as + // real MMDB does. Const reads never set it; a non-const read over-approximates, + // which is harmless — the PDB/mmCIF writer emits ANISOU on the actual values. + float &u11() { + WhatIsSet |= ASET_Anis_tFac; + return g().aniso.u11; + } + float &u22() { + WhatIsSet |= ASET_Anis_tFac; + return g().aniso.u22; + } + float &u33() { + WhatIsSet |= ASET_Anis_tFac; + return g().aniso.u33; + } + float &u12() { + WhatIsSet |= ASET_Anis_tFac; + return g().aniso.u12; + } + float &u13() { + WhatIsSet |= ASET_Anis_tFac; + return g().aniso.u13; + } + float &u23() { + WhatIsSet |= ASET_Anis_tFac; + return g().aniso.u23; + } + float u11() const { return g().aniso.u11; } + float u22() const { return g().aniso.u22; } + float u33() const { return g().aniso.u33; } + float u12() const { return g().aniso.u12; } + float u13() const { return g().aniso.u13; } + float u23() const { return g().aniso.u23; } + // bonds — not modelled yet (gemmi connections); report none. + int GetNBonds() { return 0; } + void GetBonds(PAtomBond &atomBond, int &n) { + atomBond = nullptr; + n = 0; + } + int AddBond(PAtom /*a*/, int /*order*/, int /*nAdd*/ = 1) { return 0; } + SegID segID{}; // shim-owned (gemmi has no segID); MMDB public char[] field + + // --- method surface (hot subset; rest stubbed) --- + pstr GetAtomName() const; // aligned name, MMDB semantics (const: called on const Atom) + void SetAtomName(const AtomName aName); + pstr GetElementName(); + void SetElementName(const Element elName); + pstr GetChainID(); + int GetSeqNum(); + pstr GetInsCode(); + pstr GetResName(); + Residue *&GetResidue() { return res; } // ref: rewritten `->residue` is assignable + void SetResidue(Residue *r) { res = r; } + Chain *GetChain(); // out-of-line (needs complete Residue/Chain) + Model *GetModel(); // out-of-line + int GetModelNum(); + // residue-delegating accessors (bound by the Python API); out-of-line. + pstr GetLabelCompID(); + pstr GetLabelAsymID(); + int GetLabelSeqID(); + int GetLabelEntityID(); + int GetResidueNo(); + int GetSSEType(); + bool isSolvent(); + bool isNTerminus(); + bool isCTerminus(); + bool isTer() const { return false; } // gemmi has no TER atoms; see notes + void SetCoordinates(realtype xx, realtype yy, realtype zz, + realtype occ, realtype tF); + int GetIndex(); + void MakeTer() { Ter = 1; } // mark as chain terminator + pstr GetAtomID(pstr S); // "/mdl/chain/seq(res).ins/name[elem]:alt" (out-of-line) + int GetUDData(int h, pstr &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } + // copy another atom's data into this one (mmdb Atom::Copy — no hierarchy refs) + void Copy(PAtom a) { + g() = a->g(); + Het = a->Het; + WhatIsSet = a->WhatIsSet; + std::memcpy(segID, a->segID, sizeof segID); + } + // apply a 4x4 (rot+trans) or 3x3+vec to the coordinates (mmdb Atom::Transform) + void Transform(const mat44 &tm) { + gemmi::Position &p = g().pos; + double x = p.x, y = p.y, z = p.z; + p.x = tm[0][0] * x + tm[0][1] * y + tm[0][2] * z + tm[0][3]; + p.y = tm[1][0] * x + tm[1][1] * y + tm[1][2] * z + tm[1][3]; + p.z = tm[2][0] * x + tm[2][1] * y + tm[2][2] * z + tm[2][3]; + } + void Transform(const mat33 &tm, vect3 &v) { + gemmi::Position &p = g().pos; + double x = p.x, y = p.y, z = p.z; + p.x = tm[0][0] * x + tm[0][1] * y + tm[0][2] * z + v[0]; + p.y = tm[1][0] * x + tm[1][1] * y + tm[1][2] * z + v[1]; + p.z = tm[2][0] * x + tm[2][1] * y + tm[2][2] * z + v[2]; + } + // UDData + int PutUDData(int h, int v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } + int PutUDData(int h, realtype v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } + int PutUDData(int h, cpstr v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } + int GetUDData(int h, int &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } + int GetUDData(int h, realtype &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } + + private: + friend class Residue; // AddAtom pushes the strncpy'd altLoc buffer to gemmi + mutable AtomName _name_buf{}; + Element _elem_buf{}; + mutable char _altloc_buf[4]{}; + float _sigx = 0, _sigy = 0, _sigz = 0, _sigocc = 0, _sigtemp = 0; + }; + + // =========================================================================== + class Residue : public UDStore { + public: + Manager *mgr = nullptr; + Chain *chain = nullptr; // parent; null => detached (use _local) + int ri = 0; + bool alive = true; + gemmi::Residue _local; // backing store while detached + std::vector atoms; // canonical child wrappers == PPAtom table + PPAtom atom = nullptr; // MMDB public atom-table field; kept = atoms.data() + int nAtoms = 0; // MMDB public field; kept = atoms.size() + void _sync_atom() { + atom = atoms.data(); + nAtoms = (int)atoms.size(); + } + // mmcif label_* (shim-owned; Coot sets when building dictionary residues) + ResName label_comp_id{}; + ChainID label_asym_id{}; + int label_seq_id = 0, label_entity_id = 0; + pstr GetLabelCompID() { return label_comp_id; } + pstr GetLabelAsymID() { return label_asym_id; } + int GetLabelSeqID() { return label_seq_id; } + int GetLabelEntityID() { return label_entity_id; } + int GetResidueNo() { return ri; } // 0-based index within its chain + int GetNofAltLocations() { // distinct non-blank altLocs + std::set a; + for (Atom *at : atoms) { + char c = at->g().altloc; + if (c && c != ' ') a.insert(c); + } + return a.empty() ? 1 : (int)a.size(); + } + // sugar / modified-residue classification via gemmi's tabulated residues. + bool isSugar() { + gemmi::ResidueKind k = gemmi::find_tabulated_residue(g().name).kind; + return k == gemmi::ResidueKind::PYR || k == gemmi::ResidueKind::KET; + } + // MMDB isModRes reflects PDB MODRES records (a non-standard, modified form of a + // standard residue). gemmi has no per-residue MODRES flag on the model tree, so + // approximate: an amino/nucleic residue whose one-letter code is lower-case + // (gemmi marks non-standard monomers that way). Water/ligands are excluded. + bool isModRes() { + const gemmi::ResidueInfo ri = gemmi::find_tabulated_residue(g().name); + return ri.found() && !ri.is_standard() && + (ri.is_amino_acid() || ri.is_nucleic_acid()); + } + + Residue() = default; + explicit Residue(Chain *c); // construct + add to chain (out-of-line) + + // MMDB public char-array fields. Coot reads `residue->name` and writes + // `strncpy(residue->insCode,..)`. Kept as the interface: synced gemmi->buffer on + // load (_load_id, in build_from_gemmi) and buffer->gemmi at the adopt point + // (_store_id, in Chain::Add/InsResidue). SetResName/SetResID keep both in step. + ResName name{}; + InsCode insCode{}; + void _load_id() { + std::snprintf(name, sizeof name, "%s", g().name.c_str()); + insCode[0] = g().seqid.icode && g().seqid.icode != ' ' ? g().seqid.icode : '\0'; + insCode[1] = '\0'; + } + void _store_id() { + g().name = name; + g().seqid.icode = insCode[0] ? insCode[0] : ' '; + } + + gemmi::Residue &g() const; + + int GetNumberOfAtoms() { return (int)atoms.size(); } + int GetNumberOfAtoms(bool /*countTers*/) { return (int)atoms.size(); } + PAtom GetAtom(int atomNo) { + return (atomNo >= 0 && atomNo < (int)atoms.size()) ? atoms[atomNo] : nullptr; + } + PAtom GetAtom(const AtomName aname, const Element elname = nullptr, + const AltLoc aloc = nullptr); + void GetAtomTable(PPAtom &atomTable, int &n) { + atomTable = atoms.data(); + n = (int)atoms.size(); + } + PAtom AddAtom(Manager &m, gemmi::Atom a); // append: O(1) + // Adopt a detached atom (Coot's `new mmdb::Atom` idiom). Copies the atom's + // local gemmi into this residue's gemmi (detached or bound, via g()) and + // rebinds the wrapper. Pushes the strncpy'd altLoc buffer back into gemmi. + int AddAtom(PAtom atm) { + g().atoms.push_back(atm->_local); + atm->res = this; + atm->mgr = mgr; + atm->ai = (int)atoms.size(); + if (atm->_altloc_buf[0]) g().atoms[atm->ai].altloc = atm->_altloc_buf[0]; + atoms.push_back(atm); + _sync_atom(); + return 0; + } + void DeleteAtom(int pos); + void TrimAtomTable() {} // compact after deletions — shim keeps them in sync + + pstr GetResName(); + void SetResName(const ResName n) { + g().name = n ? n : ""; + std::snprintf(name, sizeof name, "%s", n ? n : ""); + } + void SetResID(const ResName resName, int seqNo, const InsCode ic) { + g().name = resName ? resName : ""; + g().seqid.num.value = seqNo; + g().seqid.icode = (ic && ic[0]) ? ic[0] : ' '; + std::snprintf(name, sizeof name, "%s", resName ? resName : ""); + insCode[0] = (ic && ic[0]) ? ic[0] : '\0'; + insCode[1] = '\0'; + } + int &GetSeqNum(); // writable (rewrite maps `->seqNum` reads and writes) + pstr GetInsCode(); + pstr GetChainID(); + int GetModelNum(); + int &GetIndex() { return ri; } // ref: rewritten `->index` is assignable + Chain *GetChain() { return chain; } + Model *GetModel(); // out-of-line (Chain incomplete here) + // terminus tests — peptide-bond-aware: N-terminus if no preceding residue's C is + // within bonding distance of this N, C-terminus if this C bonds no following N + // (out-of-line: need Chain + backbone atom geometry). + bool isNTerminus(); + bool isCTerminus(); + pstr GetResidueID(pstr S) { // "seqnum(name):inscode" + if (S) std::snprintf(S, 100, "%d(%s):%s", GetSeqNum(), name, insCode); + return S; + } + Residue *next = nullptr; // MMDB has this; wired lazily if needed + int SSE = SSE_None; // secondary-structure element (shim-owned public field) + bool isAminoacid() { return gemmi::find_tabulated_residue(g().name).is_amino_acid(); } + bool isNucleotide() { return gemmi::find_tabulated_residue(g().name).is_nucleic_acid(); } + bool isDNARNA() { return isNucleotide(); } + bool isSolvent() { return gemmi::find_tabulated_residue(g().name).is_water(); } + // UDData + int PutUDData(int h, int v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } + int PutUDData(int h, realtype v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } + int PutUDData(int h, cpstr v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } + int GetUDData(int h, int &v) { return ud_get(mgr, UDR_RESIDUE, *this, h, v); } + int GetUDData(int h, realtype &v) { return ud_get(mgr, UDR_RESIDUE, *this, h, v); } + + private: + ResName _resname_buf{}; + InsCode _inscode_buf{}; + }; + + // =========================================================================== + class Chain : public UDStore { + public: + Manager *mgr = nullptr; + Model *model = nullptr; // parent; null => detached (use _local) + int ci = 0; + bool alive = true; + gemmi::Chain _local; // backing store while detached + std::vector residues; + + gemmi::Chain &g() const; + + int GetNumberOfResidues() { return (int)residues.size(); } + PResidue GetResidue(int resNo) { + return (resNo >= 0 && resNo < (int)residues.size()) ? residues[resNo] : nullptr; + } + // find by (seqNum, insCode) — MMDB's 2-arg overload + PResidue GetResidue(int seqNum, const InsCode insCode) { + char ic = (insCode && insCode[0]) ? insCode[0] : ' '; + for (Residue *r : residues) { + gemmi::Residue &gr = r->g(); + char ric = gr.seqid.icode ? gr.seqid.icode : ' '; + if (gr.seqid.num.value == seqNum && ric == ic) return r; + } + return nullptr; + } + void GetResidueTable(PPResidue &t, int &n) { + t = residues.data(); + n = (int)residues.size(); + } + // delete residue at index: erase gemmi + wrapper, reindex the tail + void DeleteResidue(int resNo) { + if (resNo < 0 || resNo >= (int)residues.size()) return; + g().residues.erase(g().residues.begin() + resNo); + residues.erase(residues.begin() + resNo); + for (int k = resNo; k < (int)residues.size(); ++k) residues[k]->ri = k; + } + void TrimResidueTable() {} // compact after deletions — shim stays in sync + void DeleteResidue(int seqNum, const InsCode ic) { // by (seqNum, insCode) + PResidue r = GetResidue(seqNum, ic); + if (r) DeleteResidue(r->ri); + } + pstr GetChainID(); + pstr GetChainID(pstr buf) { + if (buf) std::snprintf(buf, sizeof(ChainID), "%s", g().name.c_str()); + return buf; + } + Manager *GetCoordHierarchy() { return mgr; } // parent manager + void SetChainID(const ChainID id) { g().name = id ? id : ""; } + Chain() = default; + Chain(Model *m, const ChainID id); // construct + add to model (out-of-line) + void Copy(PChain src); // deep-copy subtree (out-of-line: needs Manager) + // Reorder residues (and their gemmi backing) ascending by (seqNum, insCode), + // MMDB's default. Keeps the wrapper vector and gemmi vector in lock-step and + // re-indexes ri. sortKey variants beyond ascending-by-number are uncommon in + // Coot and treated as the default. + void SortResidues(int /*sortKey*/ = 0) { + int n = (int)residues.size(); + if (n < 2) return; + std::vector ord(n); + for (int i = 0; i < n; ++i) ord[i] = i; + gemmi::Chain &gc = g(); + std::stable_sort(ord.begin(), ord.end(), [&](int a, int b) { + const gemmi::Residue &ra = gc.residues[a], &rb = gc.residues[b]; + if (ra.seqid.num.value != rb.seqid.num.value) return ra.seqid.num.value < rb.seqid.num.value; + char ia = ra.seqid.icode ? ra.seqid.icode : ' ', ib = rb.seqid.icode ? rb.seqid.icode : ' '; + return ia < ib; + }); + std::vector gnew; + gnew.reserve(n); + std::vector wnew; + wnew.reserve(n); + for (int k = 0; k < n; ++k) { + gnew.push_back(std::move(gc.residues[ord[k]])); + wnew.push_back(residues[ord[k]]); + } + gc.residues = std::move(gnew); + residues = std::move(wnew); + for (int k = 0; k < n; ++k) residues[k]->ri = k; + } + bool isAminoacidChain(); // defined out-of-line (needs Residue predicates) + bool isNucleotideChain(); + bool isSolventChain(); + PResidue AddResidue(Manager &m, gemmi::Residue r); // append + PResidue InsResidue(Manager &m, int pos, gemmi::Residue r); + // Adopt a detached residue (its atom wrappers already point at it, so they + // ride along once its gemmi is copied in and the wrapper is rebound). + int AddResidue(PResidue res) { + res->_store_id(); // push name/insCode buffers into gemmi + g().residues.push_back(res->g()); // res detached -> its _local (with atoms) + res->chain = this; + res->mgr = mgr; + res->ri = (int)residues.size(); + residues.push_back(res); + return 0; + } + int InsResidue(PResidue res, int pos) { + if (pos < 0) pos = 0; + if (pos > (int)residues.size()) pos = (int)residues.size(); + res->_store_id(); + g().residues.insert(g().residues.begin() + pos, res->g()); + res->chain = this; + res->mgr = mgr; + res->ri = pos; + residues.insert(residues.begin() + pos, res); + for (int k = pos + 1; k < (int)residues.size(); ++k) residues[k]->ri = k; + return 0; + } + + private: + ChainID _chainid_buf{}; + }; + + // =========================================================================== + class Model : public UDStore { + public: + Manager *mgr = nullptr; // null => detached (use _local) + int mi = 0; // 0-based internal; GetModel is 1-based externally + gemmi::Model _local{1}; // backing store while detached (gemmi Model num is int) + std::vector chains; + + gemmi::Model &g() const; + + int GetNumberOfChains() { return (int)chains.size(); } + PChain GetChain(int chainNo) { + return (chainNo >= 0 && chainNo < (int)chains.size()) ? chains[chainNo] : nullptr; + } + PChain GetChain(const ChainID chID); + // Adopt a detached chain (Coot's `new mmdb::Chain` idiom): copy its local + // gemmi (with any residues/atoms) into this model and rebind, cascading mgr + // to the sub-tree that was built while detached (mgr was null). + int AddChain(PChain chn) { + g().chains.push_back(chn->g()); + chn->model = this; + chn->mgr = mgr; + chn->ci = (int)chains.size(); + chains.push_back(chn); + for (Residue *r : chn->residues) { + r->mgr = mgr; + for (Atom *a : r->atoms) a->mgr = mgr; + } + return 0; + } + int GetSerNum() { return mi + 1; } + // delete chain at index: erase gemmi + wrapper, reindex the tail + void DeleteChain(int chainNo) { + if (chainNo < 0 || chainNo >= (int)chains.size()) return; + g().chains.erase(g().chains.begin() + chainNo); + chains.erase(chains.begin() + chainNo); + for (int k = chainNo; k < (int)chains.size(); ++k) chains[k]->ci = k; + } + void DeleteChain(const ChainID chainID) { + for (int i = 0; i < (int)chains.size(); ++i) + if (chains[i]->g().name == (chainID ? chainID : "")) { + DeleteChain(i); + return; + } + } + void GetChainTable(PPChain &t, int &n) { + t = chains.data(); + n = (int)chains.size(); + } + std::vector all_atoms; // flat, filled by build_from_gemmi + PPAtom GetAllAtoms() { return all_atoms.data(); } + int GetNumberOfAtoms() { return (int)all_atoms.size(); } + int GetNumberOfAtoms(bool /*countTers*/) { return (int)all_atoms.size(); } + // Secondary-structure assignment: mocked. gemmi's DSSP has its SS prediction + // disabled upstream ("commented out ... wasn't correct anyway"), so there is no + // gemmi-backed SS to forward to. Return the non-OK code so callers treat SS as + // unavailable rather than trusting a bogus assignment. (residue SSE stays None.) + int CalcSecStructure(bool /*flag*/) { return SSERC_noResidues; } + // LINK records — gemmi-loaded (Manager::_load_metadata) plus Coot-created ones + // (AddLink) stored here; GetLink is 1-based like MMDB. + std::vector _links; + int GetNumberOfLinks() { return (int)_links.size(); } + PLink GetLink(int i) { return (i >= 1 && i <= (int)_links.size()) ? _links[i - 1] : nullptr; } + void AddLink(PLink link) { + if (link) _links.push_back(link); + } + // Refmac LINKR records — gemmi Connections that carry a link_id (_load_metadata). + std::vector _linkrs; + int GetNumberOfLinkRs() { return (int)_linkrs.size(); } + PLinkR GetLinkR(int i) { return (i >= 1 && i <= (int)_linkrs.size()) ? _linkrs[i - 1] : nullptr; } + void AddLinkR(PLinkR lr) { + if (lr) _linkrs.push_back(lr); + } + std::vector _cispeps; + int GetNumberOfCisPeps() { return (int)_cispeps.size(); } + PCisPep GetCisPep(int i) { return (i >= 1 && i <= (int)_cispeps.size()) ? _cispeps[i - 1] : nullptr; } + void AddCisPep(PCisPep cp) { + if (cp) _cispeps.push_back(cp); + } + void RemoveCisPeps() { _cispeps.clear(); } + // secondary structure. Records live in `helices`/`sheets` below, populated + // either from gemmi on load (build_from_gemmi) or by Coot's own SS computation + // via the access_model subclass (which reaches these public members directly). + // 1-based indexing to match MMDB. + int GetNumberOfHelices() { return (int)helices.data.size(); } + PHelix GetHelix(int i) { return (i >= 1 && i <= (int)helices.data.size()) ? helices.data[i - 1] : nullptr; } + int GetNumberOfSheets() { return sheets.nSheets; } + PSheet GetSheet(int i) { return (i >= 1 && i <= sheets.nSheets && sheets.sheet) ? sheets.sheet[i - 1] : nullptr; } + Sheets sheets; // SS records (gemmi-backed on load; access_model fills) + Helices helices; // " " " + std::vector _sheet_ptrs; // backing array for sheets.sheet (gemmi load) + PSheets GetSheets() { return &sheets; } + int GetModelID() { return mi + 1; } + pstr GetModelID(pstr buf) { + if (buf) std::snprintf(buf, 16, "%d", mi + 1); + return buf; + } + int CalcSecStructure(int /*flag*/, int /*selHnd*/) { return SSERC_noResidues; } // mocked; see bool overload + void Copy(PModel src); // deep-copy subtree (out-of-line) + Manager *GetCoordHierarchy() { return mgr; } // parent manager + int GetNumberOfResidues() { + int n = 0; + for (Chain *c : chains) n += c->GetNumberOfResidues(); + return n; + } + LinkContainer _linkc; + PLinkContainer GetLinks() { + _linkc.data.assign(_links.begin(), _links.end()); + return &_linkc; + } + void RemoveLinks() { _links.clear(); } + // Reorder chains (and gemmi backing) by chain ID. sortKey selects ascending + // (default) or descending; other MMDB sort keys collapse to ID order. + void SortChains(int sortKey = 0) { + int n = (int)chains.size(); + if (n < 2) return; + bool desc = (sortKey == SORT_CHAIN_ChainID_Desc); + std::vector ord(n); + for (int i = 0; i < n; ++i) ord[i] = i; + gemmi::Model &gm = g(); + std::stable_sort(ord.begin(), ord.end(), [&](int a, int b) { + return desc ? (gm.chains[a].name > gm.chains[b].name) + : (gm.chains[a].name < gm.chains[b].name); + }); + std::vector gnew; + gnew.reserve(n); + std::vector wnew; + wnew.reserve(n); + for (int k = 0; k < n; ++k) { + gnew.push_back(std::move(gm.chains[ord[k]])); + wnew.push_back(chains[ord[k]]); + } + gm.chains = std::move(gnew); + chains = std::move(wnew); + for (int k = 0; k < n; ++k) chains[k]->ci = k; + } + PChain CreateChain(const ChainID id); // add empty chain (out-of-line: needs Manager) + int GetNumberOfStrands(int sheetNo) { + PSheet s = GetSheet(sheetNo); + return s ? s->nStrands : 0; + } + PStrand GetStrand(int sheetNo, int strandNo) { + PSheet s = GetSheet(sheetNo); + return (s && strandNo >= 1 && strandNo <= s->nStrands && s->strand) ? s->strand[strandNo - 1] : nullptr; + } + }; + + // =========================================================================== + class Manager { + public: + gemmi::Structure st; + // stable-address pools + std::deque atom_pool; + std::deque res_pool; + std::deque chain_pool; + std::deque model_pool; + std::vector models; + // stable-address pools for gemmi-derived metadata records (LINK / CISPEP / + // HELIX / SHEET). Filled by build_from_gemmi -> _load_metadata(); owned here so + // the Model containers can hold bare pointers into them. + std::deque link_pool; + std::deque linkr_pool; + std::deque cispep_pool; + std::deque helix_pool; + std::deque sheet_pool; + std::deque strand_pool; + std::deque> strandarr_pool; // backing for Sheet::strand (Strand**) + std::deque author_pool; // backing for title.author records + void _load_metadata(); // out-of-line: needs complete gemmi metadata types + + Atom *newAtom() { + atom_pool.emplace_back(); + return &atom_pool.back(); + } + Residue *newRes() { + res_pool.emplace_back(); + return &res_pool.back(); + } + Chain *newChain() { + chain_pool.emplace_back(); + return &chain_pool.back(); + } + Model *newModel() { + model_pool.emplace_back(); + return &model_pool.back(); + } + + int GetNumberOfModels() { return (int)models.size(); } + PModel GetModel(int modelNo) { // MMDB: 1 <= modelNo <= nModels + int i = modelNo - 1; + return (i >= 0 && i < (int)models.size()) ? models[i] : nullptr; + } + // per-model chain access (modelNo is 1-based, chainNo 0-based) — mmdb_coormngr.h + int GetNumberOfChains(int modelNo) { + PModel m = GetModel(modelNo); + return m ? m->GetNumberOfChains() : 0; + } + PChain GetChain(int modelNo, int chainNo) { + PModel m = GetModel(modelNo); + return m ? m->GetChain(chainNo) : nullptr; + } + // Re-index/renumber after edits. Sibling indices are kept in sync as the shim + // mutates (so PDBCLEAN_INDEX is implicit); PDBCLEAN_SERIAL renumbers atom serials + // 1..N in hierarchy order. Other clean flags are not needed by the shim. + word PDBCleanup(word CleanKey) { + if (CleanKey & (PDBCLEAN_SERIAL | PDBCLEAN_INDEX)) { + int s = 1; + for (Atom *a : all_atoms) a->g().serial = s++; + } + return 0; + } + + // PDB title records — Coot reaches `title` via an access_mol subclass; the + // TITLE string comes from gemmi (_struct.title), authors are filled on load. + Title title; + pstr GetStructureTitle(pstr T) { + if (T) std::strcpy(T, st.get_info("_struct.title").c_str()); // caller allocates (MMDB contract) + return T; + } + + // Orthogonal symmetry transformation for operator Nop (0-based) + cell shifts, + // via gemmi's space group + unit cell (shared helper). Returns 0 on success, + // nonzero if there is no usable space group / the operator is out of range. + int GetTMatrix(mat44 &TMatrix, int Nop, int cellshift_a, int cellshift_b, int cellshift_c) { + return gemmi_sym_tmatrix(st.cell, st.spacegroup_hm, TMatrix, Nop, + cellshift_a, cellshift_b, cellshift_c); + } + + void build_from_gemmi(); + + // adopt a detached model (Coot: `new mmdb::Model` -> AddChain… -> AddModel). + // Copy its local gemmi into st, rebind, cascade mgr through the sub-tree. + int AddModel(PModel mw) { + st.models.push_back(mw->g()); + mw->mgr = this; + mw->mi = (int)models.size(); + models.push_back(mw); + for (Chain *cw : mw->chains) { + cw->mgr = this; + for (Residue *rw : cw->residues) { + rw->mgr = this; + for (Atom *aw : rw->atoms) { + aw->mgr = this; + all_atoms.push_back(aw); + mw->all_atoms.push_back(aw); + } + } + } + return 0; + } + + // clone another manager's structure (mmdb Manager::Copy(PManager, COPY_MASK)). + // Copies the whole gemmi Structure and rebuilds all wrappers — clean & correct. + void Copy(PManager m, int /*CopyMask*/) { + if (m) { + st = m->st; + build_from_gemmi(); + } + } + + // ---- crystal cell & symmetry (gemmi UnitCell / SpaceGroup) ---- + std::string _sg_buf, _symop_buf; + void GetCell(realtype &a, realtype &b, realtype &c, realtype &al, realtype &be, + realtype &ga, realtype &vol, int &orthcode) { + const gemmi::UnitCell &u = st.cell; + a = u.a; + b = u.b; + c = u.c; + al = u.alpha; + be = u.beta; + ga = u.gamma; + vol = u.volume; + orthcode = 1; + } + void GetCell(realtype &a, realtype &b, realtype &c, realtype &al, realtype &be, + realtype &ga, realtype &vol) { + int oc; + GetCell(a, b, c, al, be, ga, vol, oc); + } + void SetCell(realtype a, realtype b, realtype c, realtype al, realtype be, + realtype ga, int /*OrthCode*/ = 1) { st.cell.set(a, b, c, al, be, ga); } + void Orth2Frac(realtype x, realtype y, realtype z, realtype &u, realtype &v, realtype &w) { + gemmi::Fractional f = st.cell.fractionalize(gemmi::Position(x, y, z)); + u = f.x; + v = f.y; + w = f.z; + } + void Frac2Orth(realtype u, realtype v, realtype w, realtype &x, realtype &y, realtype &z) { + gemmi::Position p = st.cell.orthogonalize(gemmi::Fractional(u, v, w)); + x = p.x; + y = p.y; + z = p.z; + } + pstr GetSpaceGroup() { + _sg_buf = st.spacegroup_hm; + return (pstr)_sg_buf.c_str(); + } + pstr GetSpaceGroupFix() { return GetSpaceGroup(); } + int SetSpaceGroup(cpstr sg) { + st.spacegroup_hm = sg ? sg : ""; + return 0; + } + int GetNumberOfSymOps() { + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(st.spacegroup_hm); + return sg ? (int)sg->operations().order() : 0; + } + pstr GetSymOp(int Nop) { + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(st.spacegroup_hm); + if (!sg) return nullptr; + int i = 0; + for (gemmi::Op op : sg->operations()) { + if (i++ == Nop) { + _symop_buf = op.triplet(); + return (pstr)_symop_buf.c_str(); + } + } + return nullptr; + } + + // ---- selection ---- + struct Selection { + SELECTION_TYPE type = STYPE_UNDEFINED; + std::vector atoms; + std::vector residues; + std::vector chains; + }; + std::vector selections; // handle is 1-based index + + int NewSelection() { + selections.emplace_back(); + return (int)selections.size(); + } + void DeleteSelection(int selHnd) { + if (selHnd < 1 || selHnd > (int)selections.size()) return; + Selection &s = selections[selHnd - 1]; + for (Atom *a : s.atoms) a->_setInSel(selHnd, false); + for (Residue *r : s.residues) r->_setInSel(selHnd, false); + for (Chain *c : s.chains) c->_setInSel(selHnd, false); + s = Selection(); + } + void GetSelIndex(int selHnd, PPAtom &SelAtom, int &n) { + Selection &s = selections[selHnd - 1]; + SelAtom = s.atoms.data(); + n = (int)s.atoms.size(); + } + void GetSelIndex(int selHnd, PPResidue &SelRes, int &n) { + Selection &s = selections[selHnd - 1]; + SelRes = s.residues.data(); + n = (int)s.residues.size(); + } + void GetSelIndex(int selHnd, PPChain &SelChain, int &n) { + Selection &s = selections[selHnd - 1]; + SelChain = s.chains.data(); + n = (int)s.chains.size(); + } + // select atoms by serial-number range (iSer1..iSer2; 0,0 => all). + void SelectAtoms(int selHnd, int iSer1, int iSer2, SELECTION_KEY key) { + if (selHnd < 1 || selHnd > (int)selections.size()) return; + Selection &s = selections[selHnd - 1]; + std::vector pick; + for (Atom *a : all_atoms) { + int sn = a->g().serial; + if ((iSer1 == 0 && iSer2 == 0) || (sn >= iSer1 && sn <= iSer2)) pick.push_back(a); + } + if (key == SKEY_OR) { + for (Atom *a : pick) + if (!a->isInSelection(selHnd)) s.atoms.push_back(a); + } else { + for (Atom *a : s.atoms) a->_setInSel(selHnd, false); + s.atoms = pick; + } + s.type = STYPE_ATOM; + for (Atom *a : s.atoms) a->_setInSel(selHnd, true); + } + + // full spatial+CID atom selection (mmdb_selmngr.h) — sphere around (x,y,z) with + // chain/resname/atomname/element filters ("!X" = exclusion, "*" = any). + void SelectAtoms(int selHnd, int /*iModel*/, cpstr Chains, int ResNo1, cpstr /*Ins1*/, + int ResNo2, cpstr /*Ins2*/, cpstr RNames, cpstr ANames, cpstr Elements, + cpstr /*altLocs*/, cpstr /*segIDs*/, cpstr /*charges*/, + realtype /*occ1*/, realtype /*occ2*/, realtype x, realtype y, realtype z, + realtype radius, SELECTION_KEY key) { + if (selHnd < 1 || selHnd > (int)selections.size()) return; + Selection &s = selections[selHnd - 1]; + // self-contained comma-list matcher ("*"=any, "!X"=exclude); `detail::` is + // declared after Manager, so don't depend on it in this inline body. + auto inlist = [](cpstr list, const std::string &v) -> bool { + if (!list || !*list || std::strcmp(list, "*") == 0) return true; + for (const char *p = list; *p;) { + const char *c = std::strchr(p, ','); + std::string tok(p, c ? (size_t)(c - p) : std::strlen(p)); + size_t a = tok.find_first_not_of(' '), b = tok.find_last_not_of(' '); + tok = (a == std::string::npos) ? std::string() : tok.substr(a, b - a + 1); + if (tok == v) return true; + if (!c) break; + p = c + 1; + } + return false; + }; + auto match = [&](cpstr list, const std::string &v) -> bool { + if (!list || !*list || std::strcmp(list, "*") == 0) return true; + if (list[0] == '!') return !inlist(list + 1, v); + return inlist(list, v); + }; + gemmi::Position pt(x, y, z); + double r2 = radius * radius; + std::vector pick; + for (Atom *a : all_atoms) { + if (radius > 0 && a->g().pos.dist_sq(pt) > r2) continue; + Residue *r = a->res; + int sn = r->GetSeqNum(); + if (ResNo1 != ANY_RES && sn < ResNo1) continue; + if (ResNo2 != ANY_RES && sn > ResNo2) continue; + if (!match(Chains, r->chain->g().name)) continue; + if (!match(RNames, std::string(r->GetResName()))) continue; + if (!match(ANames, std::string(a->GetAtomName()))) continue; + if (!match(Elements, gemmi::Element(a->g().element).name())) continue; + pick.push_back(a); + } + if (key == SKEY_OR) { + for (Atom *a : pick) + if (!a->isInSelection(selHnd)) s.atoms.push_back(a); + } else { + for (Atom *a : s.atoms) a->_setInSel(selHnd, false); + s.atoms = pick; + } + s.type = STYPE_ATOM; + for (Atom *a : s.atoms) a->_setInSel(selHnd, true); + } + + // --- misc hierarchy/bond/UDData ops used by Coot --- + void RemoveBonds() {} // gemmi has no persistent bond table + // Partial-hierarchy delete (mmdb Manager::Delete). Coot's use is + // Delete(MMDBFCM_SC) to drop secondary-structure/connectivity records before + // writing; also honour Coord (atoms) and Cryst (cell/SG) for completeness. + void Delete(int DelKey) { + bool all = DelKey == MMDBFCM_All; + if (all || (DelKey & MMDBFCM_SC)) { + for (Model *m : models) { + m->_links.clear(); + m->_linkrs.clear(); + m->_cispeps.clear(); + m->helices.data.clear(); + m->sheets.nSheets = 0; + m->sheets.sheet = nullptr; + m->_sheet_ptrs.clear(); + } + link_pool.clear(); + linkr_pool.clear(); + cispep_pool.clear(); + helix_pool.clear(); + sheet_pool.clear(); + strand_pool.clear(); + strandarr_pool.clear(); + } + if (all || (DelKey & MMDBFCM_Cryst)) { + st.cell = gemmi::UnitCell(); + st.spacegroup_hm.clear(); + } + if (all || (DelKey & MMDBFCM_Coord)) { + st.models.clear(); + build_from_gemmi(); + } + } + void DeleteAllModels() { + st.models.clear(); + build_from_gemmi(); + } // clears the hierarchy + void DeleteModel(int modelNo) { // 1-based; erase model + rebuild wrappers + int i = modelNo - 1; + if (i >= 0 && i < (int)st.models.size()) { + st.models.erase(st.models.begin() + i); + build_from_gemmi(); + } + } + pstr GetInputBuffer(pstr buf, int &count) { + count = 0; + if (buf) buf[0] = '\0'; + return buf; + } + // Insert (a copy of) an atom into the hierarchy (mmdb Manager::PutAtom). MMDB + // keeps a flat atom array with a parallel hierarchy rebuilt by FinishStructEdit; + // the shim's storage IS the hierarchy, so PutAtom finds/creates the chain and + // residue implied by the atom's source residue and appends a copy there. Only + // append (index<=0 or top) is supported — the semantics Coot relies on + // (create_mmdbmanager_from_atom_selection_straight). Returns the atom's 1-based + // position (so GetAtomI(pos) returns it). Defined out-of-line (needs Add*). + int PutAtom(int index, PAtom atom, int serNum = 0); + // hierarchy-level UDData (UDR_HIERARCHY) — Manager owns its own UDStore. + UDStore _ud; + int PutUDData(int h, int v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } + int PutUDData(int h, realtype v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } + int PutUDData(int h, cpstr v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } + int GetUDData(int h, int &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } + int GetUDData(int h, realtype &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } + int GetUDData(int h, pstr &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } + // primary CID-range selection (STYPE via Select; SelectAtoms forwards as STYPE_ATOM) + void Select(int selHnd, SELECTION_TYPE sType, int iModel, cpstr Chains, + int ResNo1, cpstr Ins1, int ResNo2, cpstr Ins2, cpstr RNames, + cpstr ANames, cpstr Elements, cpstr altLocs, SELECTION_KEY selKey = SKEY_OR); + void SelectAtoms(int selHnd, int iModel, cpstr Chains, int ResNo1, cpstr Ins1, + int ResNo2, cpstr Ins2, cpstr RNames, cpstr ANames, + cpstr Elements, cpstr altLocs, SELECTION_KEY selKey = SKEY_OR) { + Select(selHnd, STYPE_ATOM, iModel, Chains, ResNo1, Ins1, ResNo2, Ins2, + RNames, ANames, Elements, altLocs, selKey); + } + void SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, realtype y, + realtype z, realtype r, SELECTION_KEY sKey = SKEY_OR); + // select-from-selection: combine selHnd2's contents into selHnd1 per sKey + void Select(int selHnd1, SELECTION_TYPE sType, int selHnd2, SELECTION_KEY sKey); + // atoms within [d1,d2] of any atom in the given set (defined in contacts.cc) + void SelectNeighbours(int selHnd, SELECTION_TYPE sType, PPAtom atoms, int nAtoms, + realtype d1, realtype d2, SELECTION_KEY sKey = SKEY_OR); + void SetFlag(int /*flags*/) {} // no-op: read/write behaviour is fixed + void SetFlag(cpstr /*flags*/) {} + int PutPDBString(cpstr /*card*/) { return Error_NoError; } // no-op + // No persistent bond table. Verified safe: Coot's only caller (make_bonds in + // coot-utils/bonded-atoms.cc) ignores the mmdb bond table and recomputes bonds + // itself from geometry, so a no-op here matches observed Coot behaviour. + int MakeBonds(bool /*calc*/) { return 0; } + + // flat atom access (across the whole hierarchy) + std::vector all_atoms; + int GetNumberOfAtoms() { return (int)all_atoms.size(); } + int GetNumberOfAtoms(bool /*countTers*/) { return (int)all_atoms.size(); } + int GetNumberOfAtoms(cpstr CID); // count atoms matching CID (defined below) + // MMDB GetAtomI is 1-based: returns Atom[index-1]. + PAtom GetAtomI(int i) { return (i >= 1 && i <= (int)all_atoms.size()) ? all_atoms[i - 1] : nullptr; } + void GetAtomTable(PPAtom &t, int &n) { + t = all_atoms.data(); + n = (int)all_atoms.size(); + } + void GetModelTable(PPModel &t, int &n) { + t = models.data(); + n = (int)models.size(); + } + void GetAtomStatistics(int selHnd, RAtomStat AS); // defined below + int MakeSelIndex(int selHnd) { + return (selHnd >= 1 && selHnd <= (int)selections.size()) + ? (int)selections[selHnd - 1].atoms.size() + : 0; + } + void SelectAtom(int selHnd, PAtom atom, SELECTION_KEY sKey, bool makeIndex = true); + // CID-string selection, e.g. "/1/A/10-20/CA" + void Select(int selHnd, SELECTION_TYPE sType, cpstr CID, SELECTION_KEY sKey); + + // ---- contacts (gemmi NeighborSearch; TMatrix path uses a uniform grid) ---- + // TMatrix is MMDB's optional symmetry transform applied to the 2nd set: when + // given, contacts.cc transforms that set and searches against it (symmetry + // mates); when null, gemmi NeighborSearch over the untransformed model is used. + void SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, + realtype d2, int seqDist, PContact &contact, int &ncontacts, + int maxlen = 0, pmat44 TMatrix = nullptr, long group = 0); + void SeekContacts(PPAtom A, int n, realtype d1, realtype d2, int seqDist, + PContact &contact, int &ncontacts, int maxlen = 0, + pmat44 TMatrix = nullptr, long group = 0); + // single-atom vs selection (forwards to the array overload with a 1-elem array) + void SeekContacts(PAtom a, PPAtom A2, int n2, realtype d1, realtype d2, int seqDist, + PContact &contact, int &ncontacts, int maxlen = 0, + pmat44 TMatrix = nullptr, long group = 0) { + PAtom a1[1] = {a}; + SeekContacts(a1, 1, A2, n2, d1, d2, seqDist, contact, ncontacts, maxlen, TMatrix, group); + } + + int FinishStructEdit() { return 0; } // no-op: wrappers stay in sync eagerly + + // ---- UDData registry ---- + struct UDReg { + UDR_TYPE type; + int kind; + std::string name; + int slot; + }; // kind:0=int,1=real,2=str + std::vector ud_regs; + int ud_counts[5][3] = {{0}}; // [UDR_TYPE][kind] -> next slot + + int RegisterUDInteger(UDR_TYPE t, cpstr name) { return _regUD(t, 0, name); } + int RegisterUDReal(UDR_TYPE t, cpstr name) { return _regUD(t, 1, name); } + int RegisterUDString(UDR_TYPE t, cpstr name) { return _regUD(t, 2, name); } + int GetUDDHandle(UDR_TYPE t, cpstr name) { + for (int i = 0; i < (int)ud_regs.size(); ++i) + if (ud_regs[i].type == t && ud_regs[i].name == name) return i; + return -1; + } + + private: + int _regUD(UDR_TYPE t, int kind, cpstr name) { + ud_regs.push_back({t, kind, name ? name : "", ud_counts[t][kind]++}); + return (int)ud_regs.size() - 1; + } + + public: + // ---- I/O (defined in mmdb-shim/src/io.cc; keeps heavy gemmi write/read + // headers out of the ~229 Coot TUs that include mmdb_manager.h) ---- + ERROR_CODE ReadPDBASCII(cpstr fname); + ERROR_CODE ReadCoorFile(cpstr fname); // auto-detects PDB / mmCIF + ERROR_CODE WritePDBASCII(cpstr fname); + ERROR_CODE WriteCIFASCII(cpstr fname); + }; + + // ---- g() resolvers ---- + // A wrapper with no parent is "detached" (Coot's `new mmdb::Atom` idiom: build + // standalone, set fields, then Add*() into a parent). While detached, g() + // resolves to a wrapper-owned local gemmi object; Add*() copies that local into + // the parent's gemmi vector and rebinds (sets parent + index). Index-based + // resolution makes the vector push/reallocation harmless for siblings. + inline gemmi::Model &Model::g() const { return mgr ? mgr->st.models[mi] : const_cast(this)->_local; } + inline gemmi::Chain &Chain::g() const { return model ? model->g().chains[ci] : const_cast(this)->_local; } + inline gemmi::Residue &Residue::g() const { return chain ? chain->g().residues[ri] : const_cast(this)->_local; } + inline gemmi::Atom &Atom::g() const { return res ? res->g().atoms[ai] : const_cast(this)->_local; } + + // ---- UDData helpers ---- + inline Manager::UDReg *_ud_desc(Manager *mgr, UDR_TYPE myType, int handle, int kind, + int &err) { + if (!mgr || handle < 0 || handle >= (int)mgr->ud_regs.size()) { + err = UDDATA_WrongHandle; + return nullptr; + } + Manager::UDReg &d = mgr->ud_regs[handle]; + if (d.type != myType || d.kind != kind) { + err = UDDATA_WrongUDRType; + return nullptr; + } + err = UDDATA_Ok; + return &d; + } + inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, int v) { + int e; + auto *d = _ud_desc(mgr, t, h, 0, e); + if (!d) return e; + if ((int)s._udi.size() <= d->slot) s._udi.resize(d->slot + 1, 0); + s._udi[d->slot] = v; + return UDDATA_Ok; + } + inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, realtype v) { + int e; + auto *d = _ud_desc(mgr, t, h, 1, e); + if (!d) return e; + if ((int)s._udr.size() <= d->slot) s._udr.resize(d->slot + 1, 0.0); + s._udr[d->slot] = v; + return UDDATA_Ok; + } + inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, cpstr v) { + int e; + auto *d = _ud_desc(mgr, t, h, 2, e); + if (!d) return e; + if ((int)s._uds.size() <= d->slot) s._uds.resize(d->slot + 1); + s._uds[d->slot] = v ? v : ""; + return UDDATA_Ok; + } + inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, int &v) { + int e; + auto *d = _ud_desc(mgr, t, h, 0, e); + if (!d) return e; + if ((int)s._udi.size() <= d->slot) return UDDATA_NoData; + v = s._udi[d->slot]; + return UDDATA_Ok; + } + inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, realtype &v) { + int e; + auto *d = _ud_desc(mgr, t, h, 1, e); + if (!d) return e; + if ((int)s._udr.size() <= d->slot) return UDDATA_NoData; + v = s._udr[d->slot]; + return UDDATA_Ok; + } + inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, pstr &v) { + int e; + auto *d = _ud_desc(mgr, t, h, 2, e); + if (!d) return e; + if ((int)s._uds.size() <= d->slot) return UDDATA_NoData; + v = (pstr)s._uds[d->slot].c_str(); + return UDDATA_Ok; // borrowed + } + + // ---- Atom out-of-line ---- + inline pstr Atom::GetAtomName() const { + std::snprintf(_name_buf, sizeof(_name_buf), "%s", g().name.c_str()); + return _name_buf; + } + inline void Atom::SetAtomName(const AtomName aName) { g().name = aName; } + inline pstr Atom::GetElementName() { + std::snprintf(_elem_buf, sizeof(_elem_buf), "%s", g().element.name()); + return _elem_buf; + } + inline void Atom::SetElementName(const Element elName) { g().element = gemmi::Element(elName); } + inline pstr Atom::GetChainID() { return res->GetChainID(); } + inline int Atom::GetSeqNum() { return res->GetSeqNum(); } + inline Chain *Atom::GetChain() { return res ? res->GetChain() : nullptr; } + inline Model *Atom::GetModel() { return res ? res->chain->model : nullptr; } + inline pstr Atom::GetLabelCompID() { return res ? res->GetLabelCompID() : nullptr; } + inline pstr Atom::GetLabelAsymID() { return res ? res->GetLabelAsymID() : nullptr; } + inline int Atom::GetLabelSeqID() { return res ? res->GetLabelSeqID() : 0; } + inline int Atom::GetLabelEntityID() { return res ? res->GetLabelEntityID() : 0; } + inline int Atom::GetResidueNo() { return res ? res->GetResidueNo() : 0; } + inline int Atom::GetSSEType() { return res ? res->SSE : SSE_None; } + inline bool Atom::isSolvent() { return res ? res->isSolvent() : false; } + inline bool Atom::isNTerminus() { return res ? res->isNTerminus() : false; } + inline bool Atom::isCTerminus() { return res ? res->isCTerminus() : false; } + inline pstr Atom::GetInsCode() { return res->GetInsCode(); } + inline pstr Atom::GetResName() { return res->GetResName(); } + inline int Atom::GetModelNum() { return res->GetModelNum(); } + inline int Atom::GetIndex() { return ai; } + inline void Atom::SetCoordinates(realtype xx, realtype yy, realtype zz, + realtype occ, realtype tF) { + auto &a = g(); + a.pos = gemmi::Position(xx, yy, zz); + a.occ = (float)occ; + a.b_iso = (float)tF; + } + + // ---- Residue out-of-line ---- + inline pstr Residue::GetResName() { + std::snprintf(_resname_buf, sizeof(_resname_buf), "%s", g().name.c_str()); + return _resname_buf; + } + inline int &Residue::GetSeqNum() { return g().seqid.num.value; } + inline pstr Residue::GetInsCode() { + _inscode_buf[0] = g().seqid.icode == ' ' ? '\0' : g().seqid.icode; + _inscode_buf[1] = '\0'; + return _inscode_buf; + } + inline pstr Residue::GetChainID() { return chain->GetChainID(); } + inline int Residue::GetModelNum() { return chain->model->GetSerNum(); } + inline PAtom Residue::GetAtom(const AtomName aname, const Element elname, const AltLoc aloc) { + for (Atom *a : atoms) { + if (a->g().name != aname) continue; + if (elname && *elname && a->g().element.name() != std::string(elname)) continue; + if (aloc && *aloc && a->g().altloc != aloc[0]) continue; + return a; + } + return nullptr; + } + inline PAtom Residue::AddAtom(Manager &m, gemmi::Atom a) { + g().atoms.push_back(std::move(a)); + Atom *aw = m.newAtom(); + aw->mgr = &m; + aw->res = this; + aw->ai = (int)atoms.size(); + atoms.push_back(aw); + return aw; + } + inline void Residue::DeleteAtom(int pos) { + if (pos < 0 || pos >= (int)atoms.size()) return; + g().atoms.erase(g().atoms.begin() + pos); + atoms[pos]->alive = false; + atoms[pos]->ai = -1; + atoms.erase(atoms.begin() + pos); + for (int k = pos; k < (int)atoms.size(); ++k) atoms[k]->ai = k; + } + + // ---- Chain out-of-line ---- + inline bool Chain::isAminoacidChain() { + for (Residue *r : residues) + if (r->isAminoacid()) return true; return false; - }; - auto match = [&](cpstr list, const std::string &v) -> bool { - if (!list || !*list || std::strcmp(list, "*") == 0) return true; - if (list[0] == '!') return !inlist(list + 1, v); - return inlist(list, v); - }; - gemmi::Position pt(x, y, z); double r2 = radius * radius; - std::vector pick; - for (Atom *a : all_atoms) { - if (radius > 0 && a->g().pos.dist_sq(pt) > r2) continue; - Residue *r = a->res; - int sn = r->GetSeqNum(); - if (ResNo1 != ANY_RES && sn < ResNo1) continue; - if (ResNo2 != ANY_RES && sn > ResNo2) continue; - if (!match(Chains, r->chain->g().name)) continue; - if (!match(RNames, std::string(r->GetResName()))) continue; - if (!match(ANames, std::string(a->GetAtomName()))) continue; - if (!match(Elements, gemmi::Element(a->g().element).name())) continue; - pick.push_back(a); - } - if (key == SKEY_OR) { for (Atom *a : pick) if (!a->isInSelection(selHnd)) s.atoms.push_back(a); } - else { for (Atom *a : s.atoms) a->_setInSel(selHnd, false); s.atoms = pick; } - s.type = STYPE_ATOM; - for (Atom *a : s.atoms) a->_setInSel(selHnd, true); - } - - // --- misc hierarchy/bond/UDData ops used by Coot --- - void RemoveBonds() {} // gemmi has no persistent bond table - // Partial-hierarchy delete (mmdb Manager::Delete). Coot's use is - // Delete(MMDBFCM_SC) to drop secondary-structure/connectivity records before - // writing; also honour Coord (atoms) and Cryst (cell/SG) for completeness. - void Delete(int DelKey) { - bool all = DelKey == MMDBFCM_All; - if (all || (DelKey & MMDBFCM_SC)) { - for (Model *m : models) { - m->_links.clear(); m->_linkrs.clear(); m->_cispeps.clear(); - m->helices.data.clear(); - m->sheets.nSheets = 0; m->sheets.sheet = nullptr; m->_sheet_ptrs.clear(); - } - link_pool.clear(); linkr_pool.clear(); cispep_pool.clear(); - helix_pool.clear(); sheet_pool.clear(); strand_pool.clear(); strandarr_pool.clear(); - } - if (all || (DelKey & MMDBFCM_Cryst)) { st.cell = gemmi::UnitCell(); st.spacegroup_hm.clear(); } - if (all || (DelKey & MMDBFCM_Coord)) { st.models.clear(); build_from_gemmi(); } - } - void DeleteAllModels() { st.models.clear(); build_from_gemmi(); } // clears the hierarchy - void DeleteModel(int modelNo) { // 1-based; erase model + rebuild wrappers - int i = modelNo - 1; - if (i >= 0 && i < (int)st.models.size()) { st.models.erase(st.models.begin() + i); build_from_gemmi(); } - } - pstr GetInputBuffer(pstr buf, int &count) { count = 0; if (buf) buf[0] = '\0'; return buf; } - // Insert (a copy of) an atom into the hierarchy (mmdb Manager::PutAtom). MMDB - // keeps a flat atom array with a parallel hierarchy rebuilt by FinishStructEdit; - // the shim's storage IS the hierarchy, so PutAtom finds/creates the chain and - // residue implied by the atom's source residue and appends a copy there. Only - // append (index<=0 or top) is supported — the semantics Coot relies on - // (create_mmdbmanager_from_atom_selection_straight). Returns the atom's 1-based - // position (so GetAtomI(pos) returns it). Defined out-of-line (needs Add*). - int PutAtom(int index, PAtom atom, int serNum = 0); - // hierarchy-level UDData (UDR_HIERARCHY) — Manager owns its own UDStore. - UDStore _ud; - int PutUDData(int h, int v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } - int PutUDData(int h, realtype v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } - int PutUDData(int h, cpstr v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } - int GetUDData(int h, int &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } - int GetUDData(int h, realtype &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } - int GetUDData(int h, pstr &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } - // primary CID-range selection (STYPE via Select; SelectAtoms forwards as STYPE_ATOM) - void Select(int selHnd, SELECTION_TYPE sType, int iModel, cpstr Chains, - int ResNo1, cpstr Ins1, int ResNo2, cpstr Ins2, cpstr RNames, - cpstr ANames, cpstr Elements, cpstr altLocs, SELECTION_KEY selKey = SKEY_OR); - void SelectAtoms(int selHnd, int iModel, cpstr Chains, int ResNo1, cpstr Ins1, - int ResNo2, cpstr Ins2, cpstr RNames, cpstr ANames, - cpstr Elements, cpstr altLocs, SELECTION_KEY selKey = SKEY_OR) { - Select(selHnd, STYPE_ATOM, iModel, Chains, ResNo1, Ins1, ResNo2, Ins2, - RNames, ANames, Elements, altLocs, selKey); - } - void SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, realtype y, - realtype z, realtype r, SELECTION_KEY sKey = SKEY_OR); - // select-from-selection: combine selHnd2's contents into selHnd1 per sKey - void Select(int selHnd1, SELECTION_TYPE sType, int selHnd2, SELECTION_KEY sKey); - // atoms within [d1,d2] of any atom in the given set (defined in contacts.cc) - void SelectNeighbours(int selHnd, SELECTION_TYPE sType, PPAtom atoms, int nAtoms, - realtype d1, realtype d2, SELECTION_KEY sKey = SKEY_OR); - void SetFlag(int /*flags*/) {} // no-op: read/write behaviour is fixed - void SetFlag(cpstr /*flags*/) {} - int PutPDBString(cpstr /*card*/) { return Error_NoError; } // no-op - // No persistent bond table. Verified safe: Coot's only caller (make_bonds in - // coot-utils/bonded-atoms.cc) ignores the mmdb bond table and recomputes bonds - // itself from geometry, so a no-op here matches observed Coot behaviour. - int MakeBonds(bool /*calc*/) { return 0; } - - // flat atom access (across the whole hierarchy) - std::vector all_atoms; - int GetNumberOfAtoms() { return (int)all_atoms.size(); } - int GetNumberOfAtoms(bool /*countTers*/) { return (int)all_atoms.size(); } - int GetNumberOfAtoms(cpstr CID); // count atoms matching CID (defined below) - // MMDB GetAtomI is 1-based: returns Atom[index-1]. - PAtom GetAtomI(int i) { return (i >= 1 && i <= (int)all_atoms.size()) ? all_atoms[i - 1] : nullptr; } - void GetAtomTable(PPAtom &t, int &n) { t = all_atoms.data(); n = (int)all_atoms.size(); } - void GetModelTable(PPModel &t, int &n) { t = models.data(); n = (int)models.size(); } - void GetAtomStatistics(int selHnd, RAtomStat AS); // defined below - int MakeSelIndex(int selHnd) { - return (selHnd >= 1 && selHnd <= (int)selections.size()) - ? (int)selections[selHnd - 1].atoms.size() : 0; - } - void SelectAtom(int selHnd, PAtom atom, SELECTION_KEY sKey, bool makeIndex = true); - // CID-string selection, e.g. "/1/A/10-20/CA" - void Select(int selHnd, SELECTION_TYPE sType, cpstr CID, SELECTION_KEY sKey); - - // ---- contacts (gemmi NeighborSearch; TMatrix path uses a uniform grid) ---- - // TMatrix is MMDB's optional symmetry transform applied to the 2nd set: when - // given, contacts.cc transforms that set and searches against it (symmetry - // mates); when null, gemmi NeighborSearch over the untransformed model is used. - void SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, - realtype d2, int seqDist, PContact &contact, int &ncontacts, - int maxlen = 0, pmat44 TMatrix = nullptr, long group = 0); - void SeekContacts(PPAtom A, int n, realtype d1, realtype d2, int seqDist, - PContact &contact, int &ncontacts, int maxlen = 0, - pmat44 TMatrix = nullptr, long group = 0); - // single-atom vs selection (forwards to the array overload with a 1-elem array) - void SeekContacts(PAtom a, PPAtom A2, int n2, realtype d1, realtype d2, int seqDist, - PContact &contact, int &ncontacts, int maxlen = 0, - pmat44 TMatrix = nullptr, long group = 0) { - PAtom a1[1] = { a }; - SeekContacts(a1, 1, A2, n2, d1, d2, seqDist, contact, ncontacts, maxlen, TMatrix, group); - } - - int FinishStructEdit() { return 0; } // no-op: wrappers stay in sync eagerly - - // ---- UDData registry ---- - struct UDReg { UDR_TYPE type; int kind; std::string name; int slot; }; // kind:0=int,1=real,2=str - std::vector ud_regs; - int ud_counts[5][3] = {{0}}; // [UDR_TYPE][kind] -> next slot - - int RegisterUDInteger(UDR_TYPE t, cpstr name) { return _regUD(t, 0, name); } - int RegisterUDReal (UDR_TYPE t, cpstr name) { return _regUD(t, 1, name); } - int RegisterUDString (UDR_TYPE t, cpstr name) { return _regUD(t, 2, name); } - int GetUDDHandle(UDR_TYPE t, cpstr name) { - for (int i = 0; i < (int)ud_regs.size(); ++i) - if (ud_regs[i].type == t && ud_regs[i].name == name) return i; - return -1; - } -private: - int _regUD(UDR_TYPE t, int kind, cpstr name) { - ud_regs.push_back({t, kind, name ? name : "", ud_counts[t][kind]++}); - return (int)ud_regs.size() - 1; - } -public: - - // ---- I/O (defined in mmdb-shim/src/io.cc; keeps heavy gemmi write/read - // headers out of the ~229 Coot TUs that include mmdb_manager.h) ---- - ERROR_CODE ReadPDBASCII(cpstr fname); - ERROR_CODE ReadCoorFile(cpstr fname); // auto-detects PDB / mmCIF - ERROR_CODE WritePDBASCII(cpstr fname); - ERROR_CODE WriteCIFASCII(cpstr fname); -}; - -// ---- g() resolvers ---- -// A wrapper with no parent is "detached" (Coot's `new mmdb::Atom` idiom: build -// standalone, set fields, then Add*() into a parent). While detached, g() -// resolves to a wrapper-owned local gemmi object; Add*() copies that local into -// the parent's gemmi vector and rebinds (sets parent + index). Index-based -// resolution makes the vector push/reallocation harmless for siblings. -inline gemmi::Model &Model::g() const { return mgr ? mgr->st.models[mi] : const_cast(this)->_local; } -inline gemmi::Chain &Chain::g() const { return model ? model->g().chains[ci] : const_cast(this)->_local; } -inline gemmi::Residue &Residue::g() const { return chain ? chain->g().residues[ri] : const_cast(this)->_local; } -inline gemmi::Atom &Atom::g() const { return res ? res->g().atoms[ai] : const_cast(this)->_local; } - -// ---- UDData helpers ---- -inline Manager::UDReg *_ud_desc(Manager *mgr, UDR_TYPE myType, int handle, int kind, - int &err) { - if (!mgr || handle < 0 || handle >= (int)mgr->ud_regs.size()) { err = UDDATA_WrongHandle; return nullptr; } - Manager::UDReg &d = mgr->ud_regs[handle]; - if (d.type != myType || d.kind != kind) { err = UDDATA_WrongUDRType; return nullptr; } - err = UDDATA_Ok; return &d; -} -inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, int v) { - int e; auto *d = _ud_desc(mgr, t, h, 0, e); if (!d) return e; - if ((int)s._udi.size() <= d->slot) s._udi.resize(d->slot + 1, 0); - s._udi[d->slot] = v; return UDDATA_Ok; -} -inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, realtype v) { - int e; auto *d = _ud_desc(mgr, t, h, 1, e); if (!d) return e; - if ((int)s._udr.size() <= d->slot) s._udr.resize(d->slot + 1, 0.0); - s._udr[d->slot] = v; return UDDATA_Ok; -} -inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, cpstr v) { - int e; auto *d = _ud_desc(mgr, t, h, 2, e); if (!d) return e; - if ((int)s._uds.size() <= d->slot) s._uds.resize(d->slot + 1); - s._uds[d->slot] = v ? v : ""; return UDDATA_Ok; -} -inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, int &v) { - int e; auto *d = _ud_desc(mgr, t, h, 0, e); if (!d) return e; - if ((int)s._udi.size() <= d->slot) return UDDATA_NoData; - v = s._udi[d->slot]; return UDDATA_Ok; -} -inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, realtype &v) { - int e; auto *d = _ud_desc(mgr, t, h, 1, e); if (!d) return e; - if ((int)s._udr.size() <= d->slot) return UDDATA_NoData; - v = s._udr[d->slot]; return UDDATA_Ok; -} -inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, pstr &v) { - int e; auto *d = _ud_desc(mgr, t, h, 2, e); if (!d) return e; - if ((int)s._uds.size() <= d->slot) return UDDATA_NoData; - v = (pstr) s._uds[d->slot].c_str(); return UDDATA_Ok; // borrowed -} - -// ---- Atom out-of-line ---- -inline pstr Atom::GetAtomName() const { - std::snprintf(_name_buf, sizeof(_name_buf), "%s", g().name.c_str()); - return _name_buf; -} -inline void Atom::SetAtomName(const AtomName aName) { g().name = aName; } -inline pstr Atom::GetElementName() { - std::snprintf(_elem_buf, sizeof(_elem_buf), "%s", g().element.name()); - return _elem_buf; -} -inline void Atom::SetElementName(const Element elName) { g().element = gemmi::Element(elName); } -inline pstr Atom::GetChainID() { return res->GetChainID(); } -inline int Atom::GetSeqNum() { return res->GetSeqNum(); } -inline Chain *Atom::GetChain() { return res ? res->GetChain() : nullptr; } -inline Model *Atom::GetModel() { return res ? res->chain->model : nullptr; } -inline pstr Atom::GetLabelCompID() { return res ? res->GetLabelCompID() : nullptr; } -inline pstr Atom::GetLabelAsymID() { return res ? res->GetLabelAsymID() : nullptr; } -inline int Atom::GetLabelSeqID() { return res ? res->GetLabelSeqID() : 0; } -inline int Atom::GetLabelEntityID() { return res ? res->GetLabelEntityID() : 0; } -inline int Atom::GetResidueNo() { return res ? res->GetResidueNo() : 0; } -inline int Atom::GetSSEType() { return res ? res->SSE : SSE_None; } -inline bool Atom::isSolvent() { return res ? res->isSolvent() : false; } -inline bool Atom::isNTerminus() { return res ? res->isNTerminus() : false; } -inline bool Atom::isCTerminus() { return res ? res->isCTerminus() : false; } -inline pstr Atom::GetInsCode() { return res->GetInsCode(); } -inline pstr Atom::GetResName() { return res->GetResName(); } -inline int Atom::GetModelNum() { return res->GetModelNum(); } -inline int Atom::GetIndex() { return ai; } -inline void Atom::SetCoordinates(realtype xx, realtype yy, realtype zz, - realtype occ, realtype tF) { - auto &a = g(); a.pos = gemmi::Position(xx, yy, zz); a.occ = (float)occ; a.b_iso = (float)tF; -} - -// ---- Residue out-of-line ---- -inline pstr Residue::GetResName() { - std::snprintf(_resname_buf, sizeof(_resname_buf), "%s", g().name.c_str()); - return _resname_buf; -} -inline int &Residue::GetSeqNum() { return g().seqid.num.value; } -inline pstr Residue::GetInsCode() { - _inscode_buf[0] = g().seqid.icode == ' ' ? '\0' : g().seqid.icode; _inscode_buf[1] = '\0'; - return _inscode_buf; -} -inline pstr Residue::GetChainID() { return chain->GetChainID(); } -inline int Residue::GetModelNum() { return chain->model->GetSerNum(); } -inline PAtom Residue::GetAtom(const AtomName aname, const Element elname, const AltLoc aloc) { - for (Atom *a : atoms) { - if (a->g().name != aname) continue; - if (elname && *elname && a->g().element.name() != std::string(elname)) continue; - if (aloc && *aloc && a->g().altloc != aloc[0]) continue; - return a; - } - return nullptr; -} -inline PAtom Residue::AddAtom(Manager &m, gemmi::Atom a) { - g().atoms.push_back(std::move(a)); - Atom *aw = m.newAtom(); aw->mgr = &m; aw->res = this; aw->ai = (int)atoms.size(); - atoms.push_back(aw); - return aw; -} -inline void Residue::DeleteAtom(int pos) { - if (pos < 0 || pos >= (int)atoms.size()) return; - g().atoms.erase(g().atoms.begin() + pos); - atoms[pos]->alive = false; atoms[pos]->ai = -1; - atoms.erase(atoms.begin() + pos); - for (int k = pos; k < (int)atoms.size(); ++k) atoms[k]->ai = k; -} - -// ---- Chain out-of-line ---- -inline bool Chain::isAminoacidChain() { - for (Residue *r : residues) if (r->isAminoacid()) return true; - return false; -} -inline bool Chain::isNucleotideChain() { - for (Residue *r : residues) if (r->isNucleotide()) return true; - return false; -} -inline bool Chain::isSolventChain() { - if (residues.empty()) return false; - for (Residue *r : residues) if (!r->isSolvent()) return false; - return true; -} -inline pstr Chain::GetChainID() { - std::snprintf(_chainid_buf, sizeof(_chainid_buf), "%s", g().name.c_str()); - return _chainid_buf; -} -inline PResidue Chain::AddResidue(Manager &m, gemmi::Residue r) { - g().residues.push_back(std::move(r)); - Residue *rw = m.newRes(); rw->mgr = &m; rw->chain = this; rw->ri = (int)residues.size(); - for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { - Atom *aw = m.newAtom(); aw->mgr = &m; aw->res = rw; aw->ai = ai; rw->atoms.push_back(aw); - } - residues.push_back(rw); - return rw; -} -inline PResidue Chain::InsResidue(Manager &m, int pos, gemmi::Residue r) { - g().residues.insert(g().residues.begin() + pos, std::move(r)); - Residue *rw = m.newRes(); rw->mgr = &m; rw->chain = this; rw->ri = pos; - residues.insert(residues.begin() + pos, rw); - for (int k = pos + 1; k < (int)residues.size(); ++k) residues[k]->ri = k; - for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { - Atom *aw = m.newAtom(); aw->mgr = &m; aw->res = rw; aw->ai = ai; rw->atoms.push_back(aw); - } - return rw; -} - -// ---- Model out-of-line ---- -inline PChain Model::GetChain(const ChainID chID) { - for (Chain *c : chains) if (c->g().name == chID) return c; - return nullptr; -} - -// ---- Manager out-of-line ---- -inline void Manager::build_from_gemmi() { - models.clear(); - all_atoms.clear(); - for (int mi = 0; mi < (int)st.models.size(); ++mi) { - Model *mw = newModel(); mw->mgr = this; mw->mi = mi; - auto &gm = st.models[mi]; - for (int ci = 0; ci < (int)gm.chains.size(); ++ci) { - Chain *cw = newChain(); cw->mgr = this; cw->model = mw; cw->ci = ci; - auto &gc = gm.chains[ci]; - for (int ri = 0; ri < (int)gc.residues.size(); ++ri) { - Residue *rw = newRes(); rw->mgr = this; rw->chain = cw; rw->ri = ri; - auto &gr = gc.residues[ri]; - for (int ai = 0; ai < (int)gr.atoms.size(); ++ai) { - Atom *aw = newAtom(); aw->mgr = this; aw->res = rw; aw->ai = ai; - aw->WhatIsSet = ASET_Coordinates | ASET_Occupancy | ASET_tempFactor; - const gemmi::SMat33 &an = gr.atoms[ai].aniso; - if (an.u11 != 0.f || an.u22 != 0.f || an.u33 != 0.f) aw->WhatIsSet |= ASET_Anis_tFac; - rw->atoms.push_back(aw); all_atoms.push_back(aw); mw->all_atoms.push_back(aw); - } - rw->_sync_atom(); - rw->_load_id(); - cw->residues.push_back(rw); - } - mw->chains.push_back(cw); - } - models.push_back(mw); - } - _load_metadata(); -} - -// Map gemmi's structure-level metadata (connections / cispeps / helices / -// sheets) onto the MMDB per-Model record containers. gemmi is the reader; the -// shim just re-shapes. Connections/helices/sheets are not model-scoped in gemmi, -// so they go on model 1 (MMDB's usual home); cispeps honour their model_num. -inline void Manager::_load_metadata() { - link_pool.clear(); linkr_pool.clear(); cispep_pool.clear(); helix_pool.clear(); - sheet_pool.clear(); strand_pool.clear(); strandarr_pool.clear(); author_pool.clear(); - - // PDB title AUTHOR records (gemmi meta.authors) - title.author.data.clear(); - for (const std::string &au : st.meta.authors) { - author_pool.emplace_back(); - std::snprintf(author_pool.back().Line, sizeof(author_pool.back().Line), "%s", au.c_str()); - title.author.data.push_back(&author_pool.back()); - } - if (models.empty()) return; - - auto fill_ends = [](const gemmi::AtomAddress &a, ChainID &cid, ResName &rn, - int &seq, InsCode &ic, AtomName *an, AltLoc *al) { - std::snprintf(cid, sizeof(ChainID), "%s", a.chain_name.c_str()); - std::snprintf(rn, sizeof(ResName), "%s", a.res_id.name.c_str()); - seq = a.res_id.seqid.num.value; - ic[0] = (a.res_id.seqid.icode && a.res_id.seqid.icode != ' ') ? a.res_id.seqid.icode : '\0'; - ic[1] = '\0'; - if (an) std::snprintf(*an, sizeof(AtomName), "%s", a.atom_name.c_str()); - if (al) { (*al)[0] = a.altloc ? a.altloc : '\0'; (*al)[1] = '\0'; } - }; - - // --- LINK records (gemmi Connection) -> model 1 --- - Model *m1 = models[0]; - for (const gemmi::Connection &cn : st.connections) { - link_pool.emplace_back(); - Link &l = link_pool.back(); - fill_ends(cn.partner1, l.chainID1, l.resName1, l.seqNum1, l.insCode1, &l.atName1, &l.aloc1); - fill_ends(cn.partner2, l.chainID2, l.resName2, l.seqNum2, l.insCode2, &l.atName2, &l.aloc2); - l.dist = cn.reported_distance; - m1->_links.push_back(&l); - // a connection carrying a Refmac link id is also a LINKR record - if (!cn.link_id.empty()) { - linkr_pool.emplace_back(); - LinkR &lr = linkr_pool.back(); - std::snprintf(lr.linkRID, sizeof(lr.linkRID), "%s", cn.link_id.c_str()); - AtomName an; AltLoc al; - fill_ends(cn.partner1, lr.chainID1, lr.resName1, lr.seqNum1, lr.insCode1, &an, &al); - std::snprintf(lr.atName1, sizeof(AtomName), "%s", an); std::snprintf(lr.aloc1, sizeof(AltLoc), "%s", al); - fill_ends(cn.partner2, lr.chainID2, lr.resName2, lr.seqNum2, lr.insCode2, &an, &al); - std::snprintf(lr.atName2, sizeof(AtomName), "%s", an); std::snprintf(lr.aloc2, sizeof(AltLoc), "%s", al); - lr.dist = cn.reported_distance; - m1->_linkrs.push_back(&lr); - } - } - - // --- CISPEP records (gemmi CisPep) -> model by model_num (default 1) --- - for (const gemmi::CisPep &cp : st.cispeps) { - int mnum = cp.model_num > 0 ? cp.model_num : 1; - Model *mw = GetModel(mnum); - if (!mw) mw = m1; - cispep_pool.emplace_back(); - CisPep &c = cispep_pool.back(); - InsCode ic1, ic2; int s1, s2; - fill_ends(cp.partner_c, c.chainID1, c.pep1, s1, ic1, nullptr, nullptr); - fill_ends(cp.partner_n, c.chainID2, c.pep2, s2, ic2, nullptr, nullptr); - c.seqNum1 = s1; std::snprintf(c.icode1, sizeof(InsCode), "%s", ic1); - c.seqNum2 = s2; std::snprintf(c.icode2, sizeof(InsCode), "%s", ic2); - c.modNum = mnum; - if (!std::isnan(cp.reported_angle)) c.measure = cp.reported_angle; - mw->_cispeps.push_back(&c); - } - - // --- HELIX records (gemmi Helix) -> model 1 --- - for (const gemmi::Helix &gh : st.helices) { - helix_pool.emplace_back(); - Helix &h = helix_pool.back(); - AtomName an; AltLoc al; - fill_ends(gh.start, h.initChainID, h.initResName, h.initSeqNum, h.initICode, &an, &al); - fill_ends(gh.end, h.endChainID, h.endResName, h.endSeqNum, h.endICode, &an, &al); - h.helixClass = (int) gh.pdb_helix_class; - h.length = gh.length; - h.serNum = (int) helix_pool.size(); - m1->helices.AddData(&h); - } - - // --- SHEET / STRAND records (gemmi Sheet) -> model 1 --- - if (!st.sheets.empty()) { - m1->sheets.nSheets = (int) st.sheets.size(); - m1->_sheet_ptrs.assign(st.sheets.size(), nullptr); // backs Sheets::sheet (Sheet**) - for (size_t is = 0; is < st.sheets.size(); ++is) { - const gemmi::Sheet &gs = st.sheets[is]; - sheet_pool.emplace_back(); - Sheet &sh = sheet_pool.back(); - std::snprintf(sh.sheetID, sizeof(sh.sheetID), "%s", gs.name.c_str()); - sh.nStrands = (int) gs.strands.size(); - strandarr_pool.emplace_back(); - std::vector &sarr = strandarr_pool.back(); - sarr.reserve(gs.strands.size()); - for (const gemmi::Sheet::Strand &gst : gs.strands) { - strand_pool.emplace_back(); - Strand &str = strand_pool.back(); - AtomName an; AltLoc al; - fill_ends(gst.start, str.initChainID, str.initResName, str.initSeqNum, str.initICode, &an, &al); - fill_ends(gst.end, str.endChainID, str.endResName, str.endSeqNum, str.endICode, &an, &al); - std::snprintf(str.sheetID, sizeof(str.sheetID), "%s", gs.name.c_str()); - str.strandNo = (int) sarr.size() + 1; - str.sense = gst.sense; - sarr.push_back(&str); - } - sh.strand = sarr.data(); - m1->_sheet_ptrs[is] = &sh; - } - m1->sheets.sheet = m1->_sheet_ptrs.data(); - } -} - -// ---- Manager::PutAtom (hierarchy insertion) ---- -inline int Manager::PutAtom(int index, PAtom A, int serNum) { - if (!A) return 0; - Residue *src = A->res; - // ensure a model exists (Coot calls PutAtom on a fresh, empty Manager) - Model *mw = models.empty() ? nullptr : models[0]; - if (!mw) { - st.models.emplace_back(1); - mw = newModel(); mw->mgr = this; mw->mi = 0; - models.push_back(mw); - } - // find or create the chain implied by the source atom's chain - std::string cid = (src && src->chain) ? src->chain->g().name : std::string("A"); - Chain *cw = mw->GetChain(cid.c_str()); - if (!cw) cw = mw->CreateChain(cid.c_str()); - // find or create the residue implied by (seqNum, insCode) - int seq = src ? src->g().seqid.num.value : 0; - char ic = src ? src->g().seqid.icode : ' '; - char icn = ic ? ic : ' '; - Residue *rw = nullptr; - for (Residue *r : cw->residues) { - gemmi::Residue &gr = r->g(); - if (gr.seqid.num.value == seq && (gr.seqid.icode ? gr.seqid.icode : ' ') == icn) { rw = r; break; } - } - if (!rw) { - gemmi::Residue gr; - gr.name = src ? src->g().name : std::string("UNK"); - gr.seqid.num = seq; - gr.seqid.icode = icn; - rw = cw->AddResidue(*this, gr); - rw->_load_id(); - } - // append a copy of the atom's gemmi backing + register it in the flat tables - Atom *aw = rw->AddAtom(*this, A->g()); - aw->WhatIsSet = A->WhatIsSet; aw->Het = A->Het; - std::memcpy(aw->segID, A->segID, sizeof aw->segID); - aw->g().serial = serNum ? serNum : (index > 0 ? index : (int)all_atoms.size() + 1); - rw->_sync_atom(); - all_atoms.push_back(aw); mw->all_atoms.push_back(aw); - return (int)all_atoms.size(); // 1-based position (GetAtomI(pos) returns aw) -} - -// ---- selection matching ---- -namespace detail { -inline bool inList(cpstr list, const std::string &v) { - if (!list || !*list || std::strcmp(list, "*") == 0) return true; - const char *p = list; - while (*p) { - const char *c = std::strchr(p, ','); - std::string tok(p, c ? (size_t)(c - p) : std::strlen(p)); - size_t a = tok.find_first_not_of(' '), b = tok.find_last_not_of(' '); - tok = (a == std::string::npos) ? std::string() : tok.substr(a, b - a + 1); - if (tok == v) return true; - if (!c) break; p = c + 1; - } - return false; -} -inline bool altMatch(cpstr list, char alt) { - if (!list || std::strcmp(list, "*") == 0) return true; - std::string a = alt ? std::string(1, alt) : std::string(); - if (!*list) return a.empty(); // "" -> only blank altLoc - return inList(list, a); -} -} // namespace detail - -inline void Manager::Select(int selHnd, SELECTION_TYPE sType, int iModel, - cpstr Chains, int ResNo1, cpstr Ins1, int ResNo2, cpstr Ins2, cpstr RNames, - cpstr ANames, cpstr Elements, cpstr altLocs, SELECTION_KEY selKey) { - Selection &sel = selections[selHnd - 1]; - if (sel.type == STYPE_UNDEFINED) sel.type = sType; - std::vector oldA = sel.atoms; std::vector oldR = sel.residues; - std::vector oldC = sel.chains; - - std::vector mAtoms; std::vector mResidues; std::vector mChains; - for (Model *mw : models) { - if (iModel > 0 && mw->GetSerNum() != iModel) continue; - for (Chain *cw : mw->chains) { - if (!detail::inList(Chains, cw->g().name)) continue; - bool anyResidue = false; - for (Residue *rw : cw->residues) { - int sn = rw->g().seqid.num.value; - char ric = rw->g().seqid.icode ? rw->g().seqid.icode : ' '; - // (seqNum, insCode) range: an explicit insCode only constrains the - // boundary residue; blank/"*" includes every insCode at that seqNum. - if (ResNo1 != ANY_RES) { - if (sn < ResNo1) continue; - if (sn == ResNo1 && Ins1 && Ins1[0] && std::strcmp(Ins1, "*") && ric < Ins1[0]) continue; - } - if (ResNo2 != ANY_RES) { - if (sn > ResNo2) continue; - if (sn == ResNo2 && Ins2 && Ins2[0] && std::strcmp(Ins2, "*") && ric > Ins2[0]) continue; - } - if (!detail::inList(RNames, rw->g().name)) continue; - bool anyAtom = false; - for (Atom *aw : rw->atoms) { - if (!detail::inList(ANames, aw->g().name)) continue; - if (!detail::inList(Elements, aw->g().element.name())) continue; - if (!detail::altMatch(altLocs, aw->g().altloc)) continue; - anyAtom = true; - if (sType == STYPE_ATOM) mAtoms.push_back(aw); - } - if (anyAtom) anyResidue = true; - if (anyAtom && sType == STYPE_RESIDUE) mResidues.push_back(rw); - } - // STYPE_CHAIN: a chain matching the chain filter (and, if given, having a - // residue that passes the residue/atom filters) is selected whole. - if (sType == STYPE_CHAIN && anyResidue) mChains.push_back(cw); - } - } - auto combine = [&](auto &cur, auto &matched) { - using Vec = typename std::decay::type; - std::set curset(cur.begin(), cur.end()); - std::set mset(matched.begin(), matched.end()); - if (selKey == SKEY_NEW) { cur = matched; } - else if (selKey == SKEY_OR) { for (auto *x : matched) if (!curset.count(x)) cur.push_back(x); } - else if (selKey == SKEY_AND) { Vec o; for (auto *x : cur) if (mset.count(x)) o.push_back(x); cur = o; } - else if (selKey == SKEY_XOR) { Vec o; for (auto *x : cur) if (!mset.count(x)) o.push_back(x); - for (auto *x : matched) if (!curset.count(x)) o.push_back(x); cur = o; } - else if (selKey == SKEY_CLR) { Vec o; for (auto *x : cur) if (!mset.count(x)) o.push_back(x); cur = o; } - }; - if (sType == STYPE_ATOM) combine(sel.atoms, mAtoms); - else if (sType == STYPE_RESIDUE) combine(sel.residues, mResidues); - else if (sType == STYPE_CHAIN) combine(sel.chains, mChains); - for (Atom *a : oldA) a->_setInSel(selHnd, false); - for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); - for (Residue *r : oldR) r->_setInSel(selHnd, false); - for (Residue *r : sel.residues) r->_setInSel(selHnd, true); - for (Chain *c : oldC) c->_setInSel(selHnd, false); - for (Chain *c : sel.chains) c->_setInSel(selHnd, true); -} - -// select-from-selection: combine selHnd2's contents into selHnd1 -inline void Manager::Select(int selHnd1, SELECTION_TYPE sType, int selHnd2, - SELECTION_KEY sKey) { - Selection &s1 = selections[selHnd1 - 1]; - Selection &s2 = selections[selHnd2 - 1]; - if (s1.type == STYPE_UNDEFINED) s1.type = sType; - std::vector oldA = s1.atoms; std::vector oldR = s1.residues; - auto combine = [&](auto &cur, auto &m) { - using Vec = typename std::decay::type; - std::set curset(cur.begin(), cur.end()); - std::set mset(m.begin(), m.end()); - if (sKey == SKEY_NEW) cur = m; - else if (sKey == SKEY_OR) { for (auto *x : m) if (!curset.count(x)) cur.push_back(x); } - else if (sKey == SKEY_AND) { Vec o; for (auto *x : cur) if (mset.count(x)) o.push_back(x); cur = o; } - else if (sKey == SKEY_XOR) { Vec o; for (auto *x : cur) if (!mset.count(x)) o.push_back(x); - for (auto *x : m) if (!curset.count(x)) o.push_back(x); cur = o; } - else if (sKey == SKEY_CLR) { Vec o; for (auto *x : cur) if (!mset.count(x)) o.push_back(x); cur = o; } - }; - if (sType == STYPE_ATOM) combine(s1.atoms, s2.atoms); - else if (sType == STYPE_RESIDUE) combine(s1.residues, s2.residues); - for (Atom *a : oldA) a->_setInSel(selHnd1, false); - for (Atom *a : s1.atoms) a->_setInSel(selHnd1, true); - for (Residue *r : oldR) r->_setInSel(selHnd1, false); - for (Residue *r : s1.residues) r->_setInSel(selHnd1, true); -} - -inline void Manager::SelectAtom(int selHnd, PAtom atom, SELECTION_KEY sKey, bool) { - Selection &sel = selections[selHnd - 1]; - if (sel.type == STYPE_UNDEFINED) sel.type = STYPE_ATOM; - if (sKey == SKEY_NEW) { - for (Atom *a : sel.atoms) a->_setInSel(selHnd, false); - sel.atoms.clear(); - } - if (atom && !atom->isInSelection(selHnd)) { - sel.atoms.push_back(atom); atom->_setInSel(selHnd, true); - } -} - -// Pragmatic CID parser: "/model/chain/seqNum1[.ins1]-seqNum2[.ins2]/atom" -// (best-effort; strips (resname)/[element]/:altloc suffixes; parses insertion -// codes after '.'). Not the full MMDB CID grammar but covers Coot's usage. -inline void Manager::Select(int selHnd, SELECTION_TYPE sType, cpstr CID, - SELECTION_KEY sKey) { - std::string s = CID ? CID : ""; - std::vector t; - size_t p = (!s.empty() && s[0] == '/') ? 1 : 0; - while (p <= s.size()) { - size_t q = s.find('/', p); - t.push_back(s.substr(p, q == std::string::npos ? std::string::npos : q - p)); - if (q == std::string::npos) break; - p = q + 1; - } - auto tok = [&](size_t i) { return i < t.size() ? t[i] : std::string(); }; - auto strip = [](std::string v, const char *seps) { - size_t c = v.find_first_of(seps); return c == std::string::npos ? v : v.substr(0, c); - }; - int iModel = 0; std::string m = tok(0); - if (!m.empty() && m != "*" && m != "0") iModel = atoi(m.c_str()); - std::string chains = tok(1).empty() ? "*" : tok(1); - int r1 = ANY_RES, r2 = ANY_RES; - std::string ins1 = "*", ins2 = "*"; - // split "num[.ins]" into number + insertion code - auto parse_resid = [](const std::string &v, int &num, std::string &ins) { - size_t dot = v.find('.'); - num = atoi(v.substr(0, dot).c_str()); - ins = (dot == std::string::npos) ? std::string() : v.substr(dot + 1); - }; - std::string rr = strip(tok(2), "("); // drop (resname) - if (!rr.empty() && rr != "*") { - size_t dash = rr.find('-', rr[0] == '-' ? 1 : 0); - if (dash == std::string::npos) { parse_resid(rr, r1, ins1); r2 = r1; ins2 = ins1; } - else { parse_resid(rr.substr(0, dash), r1, ins1); parse_resid(rr.substr(dash + 1), r2, ins2); } - } - std::string anames = strip(strip(tok(3), "["), ":"); // drop [element]/:altloc - if (anames.empty()) anames = "*"; - Select(selHnd, sType, iModel, chains.c_str(), r1, ins1.c_str(), r2, ins2.c_str(), "*", - anames.c_str(), "*", "*", sKey); -} - -inline int Manager::GetNumberOfAtoms(cpstr CID) { - int h = NewSelection(); - Select(h, STYPE_ATOM, CID, SKEY_NEW); - int n = (int)selections[h - 1].atoms.size(); - DeleteSelection(h); - return n; -} - -inline void Manager::GetAtomStatistics(int selHnd, RAtomStat AS) { - AS = AtomStat(); - std::vector &atoms = selections[selHnd - 1].atoms; - AS.nAtoms = (int)atoms.size(); - if (atoms.empty()) return; - double sx = 0, sy = 0, sz = 0; - AS.xmin = AS.xmax = atoms[0]->x(); - AS.ymin = AS.ymax = atoms[0]->y(); - AS.zmin = AS.zmax = atoms[0]->z(); - for (Atom *a : atoms) { - double X = a->x(), Y = a->y(), Z = a->z(); - sx += X; sy += Y; sz += Z; - AS.xmin = X < AS.xmin ? X : AS.xmin; AS.xmax = X > AS.xmax ? X : AS.xmax; - AS.ymin = Y < AS.ymin ? Y : AS.ymin; AS.ymax = Y > AS.ymax ? Y : AS.ymax; - AS.zmin = Z < AS.zmin ? Z : AS.zmin; AS.zmax = Z > AS.zmax ? Z : AS.zmax; - } - AS.xm = sx / atoms.size(); AS.ym = sy / atoms.size(); AS.zm = sz / atoms.size(); -} - -inline void Manager::SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, - realtype y, realtype z, realtype r, SELECTION_KEY sKey) { - Selection &sel = selections[selHnd - 1]; - if (sel.type == STYPE_UNDEFINED) sel.type = sType; - std::vector oldA = sel.atoms; std::vector oldR = sel.residues; - gemmi::Position c(x, y, z); double r2 = r * r; - std::vector mAtoms; std::vector mResidues; - for (Model *mw : models) - for (Chain *cw : mw->chains) - for (Residue *rw : cw->residues) { - bool any = false; - for (Atom *aw : rw->atoms) - if (aw->g().pos.dist_sq(c) <= r2) { any = true; if (sType == STYPE_ATOM) mAtoms.push_back(aw); } - if (any && sType == STYPE_RESIDUE) mResidues.push_back(rw); - } - auto combine = [&](auto &cur, auto &m) { - std::set::type::value_type> cs(cur.begin(), cur.end()); - if (sKey == SKEY_NEW) cur = m; - else if (sKey == SKEY_OR) { for (auto *p : m) if (!cs.count(p)) cur.push_back(p); } - }; - if (sType == STYPE_ATOM) combine(sel.atoms, mAtoms); - else if (sType == STYPE_RESIDUE) combine(sel.residues, mResidues); - for (Atom *a : oldA) a->_setInSel(selHnd, false); - for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); - for (Residue *r : oldR) r->_setInSel(selHnd, false); - for (Residue *r : sel.residues) r->_setInSel(selHnd, true); -} - -// SeekContacts (both overloads) is defined in mmdb-shim/src/contacts.cc using -// gemmi::NeighborSearch — keeps the heavy neighbor.hpp out of Coot's many TUs. - -// ---- detached-construction constructors + subtree ops (need complete types) ---- -inline Atom::Atom(Residue *r) { if (r) r->AddAtom(this); } -inline Residue::Residue(Chain *c) { if (c) c->AddResidue(this); } -inline Chain::Chain(Model *m, const ChainID id) { if (m) m->AddChain(this); SetChainID(id); } - -// peptide-bond distance threshold for backbone C-N (a real bond is ~1.33 A). -inline bool Residue::isNTerminus() { - if (!chain || ri <= 0) return true; // first (or detached) residue - const gemmi::Atom *N = g().get_n(); - const gemmi::Atom *prevC = chain->residues[ri - 1]->g().get_c(); - if (!N || !prevC) return true; // missing backbone -> terminus - return N->pos.dist(prevC->pos) > 1.7; // not bonded to previous C -} -inline bool Residue::isCTerminus() { - if (!chain || ri < 0 || ri >= (int)chain->residues.size() - 1) return true; // last/detached - const gemmi::Atom *C = g().get_c(); - const gemmi::Atom *nextN = chain->residues[ri + 1]->g().get_n(); - if (!C || !nextN) return true; - return C->pos.dist(nextN->pos) > 1.7; // not bonded to next N -} -inline Model *Residue::GetModel() { return chain ? chain->model : nullptr; } - -inline void Chain::Copy(PChain src) { - Manager *pool = mgr ? mgr : src->mgr; - g() = src->g(); // deep gemmi copy (residues + atoms) - residues.clear(); - if (!pool) return; - gemmi::Chain &gc = g(); - for (int r = 0; r < (int)gc.residues.size(); ++r) { - Residue *rw = pool->newRes(); rw->mgr = mgr; rw->chain = this; rw->ri = r; - for (int a = 0; a < (int)gc.residues[r].atoms.size(); ++a) { - Atom *aw = pool->newAtom(); aw->mgr = mgr; aw->res = rw; aw->ai = a; - rw->atoms.push_back(aw); - } - rw->_sync_atom(); rw->_load_id(); - residues.push_back(rw); - } -} - -inline void Model::Copy(PModel src) { - Manager *pool = mgr ? mgr : src->mgr; - g() = src->g(); - chains.clear(); - if (!pool) return; - gemmi::Model &gm = g(); - for (int c = 0; c < (int)gm.chains.size(); ++c) { - Chain *cw = pool->newChain(); cw->mgr = mgr; cw->model = this; cw->ci = c; - for (int r = 0; r < (int)gm.chains[c].residues.size(); ++r) { - Residue *rw = pool->newRes(); rw->mgr = mgr; rw->chain = cw; rw->ri = r; - for (int a = 0; a < (int)gm.chains[c].residues[r].atoms.size(); ++a) { - Atom *aw = pool->newAtom(); aw->mgr = mgr; aw->res = rw; aw->ai = a; - rw->atoms.push_back(aw); - } - rw->_sync_atom(); rw->_load_id(); - cw->residues.push_back(rw); - } - chains.push_back(cw); - } -} - -inline PChain Model::CreateChain(const ChainID id) { - Chain *c = mgr ? mgr->newChain() : new Chain(); - c->mgr = mgr; c->model = this; c->ci = (int)chains.size(); - g().chains.emplace_back(id ? id : ""); - chains.push_back(c); - return c; -} - -inline pstr Atom::GetAtomID(pstr S) { - if (S) std::snprintf(S, 100, "/%d/%s/%d(%s)/%s", GetModelNum(), GetChainID(), - res ? res->GetSeqNum() : 0, GetResName(), GetAtomName()); - return S; -} - -// one-letter residue code (mmdb_tables.h) via gemmi's tabulated residues -inline void Get1LetterCode(cpstr res3, pstr res1) { - if (!res1) return; - char c = gemmi::find_tabulated_residue(res3 ? res3 : "").one_letter_code; - res1[0] = c ? (char) std::toupper((unsigned char) c) : 'X'; res1[1] = '\0'; -} -inline void Get1LetterCode(cpstr res3, char &res1) { char b[2]; Get1LetterCode(res3, b); res1 = b[0]; } - -// sort a contact array by distance (mmdb_coormngr.h SortContacts) — sortkey ignored -inline void SortContacts(PContact contacts, int nContacts, int /*sortkey*/) { - if (contacts && nContacts > 1) - std::sort(contacts, contacts + nContacts, - [](const Contact &a, const Contact &b) { return a.dist < b.dist; }); -} - -// centroid of an atom array (mmdb_coormngr.h GetMassCenter) -inline void GetMassCenter(PPAtom A, int nA, realtype &xc, realtype &yc, realtype &zc) { - double sx = 0, sy = 0, sz = 0; int n = 0; - for (int i = 0; i < nA; ++i) if (A[i]) { sx += A[i]->x(); sy += A[i]->y(); sz += A[i]->z(); ++n; } - if (n) { xc = sx / n; yc = sy / n; zc = sz / n; } else { xc = yc = zc = 0; } -} - -} // namespace mmdb + } + inline bool Chain::isNucleotideChain() { + for (Residue *r : residues) + if (r->isNucleotide()) return true; + return false; + } + inline bool Chain::isSolventChain() { + if (residues.empty()) return false; + for (Residue *r : residues) + if (!r->isSolvent()) return false; + return true; + } + inline pstr Chain::GetChainID() { + std::snprintf(_chainid_buf, sizeof(_chainid_buf), "%s", g().name.c_str()); + return _chainid_buf; + } + inline PResidue Chain::AddResidue(Manager &m, gemmi::Residue r) { + g().residues.push_back(std::move(r)); + Residue *rw = m.newRes(); + rw->mgr = &m; + rw->chain = this; + rw->ri = (int)residues.size(); + for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { + Atom *aw = m.newAtom(); + aw->mgr = &m; + aw->res = rw; + aw->ai = ai; + rw->atoms.push_back(aw); + } + residues.push_back(rw); + return rw; + } + inline PResidue Chain::InsResidue(Manager &m, int pos, gemmi::Residue r) { + g().residues.insert(g().residues.begin() + pos, std::move(r)); + Residue *rw = m.newRes(); + rw->mgr = &m; + rw->chain = this; + rw->ri = pos; + residues.insert(residues.begin() + pos, rw); + for (int k = pos + 1; k < (int)residues.size(); ++k) residues[k]->ri = k; + for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { + Atom *aw = m.newAtom(); + aw->mgr = &m; + aw->res = rw; + aw->ai = ai; + rw->atoms.push_back(aw); + } + return rw; + } + + // ---- Model out-of-line ---- + inline PChain Model::GetChain(const ChainID chID) { + for (Chain *c : chains) + if (c->g().name == chID) return c; + return nullptr; + } + + // ---- Manager out-of-line ---- + inline void Manager::build_from_gemmi() { + models.clear(); + all_atoms.clear(); + for (int mi = 0; mi < (int)st.models.size(); ++mi) { + Model *mw = newModel(); + mw->mgr = this; + mw->mi = mi; + auto &gm = st.models[mi]; + for (int ci = 0; ci < (int)gm.chains.size(); ++ci) { + Chain *cw = newChain(); + cw->mgr = this; + cw->model = mw; + cw->ci = ci; + auto &gc = gm.chains[ci]; + for (int ri = 0; ri < (int)gc.residues.size(); ++ri) { + Residue *rw = newRes(); + rw->mgr = this; + rw->chain = cw; + rw->ri = ri; + auto &gr = gc.residues[ri]; + for (int ai = 0; ai < (int)gr.atoms.size(); ++ai) { + Atom *aw = newAtom(); + aw->mgr = this; + aw->res = rw; + aw->ai = ai; + aw->WhatIsSet = ASET_Coordinates | ASET_Occupancy | ASET_tempFactor; + const gemmi::SMat33 &an = gr.atoms[ai].aniso; + if (an.u11 != 0.f || an.u22 != 0.f || an.u33 != 0.f) aw->WhatIsSet |= ASET_Anis_tFac; + rw->atoms.push_back(aw); + all_atoms.push_back(aw); + mw->all_atoms.push_back(aw); + } + rw->_sync_atom(); + rw->_load_id(); + cw->residues.push_back(rw); + } + mw->chains.push_back(cw); + } + models.push_back(mw); + } + _load_metadata(); + } + + // Map gemmi's structure-level metadata (connections / cispeps / helices / + // sheets) onto the MMDB per-Model record containers. gemmi is the reader; the + // shim just re-shapes. Connections/helices/sheets are not model-scoped in gemmi, + // so they go on model 1 (MMDB's usual home); cispeps honour their model_num. + inline void Manager::_load_metadata() { + link_pool.clear(); + linkr_pool.clear(); + cispep_pool.clear(); + helix_pool.clear(); + sheet_pool.clear(); + strand_pool.clear(); + strandarr_pool.clear(); + author_pool.clear(); + + // PDB title AUTHOR records (gemmi meta.authors) + title.author.data.clear(); + for (const std::string &au : st.meta.authors) { + author_pool.emplace_back(); + std::snprintf(author_pool.back().Line, sizeof(author_pool.back().Line), "%s", au.c_str()); + title.author.data.push_back(&author_pool.back()); + } + if (models.empty()) return; + + auto fill_ends = [](const gemmi::AtomAddress &a, ChainID &cid, ResName &rn, + int &seq, InsCode &ic, AtomName *an, AltLoc *al) { + std::snprintf(cid, sizeof(ChainID), "%s", a.chain_name.c_str()); + std::snprintf(rn, sizeof(ResName), "%s", a.res_id.name.c_str()); + seq = a.res_id.seqid.num.value; + ic[0] = (a.res_id.seqid.icode && a.res_id.seqid.icode != ' ') ? a.res_id.seqid.icode : '\0'; + ic[1] = '\0'; + if (an) std::snprintf(*an, sizeof(AtomName), "%s", a.atom_name.c_str()); + if (al) { + (*al)[0] = a.altloc ? a.altloc : '\0'; + (*al)[1] = '\0'; + } + }; + + // --- LINK records (gemmi Connection) -> model 1 --- + Model *m1 = models[0]; + for (const gemmi::Connection &cn : st.connections) { + link_pool.emplace_back(); + Link &l = link_pool.back(); + fill_ends(cn.partner1, l.chainID1, l.resName1, l.seqNum1, l.insCode1, &l.atName1, &l.aloc1); + fill_ends(cn.partner2, l.chainID2, l.resName2, l.seqNum2, l.insCode2, &l.atName2, &l.aloc2); + l.dist = cn.reported_distance; + m1->_links.push_back(&l); + // a connection carrying a Refmac link id is also a LINKR record + if (!cn.link_id.empty()) { + linkr_pool.emplace_back(); + LinkR &lr = linkr_pool.back(); + std::snprintf(lr.linkRID, sizeof(lr.linkRID), "%s", cn.link_id.c_str()); + AtomName an; + AltLoc al; + fill_ends(cn.partner1, lr.chainID1, lr.resName1, lr.seqNum1, lr.insCode1, &an, &al); + std::snprintf(lr.atName1, sizeof(AtomName), "%s", an); + std::snprintf(lr.aloc1, sizeof(AltLoc), "%s", al); + fill_ends(cn.partner2, lr.chainID2, lr.resName2, lr.seqNum2, lr.insCode2, &an, &al); + std::snprintf(lr.atName2, sizeof(AtomName), "%s", an); + std::snprintf(lr.aloc2, sizeof(AltLoc), "%s", al); + lr.dist = cn.reported_distance; + m1->_linkrs.push_back(&lr); + } + } + + // --- CISPEP records (gemmi CisPep) -> model by model_num (default 1) --- + for (const gemmi::CisPep &cp : st.cispeps) { + int mnum = cp.model_num > 0 ? cp.model_num : 1; + Model *mw = GetModel(mnum); + if (!mw) mw = m1; + cispep_pool.emplace_back(); + CisPep &c = cispep_pool.back(); + InsCode ic1, ic2; + int s1, s2; + fill_ends(cp.partner_c, c.chainID1, c.pep1, s1, ic1, nullptr, nullptr); + fill_ends(cp.partner_n, c.chainID2, c.pep2, s2, ic2, nullptr, nullptr); + c.seqNum1 = s1; + std::snprintf(c.icode1, sizeof(InsCode), "%s", ic1); + c.seqNum2 = s2; + std::snprintf(c.icode2, sizeof(InsCode), "%s", ic2); + c.modNum = mnum; + if (!std::isnan(cp.reported_angle)) c.measure = cp.reported_angle; + mw->_cispeps.push_back(&c); + } + + // --- HELIX records (gemmi Helix) -> model 1 --- + for (const gemmi::Helix &gh : st.helices) { + helix_pool.emplace_back(); + Helix &h = helix_pool.back(); + AtomName an; + AltLoc al; + fill_ends(gh.start, h.initChainID, h.initResName, h.initSeqNum, h.initICode, &an, &al); + fill_ends(gh.end, h.endChainID, h.endResName, h.endSeqNum, h.endICode, &an, &al); + h.helixClass = (int)gh.pdb_helix_class; + h.length = gh.length; + h.serNum = (int)helix_pool.size(); + m1->helices.AddData(&h); + } + + // --- SHEET / STRAND records (gemmi Sheet) -> model 1 --- + if (!st.sheets.empty()) { + m1->sheets.nSheets = (int)st.sheets.size(); + m1->_sheet_ptrs.assign(st.sheets.size(), nullptr); // backs Sheets::sheet (Sheet**) + for (size_t is = 0; is < st.sheets.size(); ++is) { + const gemmi::Sheet &gs = st.sheets[is]; + sheet_pool.emplace_back(); + Sheet &sh = sheet_pool.back(); + std::snprintf(sh.sheetID, sizeof(sh.sheetID), "%s", gs.name.c_str()); + sh.nStrands = (int)gs.strands.size(); + strandarr_pool.emplace_back(); + std::vector &sarr = strandarr_pool.back(); + sarr.reserve(gs.strands.size()); + for (const gemmi::Sheet::Strand &gst : gs.strands) { + strand_pool.emplace_back(); + Strand &str = strand_pool.back(); + AtomName an; + AltLoc al; + fill_ends(gst.start, str.initChainID, str.initResName, str.initSeqNum, str.initICode, &an, &al); + fill_ends(gst.end, str.endChainID, str.endResName, str.endSeqNum, str.endICode, &an, &al); + std::snprintf(str.sheetID, sizeof(str.sheetID), "%s", gs.name.c_str()); + str.strandNo = (int)sarr.size() + 1; + str.sense = gst.sense; + sarr.push_back(&str); + } + sh.strand = sarr.data(); + m1->_sheet_ptrs[is] = &sh; + } + m1->sheets.sheet = m1->_sheet_ptrs.data(); + } + } + + // ---- Manager::PutAtom (hierarchy insertion) ---- + inline int Manager::PutAtom(int index, PAtom A, int serNum) { + if (!A) return 0; + Residue *src = A->res; + // ensure a model exists (Coot calls PutAtom on a fresh, empty Manager) + Model *mw = models.empty() ? nullptr : models[0]; + if (!mw) { + st.models.emplace_back(1); + mw = newModel(); + mw->mgr = this; + mw->mi = 0; + models.push_back(mw); + } + // find or create the chain implied by the source atom's chain + std::string cid = (src && src->chain) ? src->chain->g().name : std::string("A"); + Chain *cw = mw->GetChain(cid.c_str()); + if (!cw) cw = mw->CreateChain(cid.c_str()); + // find or create the residue implied by (seqNum, insCode) + int seq = src ? src->g().seqid.num.value : 0; + char ic = src ? src->g().seqid.icode : ' '; + char icn = ic ? ic : ' '; + Residue *rw = nullptr; + for (Residue *r : cw->residues) { + gemmi::Residue &gr = r->g(); + if (gr.seqid.num.value == seq && (gr.seqid.icode ? gr.seqid.icode : ' ') == icn) { + rw = r; + break; + } + } + if (!rw) { + gemmi::Residue gr; + gr.name = src ? src->g().name : std::string("UNK"); + gr.seqid.num = seq; + gr.seqid.icode = icn; + rw = cw->AddResidue(*this, gr); + rw->_load_id(); + } + // append a copy of the atom's gemmi backing + register it in the flat tables + Atom *aw = rw->AddAtom(*this, A->g()); + aw->WhatIsSet = A->WhatIsSet; + aw->Het = A->Het; + std::memcpy(aw->segID, A->segID, sizeof aw->segID); + aw->g().serial = serNum ? serNum : (index > 0 ? index : (int)all_atoms.size() + 1); + rw->_sync_atom(); + all_atoms.push_back(aw); + mw->all_atoms.push_back(aw); + return (int)all_atoms.size(); // 1-based position (GetAtomI(pos) returns aw) + } + + // ---- selection matching ---- + namespace detail { + inline bool inList(cpstr list, const std::string &v) { + if (!list || !*list || std::strcmp(list, "*") == 0) return true; + const char *p = list; + while (*p) { + const char *c = std::strchr(p, ','); + std::string tok(p, c ? (size_t)(c - p) : std::strlen(p)); + size_t a = tok.find_first_not_of(' '), b = tok.find_last_not_of(' '); + tok = (a == std::string::npos) ? std::string() : tok.substr(a, b - a + 1); + if (tok == v) return true; + if (!c) break; + p = c + 1; + } + return false; + } + inline bool altMatch(cpstr list, char alt) { + if (!list || std::strcmp(list, "*") == 0) return true; + std::string a = alt ? std::string(1, alt) : std::string(); + if (!*list) return a.empty(); // "" -> only blank altLoc + return inList(list, a); + } + } // namespace detail + + inline void Manager::Select(int selHnd, SELECTION_TYPE sType, int iModel, + cpstr Chains, int ResNo1, cpstr Ins1, int ResNo2, cpstr Ins2, cpstr RNames, + cpstr ANames, cpstr Elements, cpstr altLocs, SELECTION_KEY selKey) { + Selection &sel = selections[selHnd - 1]; + if (sel.type == STYPE_UNDEFINED) sel.type = sType; + std::vector oldA = sel.atoms; + std::vector oldR = sel.residues; + std::vector oldC = sel.chains; + + std::vector mAtoms; + std::vector mResidues; + std::vector mChains; + for (Model *mw : models) { + if (iModel > 0 && mw->GetSerNum() != iModel) continue; + for (Chain *cw : mw->chains) { + if (!detail::inList(Chains, cw->g().name)) continue; + bool anyResidue = false; + for (Residue *rw : cw->residues) { + int sn = rw->g().seqid.num.value; + char ric = rw->g().seqid.icode ? rw->g().seqid.icode : ' '; + // (seqNum, insCode) range: an explicit insCode only constrains the + // boundary residue; blank/"*" includes every insCode at that seqNum. + if (ResNo1 != ANY_RES) { + if (sn < ResNo1) continue; + if (sn == ResNo1 && Ins1 && Ins1[0] && std::strcmp(Ins1, "*") && ric < Ins1[0]) continue; + } + if (ResNo2 != ANY_RES) { + if (sn > ResNo2) continue; + if (sn == ResNo2 && Ins2 && Ins2[0] && std::strcmp(Ins2, "*") && ric > Ins2[0]) continue; + } + if (!detail::inList(RNames, rw->g().name)) continue; + bool anyAtom = false; + for (Atom *aw : rw->atoms) { + if (!detail::inList(ANames, aw->g().name)) continue; + if (!detail::inList(Elements, aw->g().element.name())) continue; + if (!detail::altMatch(altLocs, aw->g().altloc)) continue; + anyAtom = true; + if (sType == STYPE_ATOM) mAtoms.push_back(aw); + } + if (anyAtom) anyResidue = true; + if (anyAtom && sType == STYPE_RESIDUE) mResidues.push_back(rw); + } + // STYPE_CHAIN: a chain matching the chain filter (and, if given, having a + // residue that passes the residue/atom filters) is selected whole. + if (sType == STYPE_CHAIN && anyResidue) mChains.push_back(cw); + } + } + auto combine = [&](auto &cur, auto &matched) { + using Vec = typename std::decay::type; + std::set curset(cur.begin(), cur.end()); + std::set mset(matched.begin(), matched.end()); + if (selKey == SKEY_NEW) { + cur = matched; + } else if (selKey == SKEY_OR) { + for (auto *x : matched) + if (!curset.count(x)) cur.push_back(x); + } else if (selKey == SKEY_AND) { + Vec o; + for (auto *x : cur) + if (mset.count(x)) o.push_back(x); + cur = o; + } else if (selKey == SKEY_XOR) { + Vec o; + for (auto *x : cur) + if (!mset.count(x)) o.push_back(x); + for (auto *x : matched) + if (!curset.count(x)) o.push_back(x); + cur = o; + } else if (selKey == SKEY_CLR) { + Vec o; + for (auto *x : cur) + if (!mset.count(x)) o.push_back(x); + cur = o; + } + }; + if (sType == STYPE_ATOM) + combine(sel.atoms, mAtoms); + else if (sType == STYPE_RESIDUE) + combine(sel.residues, mResidues); + else if (sType == STYPE_CHAIN) + combine(sel.chains, mChains); + for (Atom *a : oldA) a->_setInSel(selHnd, false); + for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); + for (Residue *r : oldR) r->_setInSel(selHnd, false); + for (Residue *r : sel.residues) r->_setInSel(selHnd, true); + for (Chain *c : oldC) c->_setInSel(selHnd, false); + for (Chain *c : sel.chains) c->_setInSel(selHnd, true); + } + + // select-from-selection: combine selHnd2's contents into selHnd1 + inline void Manager::Select(int selHnd1, SELECTION_TYPE sType, int selHnd2, + SELECTION_KEY sKey) { + Selection &s1 = selections[selHnd1 - 1]; + Selection &s2 = selections[selHnd2 - 1]; + if (s1.type == STYPE_UNDEFINED) s1.type = sType; + std::vector oldA = s1.atoms; + std::vector oldR = s1.residues; + auto combine = [&](auto &cur, auto &m) { + using Vec = typename std::decay::type; + std::set curset(cur.begin(), cur.end()); + std::set mset(m.begin(), m.end()); + if (sKey == SKEY_NEW) + cur = m; + else if (sKey == SKEY_OR) { + for (auto *x : m) + if (!curset.count(x)) cur.push_back(x); + } else if (sKey == SKEY_AND) { + Vec o; + for (auto *x : cur) + if (mset.count(x)) o.push_back(x); + cur = o; + } else if (sKey == SKEY_XOR) { + Vec o; + for (auto *x : cur) + if (!mset.count(x)) o.push_back(x); + for (auto *x : m) + if (!curset.count(x)) o.push_back(x); + cur = o; + } else if (sKey == SKEY_CLR) { + Vec o; + for (auto *x : cur) + if (!mset.count(x)) o.push_back(x); + cur = o; + } + }; + if (sType == STYPE_ATOM) + combine(s1.atoms, s2.atoms); + else if (sType == STYPE_RESIDUE) + combine(s1.residues, s2.residues); + for (Atom *a : oldA) a->_setInSel(selHnd1, false); + for (Atom *a : s1.atoms) a->_setInSel(selHnd1, true); + for (Residue *r : oldR) r->_setInSel(selHnd1, false); + for (Residue *r : s1.residues) r->_setInSel(selHnd1, true); + } + + inline void Manager::SelectAtom(int selHnd, PAtom atom, SELECTION_KEY sKey, bool) { + Selection &sel = selections[selHnd - 1]; + if (sel.type == STYPE_UNDEFINED) sel.type = STYPE_ATOM; + if (sKey == SKEY_NEW) { + for (Atom *a : sel.atoms) a->_setInSel(selHnd, false); + sel.atoms.clear(); + } + if (atom && !atom->isInSelection(selHnd)) { + sel.atoms.push_back(atom); + atom->_setInSel(selHnd, true); + } + } + + // Pragmatic CID parser: "/model/chain/seqNum1[.ins1]-seqNum2[.ins2]/atom" + // (best-effort; strips (resname)/[element]/:altloc suffixes; parses insertion + // codes after '.'). Not the full MMDB CID grammar but covers Coot's usage. + inline void Manager::Select(int selHnd, SELECTION_TYPE sType, cpstr CID, + SELECTION_KEY sKey) { + std::string s = CID ? CID : ""; + std::vector t; + size_t p = (!s.empty() && s[0] == '/') ? 1 : 0; + while (p <= s.size()) { + size_t q = s.find('/', p); + t.push_back(s.substr(p, q == std::string::npos ? std::string::npos : q - p)); + if (q == std::string::npos) break; + p = q + 1; + } + auto tok = [&](size_t i) { return i < t.size() ? t[i] : std::string(); }; + auto strip = [](std::string v, const char *seps) { + size_t c = v.find_first_of(seps); + return c == std::string::npos ? v : v.substr(0, c); + }; + int iModel = 0; + std::string m = tok(0); + if (!m.empty() && m != "*" && m != "0") iModel = atoi(m.c_str()); + std::string chains = tok(1).empty() ? "*" : tok(1); + int r1 = ANY_RES, r2 = ANY_RES; + std::string ins1 = "*", ins2 = "*"; + // split "num[.ins]" into number + insertion code + auto parse_resid = [](const std::string &v, int &num, std::string &ins) { + size_t dot = v.find('.'); + num = atoi(v.substr(0, dot).c_str()); + ins = (dot == std::string::npos) ? std::string() : v.substr(dot + 1); + }; + std::string rr = strip(tok(2), "("); // drop (resname) + if (!rr.empty() && rr != "*") { + size_t dash = rr.find('-', rr[0] == '-' ? 1 : 0); + if (dash == std::string::npos) { + parse_resid(rr, r1, ins1); + r2 = r1; + ins2 = ins1; + } else { + parse_resid(rr.substr(0, dash), r1, ins1); + parse_resid(rr.substr(dash + 1), r2, ins2); + } + } + std::string anames = strip(strip(tok(3), "["), ":"); // drop [element]/:altloc + if (anames.empty()) anames = "*"; + Select(selHnd, sType, iModel, chains.c_str(), r1, ins1.c_str(), r2, ins2.c_str(), "*", + anames.c_str(), "*", "*", sKey); + } + + inline int Manager::GetNumberOfAtoms(cpstr CID) { + int h = NewSelection(); + Select(h, STYPE_ATOM, CID, SKEY_NEW); + int n = (int)selections[h - 1].atoms.size(); + DeleteSelection(h); + return n; + } + + inline void Manager::GetAtomStatistics(int selHnd, RAtomStat AS) { + AS = AtomStat(); + std::vector &atoms = selections[selHnd - 1].atoms; + AS.nAtoms = (int)atoms.size(); + if (atoms.empty()) return; + double sx = 0, sy = 0, sz = 0; + AS.xmin = AS.xmax = atoms[0]->x(); + AS.ymin = AS.ymax = atoms[0]->y(); + AS.zmin = AS.zmax = atoms[0]->z(); + for (Atom *a : atoms) { + double X = a->x(), Y = a->y(), Z = a->z(); + sx += X; + sy += Y; + sz += Z; + AS.xmin = X < AS.xmin ? X : AS.xmin; + AS.xmax = X > AS.xmax ? X : AS.xmax; + AS.ymin = Y < AS.ymin ? Y : AS.ymin; + AS.ymax = Y > AS.ymax ? Y : AS.ymax; + AS.zmin = Z < AS.zmin ? Z : AS.zmin; + AS.zmax = Z > AS.zmax ? Z : AS.zmax; + } + AS.xm = sx / atoms.size(); + AS.ym = sy / atoms.size(); + AS.zm = sz / atoms.size(); + } + + inline void Manager::SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, + realtype y, realtype z, realtype r, SELECTION_KEY sKey) { + Selection &sel = selections[selHnd - 1]; + if (sel.type == STYPE_UNDEFINED) sel.type = sType; + std::vector oldA = sel.atoms; + std::vector oldR = sel.residues; + gemmi::Position c(x, y, z); + double r2 = r * r; + std::vector mAtoms; + std::vector mResidues; + for (Model *mw : models) + for (Chain *cw : mw->chains) + for (Residue *rw : cw->residues) { + bool any = false; + for (Atom *aw : rw->atoms) + if (aw->g().pos.dist_sq(c) <= r2) { + any = true; + if (sType == STYPE_ATOM) mAtoms.push_back(aw); + } + if (any && sType == STYPE_RESIDUE) mResidues.push_back(rw); + } + auto combine = [&](auto &cur, auto &m) { + std::set::type::value_type> cs(cur.begin(), cur.end()); + if (sKey == SKEY_NEW) + cur = m; + else if (sKey == SKEY_OR) { + for (auto *p : m) + if (!cs.count(p)) cur.push_back(p); + } + }; + if (sType == STYPE_ATOM) + combine(sel.atoms, mAtoms); + else if (sType == STYPE_RESIDUE) + combine(sel.residues, mResidues); + for (Atom *a : oldA) a->_setInSel(selHnd, false); + for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); + for (Residue *r : oldR) r->_setInSel(selHnd, false); + for (Residue *r : sel.residues) r->_setInSel(selHnd, true); + } + + // SeekContacts (both overloads) is defined in mmdb-shim/src/contacts.cc using + // gemmi::NeighborSearch — keeps the heavy neighbor.hpp out of Coot's many TUs. + + // ---- detached-construction constructors + subtree ops (need complete types) ---- + inline Atom::Atom(Residue *r) { + if (r) r->AddAtom(this); + } + inline Residue::Residue(Chain *c) { + if (c) c->AddResidue(this); + } + inline Chain::Chain(Model *m, const ChainID id) { + if (m) m->AddChain(this); + SetChainID(id); + } + + // peptide-bond distance threshold for backbone C-N (a real bond is ~1.33 A). + inline bool Residue::isNTerminus() { + if (!chain || ri <= 0) return true; // first (or detached) residue + const gemmi::Atom *N = g().get_n(); + const gemmi::Atom *prevC = chain->residues[ri - 1]->g().get_c(); + if (!N || !prevC) return true; // missing backbone -> terminus + return N->pos.dist(prevC->pos) > 1.7; // not bonded to previous C + } + inline bool Residue::isCTerminus() { + if (!chain || ri < 0 || ri >= (int)chain->residues.size() - 1) return true; // last/detached + const gemmi::Atom *C = g().get_c(); + const gemmi::Atom *nextN = chain->residues[ri + 1]->g().get_n(); + if (!C || !nextN) return true; + return C->pos.dist(nextN->pos) > 1.7; // not bonded to next N + } + inline Model *Residue::GetModel() { return chain ? chain->model : nullptr; } + + inline void Chain::Copy(PChain src) { + Manager *pool = mgr ? mgr : src->mgr; + g() = src->g(); // deep gemmi copy (residues + atoms) + residues.clear(); + if (!pool) return; + gemmi::Chain &gc = g(); + for (int r = 0; r < (int)gc.residues.size(); ++r) { + Residue *rw = pool->newRes(); + rw->mgr = mgr; + rw->chain = this; + rw->ri = r; + for (int a = 0; a < (int)gc.residues[r].atoms.size(); ++a) { + Atom *aw = pool->newAtom(); + aw->mgr = mgr; + aw->res = rw; + aw->ai = a; + rw->atoms.push_back(aw); + } + rw->_sync_atom(); + rw->_load_id(); + residues.push_back(rw); + } + } + + inline void Model::Copy(PModel src) { + Manager *pool = mgr ? mgr : src->mgr; + g() = src->g(); + chains.clear(); + if (!pool) return; + gemmi::Model &gm = g(); + for (int c = 0; c < (int)gm.chains.size(); ++c) { + Chain *cw = pool->newChain(); + cw->mgr = mgr; + cw->model = this; + cw->ci = c; + for (int r = 0; r < (int)gm.chains[c].residues.size(); ++r) { + Residue *rw = pool->newRes(); + rw->mgr = mgr; + rw->chain = cw; + rw->ri = r; + for (int a = 0; a < (int)gm.chains[c].residues[r].atoms.size(); ++a) { + Atom *aw = pool->newAtom(); + aw->mgr = mgr; + aw->res = rw; + aw->ai = a; + rw->atoms.push_back(aw); + } + rw->_sync_atom(); + rw->_load_id(); + cw->residues.push_back(rw); + } + chains.push_back(cw); + } + } + + inline PChain Model::CreateChain(const ChainID id) { + Chain *c = mgr ? mgr->newChain() : new Chain(); + c->mgr = mgr; + c->model = this; + c->ci = (int)chains.size(); + g().chains.emplace_back(id ? id : ""); + chains.push_back(c); + return c; + } + + inline pstr Atom::GetAtomID(pstr S) { + if (S) std::snprintf(S, 100, "/%d/%s/%d(%s)/%s", GetModelNum(), GetChainID(), + res ? res->GetSeqNum() : 0, GetResName(), GetAtomName()); + return S; + } + + // one-letter residue code (mmdb_tables.h) via gemmi's tabulated residues + inline void Get1LetterCode(cpstr res3, pstr res1) { + if (!res1) return; + char c = gemmi::find_tabulated_residue(res3 ? res3 : "").one_letter_code; + res1[0] = c ? (char)std::toupper((unsigned char)c) : 'X'; + res1[1] = '\0'; + } + inline void Get1LetterCode(cpstr res3, char &res1) { + char b[2]; + Get1LetterCode(res3, b); + res1 = b[0]; + } + + // sort a contact array by distance (mmdb_coormngr.h SortContacts) — sortkey ignored + inline void SortContacts(PContact contacts, int nContacts, int /*sortkey*/) { + if (contacts && nContacts > 1) + std::sort(contacts, contacts + nContacts, + [](const Contact &a, const Contact &b) { return a.dist < b.dist; }); + } + + // centroid of an atom array (mmdb_coormngr.h GetMassCenter) + inline void GetMassCenter(PPAtom A, int nA, realtype &xc, realtype &yc, realtype &zc) { + double sx = 0, sy = 0, sz = 0; + int n = 0; + for (int i = 0; i < nA; ++i) + if (A[i]) { + sx += A[i]->x(); + sy += A[i]->y(); + sz += A[i]->z(); + ++n; + } + if (n) { + xc = sx / n; + yc = sy / n; + zc = sz / n; + } else { + xc = yc = zc = 0; + } + } + +} // namespace mmdb // mmdb::mmcif::* (thin veneer over gemmi::cif) — re-opens mmdb{mmcif{...}}. // pstr/cpstr/realtype are already in scope from the headers above. diff --git a/mmdb-shim/src/contacts.cc b/mmdb-shim/src/contacts.cc index 4fa42b1417..a087d6f232 100644 --- a/mmdb-shim/src/contacts.cc +++ b/mmdb-shim/src/contacts.cc @@ -13,173 +13,199 @@ #include namespace mmdb { -namespace { + namespace { -bool seqNeglect(Atom *a, Atom *b, int seqDist); // defined below + bool seqNeglect(Atom *a, Atom *b, int seqDist); // defined below -// apply an MMDB 4x4 (rot+trans) to a position (symmetry transform of a contact set) -gemmi::Position xform(pmat44 T, const gemmi::Position &p) { - const mat44 &m = *T; - return gemmi::Position(m[0][0]*p.x + m[0][1]*p.y + m[0][2]*p.z + m[0][3], - m[1][0]*p.x + m[1][1]*p.y + m[1][2]*p.z + m[1][3], - m[2][0]*p.x + m[2][1]*p.y + m[2][2]*p.z + m[2][3]); -} + // apply an MMDB 4x4 (rot+trans) to a position (symmetry transform of a contact set) + gemmi::Position xform(pmat44 T, const gemmi::Position &p) { + const mat44 &m = *T; + return gemmi::Position(m[0][0] * p.x + m[0][1] * p.y + m[0][2] * p.z + m[0][3], + m[1][0] * p.x + m[1][1] * p.y + m[1][2] * p.z + m[1][3], + m[2][0] * p.x + m[2][1] * p.y + m[2][2] * p.z + m[2][3]); + } -// Contacts between A1 and a TMatrix-transformed second set (positions tp) via a -// uniform grid — used when SeekContacts is given a symmetry operator. selfSkip -// suppresses an atom pairing with its own untransformed self at ~zero distance. -void contacts_transformed(PPAtom A1, int n1, PPAtom A2, const std::vector &tp, - realtype d1, realtype d2, int seqDist, long group, - bool selfSkip, std::vector &found) { - double bin = d2 > 0 ? d2 : 1.0, d1s = d1 * d1, d2s = d2 * d2; - auto cellof = [&](const gemmi::Position &p) { - return std::make_tuple((int)std::floor(p.x / bin), (int)std::floor(p.y / bin), - (int)std::floor(p.z / bin)); - }; - std::map, std::vector> grid; - for (int j = 0; j < (int)tp.size(); ++j) grid[cellof(tp[j])].push_back(j); - for (int i = 0; i < n1; ++i) { - const gemmi::Position &pi = A1[i]->g().pos; - int cx, cy, cz; std::tie(cx, cy, cz) = cellof(pi); - for (int dx = -1; dx <= 1; ++dx) - for (int dy = -1; dy <= 1; ++dy) - for (int dz = -1; dz <= 1; ++dz) { - auto it = grid.find(std::make_tuple(cx + dx, cy + dy, cz + dz)); - if (it == grid.end()) continue; - for (int j : it->second) { - if (selfSkip && A1[i] == A2[j]) continue; - double ds = pi.dist_sq(tp[j]); - if (ds < d1s || ds > d2s) continue; - if (seqNeglect(A1[i], A2[j], seqDist)) continue; - found.push_back({i, j, group, std::sqrt(ds)}); - } - } - } -} + // Contacts between A1 and a TMatrix-transformed second set (positions tp) via a + // uniform grid — used when SeekContacts is given a symmetry operator. selfSkip + // suppresses an atom pairing with its own untransformed self at ~zero distance. + void contacts_transformed(PPAtom A1, int n1, PPAtom A2, const std::vector &tp, + realtype d1, realtype d2, int seqDist, long group, + bool selfSkip, std::vector &found) { + double bin = d2 > 0 ? d2 : 1.0, d1s = d1 * d1, d2s = d2 * d2; + auto cellof = [&](const gemmi::Position &p) { + return std::make_tuple((int)std::floor(p.x / bin), (int)std::floor(p.y / bin), + (int)std::floor(p.z / bin)); + }; + std::map, std::vector> grid; + for (int j = 0; j < (int)tp.size(); ++j) grid[cellof(tp[j])].push_back(j); + for (int i = 0; i < n1; ++i) { + const gemmi::Position &pi = A1[i]->g().pos; + int cx, cy, cz; + std::tie(cx, cy, cz) = cellof(pi); + for (int dx = -1; dx <= 1; ++dx) + for (int dy = -1; dy <= 1; ++dy) + for (int dz = -1; dz <= 1; ++dz) { + auto it = grid.find(std::make_tuple(cx + dx, cy + dy, cz + dz)); + if (it == grid.end()) continue; + for (int j : it->second) { + if (selfSkip && A1[i] == A2[j]) continue; + double ds = pi.dist_sq(tp[j]); + if (ds < d1s || ds > d2s) continue; + if (seqNeglect(A1[i], A2[j], seqDist)) continue; + found.push_back({i, j, group, std::sqrt(ds)}); + } + } + } + } -bool seqNeglect(Atom *a, Atom *b, int seqDist) { - if (seqDist <= 0) return false; - if (a->res->chain != b->res->chain) return false; - return std::abs(a->GetSeqNum() - b->GetSeqNum()) < seqDist; -} -void alloc_contacts(std::vector &v, PContact &out, int &n) { - n = (int)v.size(); - out = n ? new Contact[n] : nullptr; // caller delete[]s (MMDB semantics) - for (int i = 0; i < n; ++i) out[i] = v[i]; -} -// Map a NeighborSearch Mark back to the shim wrapper via the parallel tree. -inline Atom *mark_to_atom(Model *mw, const gemmi::NeighborSearch::Mark *m) { - return mw->chains[m->chain_idx]->residues[m->residue_idx]->atoms[m->atom_idx]; -} + bool seqNeglect(Atom *a, Atom *b, int seqDist) { + if (seqDist <= 0) return false; + if (a->res->chain != b->res->chain) return false; + return std::abs(a->GetSeqNum() - b->GetSeqNum()) < seqDist; + } + void alloc_contacts(std::vector &v, PContact &out, int &n) { + n = (int)v.size(); + out = n ? new Contact[n] : nullptr; // caller delete[]s (MMDB semantics) + for (int i = 0; i < n; ++i) out[i] = v[i]; + } + // Map a NeighborSearch Mark back to the shim wrapper via the parallel tree. + inline Atom *mark_to_atom(Model *mw, const gemmi::NeighborSearch::Mark *m) { + return mw->chains[m->chain_idx]->residues[m->residue_idx]->atoms[m->atom_idx]; + } -template -void skcombine(Vec &cur, Vec &m, SELECTION_KEY k) { - std::set cs(cur.begin(), cur.end()), ms(m.begin(), m.end()); - if (k == SKEY_NEW) cur = m; - else if (k == SKEY_OR) { for (auto *x : m) if (!cs.count(x)) cur.push_back(x); } - else if (k == SKEY_AND) { Vec o; for (auto *x : cur) if (ms.count(x)) o.push_back(x); cur = o; } - else if (k == SKEY_XOR) { Vec o; for (auto *x : cur) if (!ms.count(x)) o.push_back(x); - for (auto *x : m) if (!cs.count(x)) o.push_back(x); cur = o; } - else if (k == SKEY_CLR) { Vec o; for (auto *x : cur) if (!ms.count(x)) o.push_back(x); cur = o; } -} + template + void skcombine(Vec &cur, Vec &m, SELECTION_KEY k) { + std::set cs(cur.begin(), cur.end()), ms(m.begin(), m.end()); + if (k == SKEY_NEW) + cur = m; + else if (k == SKEY_OR) { + for (auto *x : m) + if (!cs.count(x)) cur.push_back(x); + } else if (k == SKEY_AND) { + Vec o; + for (auto *x : cur) + if (ms.count(x)) o.push_back(x); + cur = o; + } else if (k == SKEY_XOR) { + Vec o; + for (auto *x : cur) + if (!ms.count(x)) o.push_back(x); + for (auto *x : m) + if (!cs.count(x)) o.push_back(x); + cur = o; + } else if (k == SKEY_CLR) { + Vec o; + for (auto *x : cur) + if (!ms.count(x)) o.push_back(x); + cur = o; + } + } -} // namespace + } // namespace -// atoms within [d1,d2] of any atom in the given set. -void Manager::SelectNeighbours(int selHnd, SELECTION_TYPE sType, PPAtom atoms, - int nAtoms, realtype d1, realtype d2, SELECTION_KEY sKey) { - std::vector mAtoms; std::vector mResidues; - if (nAtoms > 0) { - Model *mw = atoms[0]->res->chain->model; - gemmi::NeighborSearch ns(mw->g(), st.cell, d2); - ns.populate(true); - std::set seenA; std::set seenR; - for (int i = 0; i < nAtoms; ++i) - for (auto *m : ns.find_atoms(atoms[i]->g().pos, '\0', d1, d2)) { - if (m->image_idx != 0) continue; - Atom *b = mark_to_atom(mw, m); - if (sType == STYPE_ATOM) { if (seenA.insert(b).second) mAtoms.push_back(b); } - else if (sType == STYPE_RESIDUE) { if (seenR.insert(b->res).second) mResidues.push_back(b->res); } + // atoms within [d1,d2] of any atom in the given set. + void Manager::SelectNeighbours(int selHnd, SELECTION_TYPE sType, PPAtom atoms, + int nAtoms, realtype d1, realtype d2, SELECTION_KEY sKey) { + std::vector mAtoms; + std::vector mResidues; + if (nAtoms > 0) { + Model *mw = atoms[0]->res->chain->model; + gemmi::NeighborSearch ns(mw->g(), st.cell, d2); + ns.populate(true); + std::set seenA; + std::set seenR; + for (int i = 0; i < nAtoms; ++i) + for (auto *m : ns.find_atoms(atoms[i]->g().pos, '\0', d1, d2)) { + if (m->image_idx != 0) continue; + Atom *b = mark_to_atom(mw, m); + if (sType == STYPE_ATOM) { + if (seenA.insert(b).second) mAtoms.push_back(b); + } else if (sType == STYPE_RESIDUE) { + if (seenR.insert(b->res).second) mResidues.push_back(b->res); + } + } } - } - Selection &sel = selections[selHnd - 1]; - if (sel.type == STYPE_UNDEFINED) sel.type = sType; - std::vector oldA = sel.atoms; std::vector oldR = sel.residues; - if (sType == STYPE_ATOM) skcombine(sel.atoms, mAtoms, sKey); - else if (sType == STYPE_RESIDUE) skcombine(sel.residues, mResidues, sKey); - for (Atom *a : oldA) a->_setInSel(selHnd, false); - for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); - for (Residue *r : oldR) r->_setInSel(selHnd, false); - for (Residue *r : sel.residues) r->_setInSel(selHnd, true); -} + Selection &sel = selections[selHnd - 1]; + if (sel.type == STYPE_UNDEFINED) sel.type = sType; + std::vector oldA = sel.atoms; + std::vector oldR = sel.residues; + if (sType == STYPE_ATOM) + skcombine(sel.atoms, mAtoms, sKey); + else if (sType == STYPE_RESIDUE) + skcombine(sel.residues, mResidues, sKey); + for (Atom *a : oldA) a->_setInSel(selHnd, false); + for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); + for (Residue *r : oldR) r->_setInSel(selHnd, false); + for (Residue *r : sel.residues) r->_setInSel(selHnd, true); + } -void Manager::SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, - realtype d2, int seqDist, PContact &contact, int &ncontacts, int /*maxlen*/, - pmat44 TMatrix, long group) { - std::vector found; - if (TMatrix && n1 > 0 && n2 > 0) { // contacts against a symmetry-transformed A2 - std::vector tp(n2); - for (int j = 0; j < n2; ++j) tp[j] = xform(TMatrix, A2[j]->g().pos); - contacts_transformed(A1, n1, A2, tp, d1, d2, seqDist, group, /*selfSkip=*/false, found); - alloc_contacts(found, contact, ncontacts); - return; - } - if (n1 > 0 && n2 > 0) { - Model *mw = A1[0]->res->chain->model; // NeighborSearch is per-model - gemmi::NeighborSearch ns(mw->g(), st.cell, d2); - ns.populate(true); - std::unordered_map a2idx; - a2idx.reserve(n2 * 2); - for (int j = 0; j < n2; ++j) a2idx.emplace(A2[j], j); + void Manager::SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, + realtype d2, int seqDist, PContact &contact, int &ncontacts, int /*maxlen*/, + pmat44 TMatrix, long group) { + std::vector found; + if (TMatrix && n1 > 0 && n2 > 0) { // contacts against a symmetry-transformed A2 + std::vector tp(n2); + for (int j = 0; j < n2; ++j) tp[j] = xform(TMatrix, A2[j]->g().pos); + contacts_transformed(A1, n1, A2, tp, d1, d2, seqDist, group, /*selfSkip=*/false, found); + alloc_contacts(found, contact, ncontacts); + return; + } + if (n1 > 0 && n2 > 0) { + Model *mw = A1[0]->res->chain->model; // NeighborSearch is per-model + gemmi::NeighborSearch ns(mw->g(), st.cell, d2); + ns.populate(true); + std::unordered_map a2idx; + a2idx.reserve(n2 * 2); + for (int j = 0; j < n2; ++j) a2idx.emplace(A2[j], j); - for (int i = 0; i < n1; ++i) { - if (A1[i]->res->chain->model != mw) continue; // single-model contact search - for (auto *m : ns.find_atoms(A1[i]->g().pos, '\0', d1, d2)) { - if (m->image_idx != 0) continue; // exclude symmetry mates - Atom *b = mark_to_atom(mw, m); - if (A1[i] == b) continue; - auto it = a2idx.find(b); - if (it == a2idx.end()) continue; - if (seqNeglect(A1[i], b, seqDist)) continue; - found.push_back({i, it->second, group, A1[i]->g().pos.dist(b->g().pos)}); + for (int i = 0; i < n1; ++i) { + if (A1[i]->res->chain->model != mw) continue; // single-model contact search + for (auto *m : ns.find_atoms(A1[i]->g().pos, '\0', d1, d2)) { + if (m->image_idx != 0) continue; // exclude symmetry mates + Atom *b = mark_to_atom(mw, m); + if (A1[i] == b) continue; + auto it = a2idx.find(b); + if (it == a2idx.end()) continue; + if (seqNeglect(A1[i], b, seqDist)) continue; + found.push_back({i, it->second, group, A1[i]->g().pos.dist(b->g().pos)}); + } + } } - } - } - alloc_contacts(found, contact, ncontacts); -} + alloc_contacts(found, contact, ncontacts); + } -void Manager::SeekContacts(PPAtom A, int n, realtype d1, realtype d2, - int seqDist, PContact &contact, int &ncontacts, int /*maxlen*/, - pmat44 TMatrix, long group) { - std::vector found; - if (TMatrix && n > 0) { // self-contacts against the symmetry-transformed set - std::vector tp(n); - for (int i = 0; i < n; ++i) tp[i] = xform(TMatrix, A[i]->g().pos); - contacts_transformed(A, n, A, tp, d1, d2, seqDist, group, /*selfSkip=*/true, found); - alloc_contacts(found, contact, ncontacts); - return; - } - if (n > 0) { - Model *mw = A[0]->res->chain->model; - gemmi::NeighborSearch ns(mw->g(), st.cell, d2); - ns.populate(true); - std::unordered_map idx; - idx.reserve(n * 2); - for (int i = 0; i < n; ++i) idx.emplace(A[i], i); + void Manager::SeekContacts(PPAtom A, int n, realtype d1, realtype d2, + int seqDist, PContact &contact, int &ncontacts, int /*maxlen*/, + pmat44 TMatrix, long group) { + std::vector found; + if (TMatrix && n > 0) { // self-contacts against the symmetry-transformed set + std::vector tp(n); + for (int i = 0; i < n; ++i) tp[i] = xform(TMatrix, A[i]->g().pos); + contacts_transformed(A, n, A, tp, d1, d2, seqDist, group, /*selfSkip=*/true, found); + alloc_contacts(found, contact, ncontacts); + return; + } + if (n > 0) { + Model *mw = A[0]->res->chain->model; + gemmi::NeighborSearch ns(mw->g(), st.cell, d2); + ns.populate(true); + std::unordered_map idx; + idx.reserve(n * 2); + for (int i = 0; i < n; ++i) idx.emplace(A[i], i); - for (int i = 0; i < n; ++i) { - if (A[i]->res->chain->model != mw) continue; - for (auto *m : ns.find_atoms(A[i]->g().pos, '\0', d1, d2)) { - if (m->image_idx != 0) continue; - Atom *b = mark_to_atom(mw, m); - auto it = idx.find(b); - if (it == idx.end() || it->second <= i) continue; // unordered pairs, once - if (seqNeglect(A[i], b, seqDist)) continue; - found.push_back({i, it->second, group, A[i]->g().pos.dist(b->g().pos)}); + for (int i = 0; i < n; ++i) { + if (A[i]->res->chain->model != mw) continue; + for (auto *m : ns.find_atoms(A[i]->g().pos, '\0', d1, d2)) { + if (m->image_idx != 0) continue; + Atom *b = mark_to_atom(mw, m); + auto it = idx.find(b); + if (it == idx.end() || it->second <= i) continue; // unordered pairs, once + if (seqNeglect(A[i], b, seqDist)) continue; + found.push_back({i, it->second, group, A[i]->g().pos.dist(b->g().pos)}); + } + } } - } - } - alloc_contacts(found, contact, ncontacts); -} + alloc_contacts(found, contact, ncontacts); + } -} // namespace mmdb +} // namespace mmdb diff --git a/mmdb-shim/src/io.cc b/mmdb-shim/src/io.cc index 0873ef7376..a8b6545b1f 100644 --- a/mmdb-shim/src/io.cc +++ b/mmdb-shim/src/io.cc @@ -5,56 +5,56 @@ #define COOT_USE_MMDB_SHIM 1 #include -#include // read_structure_file (auto-detect) -#include // read_pdb_file -#include // write_pdb -#include // make_mmcif_document -#include // write_cif_to_stream +#include // read_structure_file (auto-detect) +#include // read_pdb_file +#include // write_pdb +#include // make_mmcif_document +#include // write_cif_to_stream #include namespace mmdb { -// Rebuild the wrapper tree from a freshly loaded gemmi::Structure. gemmi's PDB/ -// mmCIF readers split a single author chain into polymer/ligand/water parts that -// share the chain name; MMDB keeps one chain per chain ID. For MMDB chain-count -// parity we merge those parts back (Structure::merge_chain_parts), so Coot sees -// one mmdb::Chain per chain ID, as it does with real MMDB. -ERROR_CODE Manager::ReadPDBASCII(cpstr fname) { - try { - st = gemmi::read_pdb_file(fname); - } catch (const std::exception &) { - return Error_CantOpenFile; - } - st.merge_chain_parts(); - build_from_gemmi(); - return Error_NoError; -} - -ERROR_CODE Manager::ReadCoorFile(cpstr fname) { - try { - st = gemmi::read_structure_file(fname); - } catch (const std::exception &) { - return Error_CantOpenFile; - } - st.merge_chain_parts(); - build_from_gemmi(); - return Error_NoError; -} - -ERROR_CODE Manager::WritePDBASCII(cpstr fname) { - std::ofstream os(fname); - if (!os) return Error_CantOpenFile; - gemmi::write_pdb(st, os); - return Error_NoError; -} - -ERROR_CODE Manager::WriteCIFASCII(cpstr fname) { - std::ofstream os(fname); - if (!os) return Error_CantOpenFile; - gemmi::cif::Document doc = gemmi::make_mmcif_document(st); - gemmi::cif::write_cif_to_stream(os, doc); - return Error_NoError; -} - -} // namespace mmdb + // Rebuild the wrapper tree from a freshly loaded gemmi::Structure. gemmi's PDB/ + // mmCIF readers split a single author chain into polymer/ligand/water parts that + // share the chain name; MMDB keeps one chain per chain ID. For MMDB chain-count + // parity we merge those parts back (Structure::merge_chain_parts), so Coot sees + // one mmdb::Chain per chain ID, as it does with real MMDB. + ERROR_CODE Manager::ReadPDBASCII(cpstr fname) { + try { + st = gemmi::read_pdb_file(fname); + } catch (const std::exception &) { + return Error_CantOpenFile; + } + st.merge_chain_parts(); + build_from_gemmi(); + return Error_NoError; + } + + ERROR_CODE Manager::ReadCoorFile(cpstr fname) { + try { + st = gemmi::read_structure_file(fname); + } catch (const std::exception &) { + return Error_CantOpenFile; + } + st.merge_chain_parts(); + build_from_gemmi(); + return Error_NoError; + } + + ERROR_CODE Manager::WritePDBASCII(cpstr fname) { + std::ofstream os(fname); + if (!os) return Error_CantOpenFile; + gemmi::write_pdb(st, os); + return Error_NoError; + } + + ERROR_CODE Manager::WriteCIFASCII(cpstr fname) { + std::ofstream os(fname); + if (!os) return Error_CantOpenFile; + gemmi::cif::Document doc = gemmi::make_mmcif_document(st); + gemmi::cif::write_cif_to_stream(os, doc); + return Error_NoError; + } + +} // namespace mmdb From 4bc24bb162a9f53da44d759e66c8b424546c869e Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Wed, 22 Jul 2026 12:07:31 +0100 Subject: [PATCH 09/23] Fixed bug with null chains --- mmdb-shim/include/mmdb2/_shim_impl.hh | 49 ++++++++++++++++++--------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh index 5bb82f2ab0..de1d7540da 100644 --- a/mmdb-shim/include/mmdb2/_shim_impl.hh +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -497,6 +497,13 @@ namespace mmdb { return gemmi::Element(element ? element : "X").vdw_r(); } + // Borrowed empty C-string, returned by the delegating accessors when an object + // is detached (no parent) — real MMDB yields safe defaults, not a crash. + inline pstr mmdb_empty_pstr() { + static char e[1] = {0}; + return e; + } + // UDData helpers (defined after Manager); each class forwards with its UDR type. int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int v); int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype v); @@ -1325,14 +1332,17 @@ namespace mmdb { Selection &s = selections[selHnd - 1]; // self-contained comma-list matcher ("*"=any, "!X"=exclude); `detail::` is // declared after Manager, so don't depend on it in this inline body. - auto inlist = [](cpstr list, const std::string &v) -> bool { + auto trimws = [](const std::string &s) -> std::string { + size_t a = s.find_first_not_of(' '), b = s.find_last_not_of(' '); + return a == std::string::npos ? std::string() : s.substr(a, b - a + 1); + }; + auto inlist = [&trimws](cpstr list, const std::string &v) -> bool { if (!list || !*list || std::strcmp(list, "*") == 0) return true; + std::string vt = trimws(v); for (const char *p = list; *p;) { const char *c = std::strchr(p, ','); std::string tok(p, c ? (size_t)(c - p) : std::strlen(p)); - size_t a = tok.find_first_not_of(' '), b = tok.find_last_not_of(' '); - tok = (a == std::string::npos) ? std::string() : tok.substr(a, b - a + 1); - if (tok == v) return true; + if (trimws(tok) == vt) return true; if (!c) break; p = c + 1; } @@ -1406,7 +1416,7 @@ namespace mmdb { void DeleteAllModels() { st.models.clear(); build_from_gemmi(); - } // clears the hierarchy + } // clears the hierarchy void DeleteModel(int modelNo) { // 1-based; erase model + rebuild wrappers int i = modelNo - 1; if (i >= 0 && i < (int)st.models.size()) { @@ -1625,10 +1635,10 @@ namespace mmdb { return _elem_buf; } inline void Atom::SetElementName(const Element elName) { g().element = gemmi::Element(elName); } - inline pstr Atom::GetChainID() { return res->GetChainID(); } - inline int Atom::GetSeqNum() { return res->GetSeqNum(); } + inline pstr Atom::GetChainID() { return res ? res->GetChainID() : mmdb_empty_pstr(); } + inline int Atom::GetSeqNum() { return res ? res->GetSeqNum() : 0; } inline Chain *Atom::GetChain() { return res ? res->GetChain() : nullptr; } - inline Model *Atom::GetModel() { return res ? res->chain->model : nullptr; } + inline Model *Atom::GetModel() { return (res && res->chain) ? res->chain->model : nullptr; } inline pstr Atom::GetLabelCompID() { return res ? res->GetLabelCompID() : nullptr; } inline pstr Atom::GetLabelAsymID() { return res ? res->GetLabelAsymID() : nullptr; } inline int Atom::GetLabelSeqID() { return res ? res->GetLabelSeqID() : 0; } @@ -1638,9 +1648,9 @@ namespace mmdb { inline bool Atom::isSolvent() { return res ? res->isSolvent() : false; } inline bool Atom::isNTerminus() { return res ? res->isNTerminus() : false; } inline bool Atom::isCTerminus() { return res ? res->isCTerminus() : false; } - inline pstr Atom::GetInsCode() { return res->GetInsCode(); } - inline pstr Atom::GetResName() { return res->GetResName(); } - inline int Atom::GetModelNum() { return res->GetModelNum(); } + inline pstr Atom::GetInsCode() { return res ? res->GetInsCode() : mmdb_empty_pstr(); } + inline pstr Atom::GetResName() { return res ? res->GetResName() : mmdb_empty_pstr(); } + inline int Atom::GetModelNum() { return res ? res->GetModelNum() : 0; } inline int Atom::GetIndex() { return ai; } inline void Atom::SetCoordinates(realtype xx, realtype yy, realtype zz, realtype occ, realtype tF) { @@ -1661,8 +1671,8 @@ namespace mmdb { _inscode_buf[1] = '\0'; return _inscode_buf; } - inline pstr Residue::GetChainID() { return chain->GetChainID(); } - inline int Residue::GetModelNum() { return chain->model->GetSerNum(); } + inline pstr Residue::GetChainID() { return chain ? chain->GetChainID() : mmdb_empty_pstr(); } + inline int Residue::GetModelNum() { return (chain && chain->model) ? chain->model->GetSerNum() : 0; } inline PAtom Residue::GetAtom(const AtomName aname, const Element elname, const AltLoc aloc) { for (Atom *a : atoms) { if (a->g().name != aname) continue; @@ -1977,15 +1987,22 @@ namespace mmdb { // ---- selection matching ---- namespace detail { + inline std::string trimws(const std::string &s) { + size_t a = s.find_first_not_of(' '), b = s.find_last_not_of(' '); + return a == std::string::npos ? std::string() : s.substr(a, b - a + 1); + } + // Whitespace-insensitive membership test. MMDB atom names are stored space- + // padded ("_CA_", "_O__"), while CID/selection queries are unpadded ("CA", + // "O"); real MMDB matches them regardless of padding, so trim both sides. + // Harmless for chain IDs / residue / element names (already unpadded). inline bool inList(cpstr list, const std::string &v) { if (!list || !*list || std::strcmp(list, "*") == 0) return true; + std::string vt = trimws(v); const char *p = list; while (*p) { const char *c = std::strchr(p, ','); std::string tok(p, c ? (size_t)(c - p) : std::strlen(p)); - size_t a = tok.find_first_not_of(' '), b = tok.find_last_not_of(' '); - tok = (a == std::string::npos) ? std::string() : tok.substr(a, b - a + 1); - if (tok == v) return true; + if (trimws(tok) == vt) return true; if (!c) break; p = c + 1; } From de11b7f1c4bb7c662ecdd8f83ffed754a4801344 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Wed, 22 Jul 2026 13:36:59 +0100 Subject: [PATCH 10/23] Updated implementation --- mmdb-shim/include/mmdb2/_mmcif_impl.hh | 11 ++- mmdb-shim/include/mmdb2/_shim_impl.hh | 118 +++++++++++++++++++++---- 2 files changed, 111 insertions(+), 18 deletions(-) diff --git a/mmdb-shim/include/mmdb2/_mmcif_impl.hh b/mmdb-shim/include/mmdb2/_mmcif_impl.hh index 35b7933b5e..8da7f7514c 100644 --- a/mmdb-shim/include/mmdb2/_mmcif_impl.hh +++ b/mmdb-shim/include/mmdb2/_mmcif_impl.hh @@ -545,7 +545,16 @@ namespace mmdb { std::vector t = collect_tags(); if (tagNo < 0 || (size_t)tagNo >= t.size()) return nullptr; int rc = 0; - return GetString(t[tagNo].c_str(), rc); + pstr s = GetString(t[tagNo].c_str(), rc); + // The tag is enumerated (exists), but its value may be a CIF null (`?`/`.`), + // for which GetString returns null. MMDB's GetField never returns null for an + // in-range tag, and callers (e.g. gphl_chem_comp_info) wrap it straight into + // std::string — so hand back an empty (non-null) field instead of crashing. + if (!s) { + sret.emplace_back(); + s = (pstr)sret.back().c_str(); + } + return s; } inline pstr Struct::GetString(cpstr TName, int &RC) { if (!owner) { diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh index de1d7540da..8d890798b1 100644 --- a/mmdb-shim/include/mmdb2/_shim_impl.hh +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -11,6 +11,7 @@ #pragma once #include +#include // trim_str — normalise MMDB-padded names to gemmi's trimmed form #include #include // space-group / symmetry operators @@ -527,6 +528,12 @@ namespace mmdb { Atom() = default; explicit Atom(Residue *r); // construct + add to residue (out-of-line) + // MMDB owns atoms via `new`/`delete`: Coot writes `delete atom;` to remove an + // atom from the hierarchy (coot-molecule.cc et al.). So atoms are individually + // heap-allocated (Manager::newAtom) and tracked in Manager::_atom_allocs; this + // destructor detaches from the parent residue + flat lists + selections when a + // live atom is deleted, and is a no-op during Manager teardown (_bulk_free). + ~Atom(); // out-of-line (needs complete Manager/Residue) gemmi::Atom &g() const; // resolve to live gemmi (defined after Manager) @@ -773,17 +780,9 @@ namespace mmdb { // Adopt a detached atom (Coot's `new mmdb::Atom` idiom). Copies the atom's // local gemmi into this residue's gemmi (detached or bound, via g()) and // rebinds the wrapper. Pushes the strncpy'd altLoc buffer back into gemmi. - int AddAtom(PAtom atm) { - g().atoms.push_back(atm->_local); - atm->res = this; - atm->mgr = mgr; - atm->ai = (int)atoms.size(); - if (atm->_altloc_buf[0]) g().atoms[atm->ai].altloc = atm->_altloc_buf[0]; - atoms.push_back(atm); - _sync_atom(); - return 0; - } + int AddAtom(PAtom atm); // out-of-line: needs complete Manager (_atom_allocs) void DeleteAtom(int pos); + void _detach_atom(Atom *a); // unlink (no free); used by ~Atom on Coot `delete atom` void TrimAtomTable() {} // compact after deletions — shim keeps them in sync pstr GetResName(); @@ -1097,8 +1096,19 @@ namespace mmdb { class Manager { public: gemmi::Structure st; - // stable-address pools - std::deque atom_pool; + // Atoms are heap-allocated individually (not pooled) so Coot's MMDB idiom + // `delete atom;` frees exactly one node. The manager owns every atom it hands + // out and frees the survivors at teardown; `~Atom` removes itself from this set + // when Coot deletes it early. `_bulk_free` tells `~Atom` to skip detach work + // while the manager is tearing everything down. + std::set _atom_allocs; + bool _bulk_free = false; + ~Manager() { + _bulk_free = true; + for (Atom *a : _atom_allocs) delete a; + _atom_allocs.clear(); + } + // stable-address pools (Residue/Chain/Model still pooled — see _atom_allocs note) std::deque res_pool; std::deque chain_pool; std::deque model_pool; @@ -1117,8 +1127,10 @@ namespace mmdb { void _load_metadata(); // out-of-line: needs complete gemmi metadata types Atom *newAtom() { - atom_pool.emplace_back(); - return &atom_pool.back(); + Atom *a = new Atom(); + a->mgr = this; + _atom_allocs.insert(a); + return a; } Residue *newRes() { res_pool.emplace_back(); @@ -1558,7 +1570,16 @@ namespace mmdb { inline gemmi::Model &Model::g() const { return mgr ? mgr->st.models[mi] : const_cast(this)->_local; } inline gemmi::Chain &Chain::g() const { return model ? model->g().chains[ci] : const_cast(this)->_local; } inline gemmi::Residue &Residue::g() const { return chain ? chain->g().residues[ri] : const_cast(this)->_local; } - inline gemmi::Atom &Atom::g() const { return res ? res->g().atoms[ai] : const_cast(this)->_local; } + inline gemmi::Atom &Atom::g() const { + if (res && res->chain && res->chain->model && res->chain->model->mgr) { + auto &mgr = *res->chain->model->mgr; + int mi = res->chain->model->mi; + if (mi >= 0 && mi < (int)mgr.st.models.size()) { + return res->g().atoms[ai]; + } + } + return const_cast(this)->_local; + } // ---- UDData helpers ---- inline Manager::UDReg *_ud_desc(Manager *mgr, UDR_TYPE myType, int handle, int kind, @@ -1626,10 +1647,20 @@ namespace mmdb { // ---- Atom out-of-line ---- inline pstr Atom::GetAtomName() const { - std::snprintf(_name_buf, sizeof(_name_buf), "%s", g().name.c_str()); + // MMDB returns the PDB-column-aligned 4-char atom name (e.g. " N ", " CA ", + // " CG2"); gemmi stores the trimmed name ("N"/"CA"/"CG2"). Reproduce MMDB + // alignment via gemmi's padded_name() (left-pad by element) + right-pad to 4 + // — the exact rule gemmi's own mmdb.hpp bridge uses. Coot's atom_spec_t names + // are these 4-char strings, so returning the trimmed name breaks every lookup. + std::string padded = g().padded_name(); + if (padded.size() < 4) padded.resize(4, ' '); + std::snprintf(_name_buf, sizeof(_name_buf), "%s", padded.c_str()); return _name_buf; } - inline void Atom::SetAtomName(const AtomName aName) { g().name = aName; } + // Coot passes MMDB-aligned 4-char names (" CA "); gemmi stores trimmed names + // ("CA") and re-pads on output (GetAtomName / PDB write) — store trimmed so + // gemmi's own formatting stays correct. + inline void Atom::SetAtomName(const AtomName aName) { g().name = aName ? gemmi::trim_str(aName) : ""; } inline pstr Atom::GetElementName() { std::snprintf(_elem_buf, sizeof(_elem_buf), "%s", g().element.name()); return _elem_buf; @@ -1691,6 +1722,21 @@ namespace mmdb { atoms.push_back(aw); return aw; } + // Adopt a Coot-`new`d detached atom (the `new mmdb::Atom; …; res->AddAtom(at)` + // idiom). Copy its local gemmi into this residue, rebind the wrapper, and — when + // this residue is manager-bound — transfer ownership to the manager so `~Manager` + // frees it (MMDB semantics); `~Atom` drops it back out on an early Coot `delete`. + inline int Residue::AddAtom(PAtom atm) { + g().atoms.push_back(atm->_local); + atm->res = this; + atm->mgr = mgr; + atm->ai = (int)atoms.size(); + if (atm->_altloc_buf[0]) g().atoms[atm->ai].altloc = atm->_altloc_buf[0]; + atoms.push_back(atm); + if (mgr) mgr->_atom_allocs.insert(atm); + _sync_atom(); + return 0; + } inline void Residue::DeleteAtom(int pos) { if (pos < 0 || pos >= (int)atoms.size()) return; g().atoms.erase(g().atoms.begin() + pos); @@ -1700,6 +1746,44 @@ namespace mmdb { for (int k = pos; k < (int)atoms.size(); ++k) atoms[k]->ai = k; } + // Unlink one atom wrapper from this residue without freeing it: erase from the + // wrapper table AND the parallel gemmi atom vector (kept in lockstep), then + // reindex trailing atoms. Used by ~Atom when Coot `delete`s a live atom. + inline void Residue::_detach_atom(Atom *a) { + auto it = std::find(atoms.begin(), atoms.end(), a); + if (it == atoms.end()) return; + int pos = (int)(it - atoms.begin()); + if (pos < (int)g().atoms.size()) g().atoms.erase(g().atoms.begin() + pos); + atoms.erase(atoms.begin() + pos); + for (int k = pos; k < (int)atoms.size(); ++k) atoms[k]->ai = k; + } + + // Coot's `delete atom;` removes an atom from the hierarchy. Detach it from the + // parent residue, the manager/model flat lists, and any selections so no stale + // pointer survives; then drop it from the ownership set. A no-op during teardown + // (memory is freed wholesale by ~Manager) and for never-adopted detached atoms. + inline Atom::~Atom() { + if (!mgr || mgr->_bulk_free) return; + Manager *m = mgr; + if (res) { + Model *mod = (res->chain ? res->chain->model : nullptr); + res->_detach_atom(this); + if (mod) { + auto &ma = mod->all_atoms; + ma.erase(std::remove(ma.begin(), ma.end(), this), ma.end()); + } + } + auto &aa = m->all_atoms; + aa.erase(std::remove(aa.begin(), aa.end(), this), aa.end()); + for (int h = 1; h <= (int)m->selections.size(); ++h) { + if (isInSelection(h)) { + auto &sa = m->selections[h - 1].atoms; + sa.erase(std::remove(sa.begin(), sa.end(), this), sa.end()); + } + } + m->_atom_allocs.erase(this); + } + // ---- Chain out-of-line ---- inline bool Chain::isAminoacidChain() { for (Residue *r : residues) From 67e3c20fa79ddc49e69035f7fdda93b2ce518e47 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Wed, 22 Jul 2026 14:39:20 +0100 Subject: [PATCH 11/23] Added infrastructure for safer deletion --- mmdb-shim/include/mmdb2/_shim_impl.hh | 141 ++++++++++++++++++++++---- 1 file changed, 124 insertions(+), 17 deletions(-) diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh index 8d890798b1..6d46ba0037 100644 --- a/mmdb-shim/include/mmdb2/_shim_impl.hh +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -746,6 +746,12 @@ namespace mmdb { Residue() = default; explicit Residue(Chain *c); // construct + add to chain (out-of-line) + // MMDB owns residues via `new`/`delete` (Coot writes `delete residue_p;`). Like + // ~Atom, this frees the residue's atoms, then DEFERS structural removal: it nulls + // this residue's slot in the parent chain (a tombstone) but leaves the gemmi + // placeholder residue in place so siblings' `ri` stays valid — _compact_residues + // drops both later. No-op during Manager teardown (_bulk_free). + ~Residue(); // out-of-line (needs complete Manager/Chain) // MMDB public char-array fields. Coot reads `residue->name` and writes // `strncpy(residue->insCode,..)`. Kept as the interface: synced gemmi->buffer on @@ -848,10 +854,12 @@ namespace mmdb { PResidue GetResidue(int resNo) { return (resNo >= 0 && resNo < (int)residues.size()) ? residues[resNo] : nullptr; } - // find by (seqNum, insCode) — MMDB's 2-arg overload + // find by (seqNum, insCode) — MMDB's 2-arg overload. Skips deferred-delete + // tombstone (null) slots. PResidue GetResidue(int seqNum, const InsCode insCode) { char ic = (insCode && insCode[0]) ? insCode[0] : ' '; for (Residue *r : residues) { + if (!r) continue; // tombstone gemmi::Residue &gr = r->g(); char ric = gr.seqid.icode ? gr.seqid.icode : ' '; if (gr.seqid.num.value == seqNum && ric == ic) return r; @@ -862,18 +870,23 @@ namespace mmdb { t = residues.data(); n = (int)residues.size(); } - // delete residue at index: erase gemmi + wrapper, reindex the tail + // MMDB DeleteResidue is DEFERRED: it frees the residue and leaves a NULL slot + // (nResidues unchanged) until TrimResidueTable/FinishStructEdit. `delete residue` + // (via ~Residue) does the same. Coot relies on this (e.g. change_chain_id iterates + // to the original count while deleting). We keep the gemmi placeholder residue too + // so surviving residues' `ri` stays aligned; _compact_residues() drops both later. void DeleteResidue(int resNo) { if (resNo < 0 || resNo >= (int)residues.size()) return; - g().residues.erase(g().residues.begin() + resNo); - residues.erase(residues.begin() + resNo); - for (int k = resNo; k < (int)residues.size(); ++k) residues[k]->ri = k; + if (residues[resNo]) delete residues[resNo]; // ~Residue nulls the slot } - void TrimResidueTable() {} // compact after deletions — shim stays in sync void DeleteResidue(int seqNum, const InsCode ic) { // by (seqNum, insCode) PResidue r = GetResidue(seqNum, ic); - if (r) DeleteResidue(r->ri); + if (r) delete r; // ~Residue nulls its slot; keeps the gemmi placeholder } + void TrimResidueTable() { _compact_residues(); } + // Drop tombstoned (null) residue slots and their gemmi placeholder residues in + // lock-step, then reindex ri. Out-of-line: needs a complete Residue. + void _compact_residues(); pstr GetChainID(); pstr GetChainID(pstr buf) { if (buf) std::snprintf(buf, sizeof(ChainID), "%s", g().name.c_str()); @@ -889,6 +902,7 @@ namespace mmdb { // re-indexes ri. sortKey variants beyond ascending-by-number are uncommon in // Coot and treated as the default. void SortResidues(int /*sortKey*/ = 0) { + _compact_residues(); // never sort across deferred-delete tombstones int n = (int)residues.size(); if (n < 2) return; std::vector ord(n); @@ -929,6 +943,7 @@ namespace mmdb { return 0; } int InsResidue(PResidue res, int pos) { + _compact_residues(); // don't insert/reindex across tombstones if (pos < 0) pos = 0; if (pos > (int)residues.size()) pos = (int)residues.size(); res->_store_id(); @@ -1102,14 +1117,16 @@ namespace mmdb { // when Coot deletes it early. `_bulk_free` tells `~Atom` to skip detach work // while the manager is tearing everything down. std::set _atom_allocs; + std::set _res_allocs; // residues heap-allocated too (Coot `delete residue_p`) bool _bulk_free = false; ~Manager() { _bulk_free = true; for (Atom *a : _atom_allocs) delete a; _atom_allocs.clear(); + for (Residue *r : _res_allocs) delete r; + _res_allocs.clear(); } - // stable-address pools (Residue/Chain/Model still pooled — see _atom_allocs note) - std::deque res_pool; + // stable-address pools (Chain/Model still pooled — see _atom_allocs / _res_allocs note) std::deque chain_pool; std::deque model_pool; std::vector models; @@ -1133,8 +1150,10 @@ namespace mmdb { return a; } Residue *newRes() { - res_pool.emplace_back(); - return &res_pool.back(); + Residue *r = new Residue(); + r->mgr = this; + _res_allocs.insert(r); + return r; } Chain *newChain() { chain_pool.emplace_back(); @@ -1163,6 +1182,13 @@ namespace mmdb { // mutates (so PDBCLEAN_INDEX is implicit); PDBCLEAN_SERIAL renumbers atom serials // 1..N in hierarchy order. Other clean flags are not needed by the shim. word PDBCleanup(word CleanKey) { + // INDEX cleanup compacts deferred residue deletions (drops tombstones) — do it + // before renumbering so serials/indices count only surviving atoms. + if (CleanKey & PDBCLEAN_INDEX) { + for (Model *mw : models) + for (Chain *cw : mw->chains) cw->_compact_residues(); + _rebuild_all_atoms(); + } if (CleanKey & (PDBCLEAN_SERIAL | PDBCLEAN_INDEX)) { int s = 1; for (Atom *a : all_atoms) a->g().serial = s++; @@ -1525,7 +1551,29 @@ namespace mmdb { SeekContacts(a1, 1, A2, n2, d1, d2, seqDist, contact, ncontacts, maxlen, TMatrix, group); } - int FinishStructEdit() { return 0; } // no-op: wrappers stay in sync eagerly + // Compact deferred residue deletions across the whole hierarchy: MMDB defers + // DeleteResidue (tombstone the slot, keep the count) until FinishStructEdit, so + // here we drop the null tombstone slots + their gemmi placeholder residues and + // rebuild the flat atom lists. (Atoms already stay in sync eagerly.) + void _rebuild_all_atoms() { + all_atoms.clear(); + for (Model *mw : models) { + mw->all_atoms.clear(); + for (Chain *cw : mw->chains) + for (Residue *rw : cw->residues) + if (rw) + for (Atom *aw : rw->atoms) { + all_atoms.push_back(aw); + mw->all_atoms.push_back(aw); + } + } + } + int FinishStructEdit() { + for (Model *mw : models) + for (Chain *cw : mw->chains) cw->_compact_residues(); + _rebuild_all_atoms(); + return 0; + } // ---- UDData registry ---- struct UDReg { @@ -1784,21 +1832,75 @@ namespace mmdb { m->_atom_allocs.erase(this); } + // Coot's `delete residue_p;` (and Chain::DeleteResidue) removes a residue. Free its + // atoms (MMDB: deleting a residue deletes its atoms), then DEFER the structural + // removal: null this residue's slot in the parent chain but keep the gemmi + // placeholder so siblings' `ri` stays valid; _compact_residues drops both. A no-op + // during Manager teardown (memory is freed wholesale by ~Manager). + inline Residue::~Residue() { + if (!mgr || mgr->_bulk_free) return; + Manager *m = mgr; + // free my atoms: null each atom's res first so ~Atom doesn't mutate this->atoms + // mid-iteration (~Atom still cleans all_atoms/model/selections/registry). + std::vector ats = atoms; + atoms.clear(); + for (Atom *a : ats) { + a->res = nullptr; + delete a; + } + // tombstone my slot in the parent chain (keep the gemmi placeholder residue) + if (chain) { + auto &rv = chain->residues; + for (size_t i = 0; i < rv.size(); ++i) + if (rv[i] == this) { + rv[i] = nullptr; + break; + } + } + m->_res_allocs.erase(this); + } + + inline void Chain::_compact_residues() { + // Drop tombstoned (null) wrapper slots and their gemmi placeholder residues in + // lock-step (wrapper[i] <-> g().residues[i]); then reindex ri to the new order. + bool any_null = false; + for (Residue *r : residues) + if (!r) { + any_null = true; + break; + } + if (!any_null) return; + std::vector keptw; + std::vector keptg; + gemmi::Chain &gc = g(); + keptw.reserve(residues.size()); + keptg.reserve(gc.residues.size()); + for (size_t i = 0; i < residues.size(); ++i) { + if (residues[i]) { + keptw.push_back(residues[i]); + if (i < gc.residues.size()) keptg.push_back(std::move(gc.residues[i])); + } + } + residues.swap(keptw); + gc.residues.swap(keptg); + for (int k = 0; k < (int)residues.size(); ++k) residues[k]->ri = k; + } + // ---- Chain out-of-line ---- inline bool Chain::isAminoacidChain() { for (Residue *r : residues) - if (r->isAminoacid()) return true; + if (r && r->isAminoacid()) return true; return false; } inline bool Chain::isNucleotideChain() { for (Residue *r : residues) - if (r->isNucleotide()) return true; + if (r && r->isNucleotide()) return true; return false; } inline bool Chain::isSolventChain() { if (residues.empty()) return false; for (Residue *r : residues) - if (!r->isSolvent()) return false; + if (r && !r->isSolvent()) return false; return true; } inline pstr Chain::GetChainID() { @@ -1822,6 +1924,7 @@ namespace mmdb { return rw; } inline PResidue Chain::InsResidue(Manager &m, int pos, gemmi::Residue r) { + _compact_residues(); // don't insert/reindex across deferred-delete tombstones g().residues.insert(g().residues.begin() + pos, std::move(r)); Residue *rw = m.newRes(); rw->mgr = &m; @@ -2389,15 +2492,19 @@ namespace mmdb { // peptide-bond distance threshold for backbone C-N (a real bond is ~1.33 A). inline bool Residue::isNTerminus() { if (!chain || ri <= 0) return true; // first (or detached) residue + Residue *prev = chain->residues[ri - 1]; + if (!prev) return true; // previous slot is a deferred-delete tombstone const gemmi::Atom *N = g().get_n(); - const gemmi::Atom *prevC = chain->residues[ri - 1]->g().get_c(); + const gemmi::Atom *prevC = prev->g().get_c(); if (!N || !prevC) return true; // missing backbone -> terminus return N->pos.dist(prevC->pos) > 1.7; // not bonded to previous C } inline bool Residue::isCTerminus() { if (!chain || ri < 0 || ri >= (int)chain->residues.size() - 1) return true; // last/detached + Residue *next = chain->residues[ri + 1]; + if (!next) return true; // next slot is a deferred-delete tombstone const gemmi::Atom *C = g().get_c(); - const gemmi::Atom *nextN = chain->residues[ri + 1]->g().get_n(); + const gemmi::Atom *nextN = next->g().get_n(); if (!C || !nextN) return true; return C->pos.dist(nextN->pos) > 1.7; // not bonded to next N } From 979c23b8f0d9a915ac2610bfba4b08d2e2d312b3 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Wed, 22 Jul 2026 18:07:07 +0100 Subject: [PATCH 12/23] Fixed bugs with implementation --- mmdb-shim/include/mmdb2/_shim_impl.hh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh index 6d46ba0037..f14440a2a4 100644 --- a/mmdb-shim/include/mmdb2/_shim_impl.hh +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -1710,7 +1710,15 @@ namespace mmdb { // gemmi's own formatting stays correct. inline void Atom::SetAtomName(const AtomName aName) { g().name = aName ? gemmi::trim_str(aName) : ""; } inline pstr Atom::GetElementName() { - std::snprintf(_elem_buf, sizeof(_elem_buf), "%s", g().element.name()); + // MMDB returns the PDB-column-aligned element: 2 chars, right-justified, + // UPPERCASE (" H", " C", "NA", "FE"). gemmi's Element::name() is unpadded and + // mixed-case ("H"/"C"/"Na"/"Fe"), so Coot's element tests — e.g. + // get_number_of_hydrogen_atoms() comparing `ele == " H"` — never match. Align + // to MMDB: uppercase then right-pad into a 2-wide field. + std::string e = g().element.name(); + for (char &c : e) c = std::toupper((unsigned char)c); + if (e.size() < 2) e.insert(e.begin(), 2 - e.size(), ' '); + std::snprintf(_elem_buf, sizeof(_elem_buf), "%s", e.c_str()); return _elem_buf; } inline void Atom::SetElementName(const Element elName) { g().element = gemmi::Element(elName); } @@ -1753,8 +1761,15 @@ namespace mmdb { inline pstr Residue::GetChainID() { return chain ? chain->GetChainID() : mmdb_empty_pstr(); } inline int Residue::GetModelNum() { return (chain && chain->model) ? chain->model->GetSerNum() : 0; } inline PAtom Residue::GetAtom(const AtomName aname, const Element elname, const AltLoc aloc) { + // MMDB matches the PDB-column-aligned 4-char name (real Coot calls + // `GetAtom(" CA ")`), but gemmi stores names trimmed ("CA"). Trim the query so + // both padded and unpadded lookups resolve — mirrors the selection matchers + // (detail::inList / SelectAtoms), which already trim both sides. Element/altLoc + // still disambiguate when supplied (e.g. carbon-alpha " CA " vs calcium "CA ", + // which share a trimmed name). + const std::string want = aname ? gemmi::trim_str(aname) : std::string(); for (Atom *a : atoms) { - if (a->g().name != aname) continue; + if (std::string(a->g().name) != want) continue; if (elname && *elname && a->g().element.name() != std::string(elname)) continue; if (aloc && *aloc && a->g().altloc != aloc[0]) continue; return a; From 8be310197888511693a67fcffa25a6c37f285658 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Wed, 22 Jul 2026 18:32:06 +0100 Subject: [PATCH 13/23] Create alternate to MMDBAtom_list in clipper --- coot-utils/maps-spherical.cc | 3 +- coot-utils/mmdb-to-clipper-atom-list.hh | 76 +++++++++++++++++++++++++ coot-utils/read-sm-cif.cc | 3 +- coot-utils/sfcalc-genmap.cc | 5 +- mmdb-shim/include/mmdb2/_shim_impl.hh | 12 ++-- src/molecule-class-info-maps.cc | 5 +- 6 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 coot-utils/mmdb-to-clipper-atom-list.hh diff --git a/coot-utils/maps-spherical.cc b/coot-utils/maps-spherical.cc index 0ed17c0353..3a8ab83d23 100644 --- a/coot-utils/maps-spherical.cc +++ b/coot-utils/maps-spherical.cc @@ -27,6 +27,7 @@ #include "utils/coot-utils.hh" #include "coot-map-utils.hh" +#include "mmdb-to-clipper-atom-list.hh" #include "emma.hh" #include "peak-search.hh" #include "xmap-stats.hh" // needed? @@ -86,7 +87,7 @@ coot::util::emma::sfs_from_boxed_molecule(mmdb::Manager *mol_orig, float border) std::cout << "DEBUG:: P1-sfs: cell " << cell.format() << std::endl; std::cout << "DEBUG:: P1-sfs: resolution limit " << reso.limit() << std::endl; - clipper::MMDBAtom_list atoms(atom_selection, n_selected_atoms); + coot::MMDBAtom_list atoms(atom_selection, n_selected_atoms); std::cout << "DEBUG:: P1-sfs: n_selected_atoms: " << n_selected_atoms << std::endl; fc_from_model = clipper::HKL_data(hkl_info, cell); diff --git a/coot-utils/mmdb-to-clipper-atom-list.hh b/coot-utils/mmdb-to-clipper-atom-list.hh new file mode 100644 index 0000000000..daeff1e26e --- /dev/null +++ b/coot-utils/mmdb-to-clipper-atom-list.hh @@ -0,0 +1,76 @@ +/* + * coot-utils/mmdb-to-clipper-atom-list.hh + * + * Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology + * + * This file is part of Coot + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copies of the GNU General Public License and + * the GNU Lesser General Public License along with this program; if not, + * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth + * Floor, Boston, MA 02110-1301, USA. + * See http://www.gnu.org/licenses/ + */ + +#ifndef COOT_UTILS_MMDB_TO_CLIPPER_ATOM_LIST_HH +#define COOT_UTILS_MMDB_TO_CLIPPER_ATOM_LIST_HH + +#include +#include +#include + +namespace coot { + + //! A drop-in replacement for clipper::MMDBAtom_list. + // + // clipper::MMDBAtom (clipper/mmdb/clipper_mmdb.cpp) derives from mmdb::CAtom and + // reads the atom's coordinate/element/occupancy/B as *public data members* + // (`return Coord_orth(x,y,z);`, `String(mmdb::CAtom::element)`, ...). Those method + // bodies are compiled into libclipper-mmdb against real MMDB's memory layout, so + // reinterpret-casting an mmdb-shim atom (which is gemmi-backed, with a completely + // different layout, and exposes x()/element via accessor methods) to MMDBAtom* + // reads garbage — every structure-factor calculation then sees junk coordinates. + // + // clipper::Atom / Atom_list are pure clipper value types with no MMDB dependency, + // so we build the Atom_list ourselves through the shim's accessor methods. The + // result feeds clipper's SFcalc unchanged. Matches clipper::MMDBAtom's field + // semantics: element as the PDB-aligned 2-char string, isotropic U from B, and + // anisotropic U only when ANISOU was present. + class MMDBAtom_list : public clipper::Atom_list { + public: + MMDBAtom_list(const mmdb::PPAtom ppcatom, const int natom) { + reserve(natom); + for (int i = 0; i < natom; i++) { + mmdb::Atom *at = ppcatom[i]; + if (!at) continue; + clipper::Atom a; + a.set_element(clipper::String(at->GetElementName())); + if (!at->isTer()) + a.set_coord_orth(clipper::Coord_orth(at->x(), at->y(), at->z())); + else + a.set_coord_orth(clipper::Coord_orth(clipper::Coord_orth::null())); + a.set_occupancy(at->occupancy()); + a.set_u_iso(clipper::Util::b2u(at->tempFactor())); + if (at->WhatIsSet & ::mmdb::ASET_Anis_tFac) + a.set_u_aniso_orth(clipper::U_aniso_orth(at->u11(), at->u22(), at->u33(), + at->u12(), at->u13(), at->u23())); + else + a.set_u_aniso_orth(clipper::U_aniso_orth(clipper::U_aniso_orth::null())); + push_back(a); + } + } + }; + +} // namespace coot + +#endif // COOT_UTILS_MMDB_TO_CLIPPER_ATOM_LIST_HH diff --git a/coot-utils/read-sm-cif.cc b/coot-utils/read-sm-cif.cc index 95eecb0ab2..430f8d45b8 100644 --- a/coot-utils/read-sm-cif.cc +++ b/coot-utils/read-sm-cif.cc @@ -29,6 +29,7 @@ #include #include #include +#include "mmdb-to-clipper-atom-list.hh" #include "clipper/core/clipper_instance.h" // tidy up space group cache #include "clipper/core/resol_basisfn.h" #include "clipper/contrib/sfcalc_obs.h" @@ -1089,7 +1090,7 @@ coot::smcif::sigmaa_maps_by_calc_sfs(mmdb::Atom **atom_selection, int n_selected mydata.cell(), hkl_sampling_local); // get a list of all the atoms - clipper::MMDBAtom_list atoms(atom_selection, n_selected_atoms); + coot::MMDBAtom_list atoms(atom_selection, n_selected_atoms); clipper::HKL_data< clipper::datatypes::F_phi > fphidata(mydata.spacegroup(), mydata.cell(), hkl_sampling_local); diff --git a/coot-utils/sfcalc-genmap.cc b/coot-utils/sfcalc-genmap.cc index 871100dd39..4f2b3e04ed 100644 --- a/coot-utils/sfcalc-genmap.cc +++ b/coot-utils/sfcalc-genmap.cc @@ -34,6 +34,7 @@ #include #include "sfcalc-genmap.hh" +#include "mmdb-to-clipper-atom-list.hh" // calculate structure factors from the given model and data // and update the map xmap_p @@ -64,7 +65,7 @@ void coot::util::sfcalc_genmap(mmdb::Manager *mol, int hndl = mol->NewSelection(); // d mol->SelectAtoms(hndl, 0, 0, ::mmdb::SKEY_NEW); mol->GetSelIndex(hndl, atom_sel, nsel); - clipper::MMDBAtom_list atoms(atom_sel, nsel); + coot::MMDBAtom_list atoms(atom_sel, nsel); // clipper::MTZcrystal cxtl; clipper::HKL_info hkls; @@ -245,7 +246,7 @@ coot::util::sfcalc_genmaps_using_bulk_solvent(mmdb::Manager *mol, int hndl = mol->NewSelection(); // d mol->SelectAtoms(hndl, 0, 0, ::mmdb::SKEY_NEW); mol->GetSelIndex(hndl, atom_sel, nsel); - clipper::MMDBAtom_list atoms(atom_sel, nsel); + coot::MMDBAtom_list atoms(atom_sel, nsel); // std::cout << "DEBUG:: in sfcalc_genmaps_using_bulk_solvent() nsel for atoms " << nsel << std::endl; auto tp_2 = std::chrono::high_resolution_clock::now(); diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh index f14440a2a4..0c4c4842d1 100644 --- a/mmdb-shim/include/mmdb2/_shim_impl.hh +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -1590,14 +1590,16 @@ namespace mmdb { int RegisterUDString(UDR_TYPE t, cpstr name) { return _regUD(t, 2, name); } int GetUDDHandle(UDR_TYPE t, cpstr name) { for (int i = 0; i < (int)ud_regs.size(); ++i) - if (ud_regs[i].type == t && ud_regs[i].name == name) return i; - return -1; + if (ud_regs[i].type == t && ud_regs[i].name == name) return i + 1; + return 0; // MMDB: 0 == "not registered" — Coot relies on `if (handle == 0) Register…` } private: + // MMDB UDData handles are 1-based (0 is reserved for "not registered", see + // GetUDDHandle). Return a 1-based handle; _ud_desc maps back with handle-1. int _regUD(UDR_TYPE t, int kind, cpstr name) { ud_regs.push_back({t, kind, name ? name : "", ud_counts[t][kind]++}); - return (int)ud_regs.size() - 1; + return (int)ud_regs.size(); } public: @@ -1632,11 +1634,11 @@ namespace mmdb { // ---- UDData helpers ---- inline Manager::UDReg *_ud_desc(Manager *mgr, UDR_TYPE myType, int handle, int kind, int &err) { - if (!mgr || handle < 0 || handle >= (int)mgr->ud_regs.size()) { + if (!mgr || handle < 1 || handle > (int)mgr->ud_regs.size()) { err = UDDATA_WrongHandle; return nullptr; } - Manager::UDReg &d = mgr->ud_regs[handle]; + Manager::UDReg &d = mgr->ud_regs[handle - 1]; // handles are 1-based (see _regUD) if (d.type != myType || d.kind != kind) { err = UDDATA_WrongUDRType; return nullptr; diff --git a/src/molecule-class-info-maps.cc b/src/molecule-class-info-maps.cc index 83677829fa..3a9004f9a1 100644 --- a/src/molecule-class-info-maps.cc +++ b/src/molecule-class-info-maps.cc @@ -58,6 +58,7 @@ #include "coords/mmdb-crystal.hh" #include "coot-utils/coot-coord-utils.hh" #include "coot-utils/xmap-stats.hh" +#include "coot-utils/mmdb-to-clipper-atom-list.hh" #include "density-contour/CIsoSurface.h" #include "molecule-class-info.h" @@ -3130,7 +3131,7 @@ molecule_class_info_t::calculate_sfs_and_make_map(int imol_no_in, clipper::HKL_data< clipper::datatypes::F_phi > map_fphidata(myfsigf.spacegroup(),myfsigf.cell(), myfsigf.hkl_sampling()); // get a list of all the atoms - clipper::MMDBAtom_list atoms(SelAtom.atom_selection, SelAtom.n_selected_atoms); + coot::MMDBAtom_list atoms(SelAtom.atom_selection, SelAtom.n_selected_atoms); std::cout << "isotropic fft of " << SelAtom.n_selected_atoms << " atoms..." << std::endl; @@ -3247,7 +3248,7 @@ molecule_class_info_t::calculate_sfs_and_make_map(int imol_no_in, hndl = mmdb->NewSelection(); mmdb->SelectAtoms( hndl, 0, 0, mmdb::SKEY_NEW ); mmdb->GetSelIndex( hndl, psel, nsel ); - clipper::MMDBAtom_list atoms( psel, nsel ); + coot::MMDBAtom_list atoms( psel, nsel ); mmdb->DeleteSelection( hndl ); // calculate structure factors From 412be75041386faed42db38a1e6821ce670d36a3 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Wed, 22 Jul 2026 18:46:14 +0100 Subject: [PATCH 14/23] Fix issue with numeric CID defaulting to model --- mmdb-shim/include/mmdb2/_shim_impl.hh | 30 ++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh index 0c4c4842d1..dadb6b8ab8 100644 --- a/mmdb-shim/include/mmdb2/_shim_impl.hh +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -2201,6 +2201,10 @@ namespace mmdb { // Harmless for chain IDs / residue / element names (already unpadded). inline bool inList(cpstr list, const std::string &v) { if (!list || !*list || std::strcmp(list, "*") == 0) return true; + // MMDB negation: a leading '!' inverts the match (e.g. "!HOH" = any residue + // that is not water). Coot's Select() uses this for chain/residue/element/ + // atom-name filters; without it every residue is (wrongly) excluded. + if (list[0] == '!') return !inList(list + 1, v); std::string vt = trimws(v); const char *p = list; while (*p) { @@ -2387,10 +2391,26 @@ namespace mmdb { size_t c = v.find_first_of(seps); return c == std::string::npos ? v : v.substr(0, c); }; + // Assign tokens to model/chain/residue/atom. A leading '/' (or any '/') means + // the model field is present at tok(0). A slash-less CID has NO model/chain + // prefix: MMDB reads a bare numeric token as a residue seqNum ("262" = residue + // 262 in every chain), and a bare non-numeric token as a chain id ("A"). + std::string model_s, chain_s, res_s, atom_s; + if (s.find('/') != std::string::npos) { + model_s = tok(0); + chain_s = tok(1); + res_s = tok(2); + atom_s = tok(3); + } else { + const std::string only = tok(0); + if (!only.empty() && (std::isdigit((unsigned char)only[0]) || only[0] == '-')) + res_s = only; + else + chain_s = only; + } int iModel = 0; - std::string m = tok(0); - if (!m.empty() && m != "*" && m != "0") iModel = atoi(m.c_str()); - std::string chains = tok(1).empty() ? "*" : tok(1); + if (!model_s.empty() && model_s != "*" && model_s != "0") iModel = atoi(model_s.c_str()); + std::string chains = chain_s.empty() ? "*" : chain_s; int r1 = ANY_RES, r2 = ANY_RES; std::string ins1 = "*", ins2 = "*"; // split "num[.ins]" into number + insertion code @@ -2399,7 +2419,7 @@ namespace mmdb { num = atoi(v.substr(0, dot).c_str()); ins = (dot == std::string::npos) ? std::string() : v.substr(dot + 1); }; - std::string rr = strip(tok(2), "("); // drop (resname) + std::string rr = strip(res_s, "("); // drop (resname) if (!rr.empty() && rr != "*") { size_t dash = rr.find('-', rr[0] == '-' ? 1 : 0); if (dash == std::string::npos) { @@ -2411,7 +2431,7 @@ namespace mmdb { parse_resid(rr.substr(dash + 1), r2, ins2); } } - std::string anames = strip(strip(tok(3), "["), ":"); // drop [element]/:altloc + std::string anames = strip(strip(atom_s, "["), ":"); // drop [element]/:altloc if (anames.empty()) anames = "*"; Select(selHnd, sType, iModel, chains.c_str(), r1, ins1.c_str(), r2, ins2.c_str(), "*", anames.c_str(), "*", "*", sKey); From 5a59657a593bf1e9335506dbb19f2f0e8aa7a5da Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Wed, 22 Jul 2026 18:57:04 +0100 Subject: [PATCH 15/23] Fix bug with stale owner --- mmdb-shim/include/mmdb2/_shim_impl.hh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh index dadb6b8ab8..211f086660 100644 --- a/mmdb-shim/include/mmdb2/_shim_impl.hh +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -1558,14 +1558,27 @@ namespace mmdb { void _rebuild_all_atoms() { all_atoms.clear(); for (Model *mw : models) { + mw->mgr = this; mw->all_atoms.clear(); - for (Chain *cw : mw->chains) + for (Chain *cw : mw->chains) { + cw->mgr = this; for (Residue *rw : cw->residues) - if (rw) + if (rw) { + rw->mgr = this; for (Atom *aw : rw->atoms) { + // Rebind ownership pointers: residues added via AddResidue/ + // InsResidue (e.g. add_terminal_residue) carry atoms whose mgr + // still points at the deep-copy temporary (or is null). Atom + // UDData routes through Atom::mgr, so without this the new atoms + // fail Put/GetUDData with WrongHandle — which drops their bonds + // (the atom-index UDD never lands) and any UD colouring. + aw->mgr = this; + aw->res = rw; all_atoms.push_back(aw); mw->all_atoms.push_back(aw); } + } + } } } int FinishStructEdit() { From 265f85d02b2077ddba742807befa1845208f3f61 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Thu, 23 Jul 2026 09:32:22 +0100 Subject: [PATCH 16/23] Split up implementation and added architecture.md --- mmdb-shim/ARCHITECTURE.md | 329 +++ mmdb-shim/include/mmdb2/_shim_hierarchy.hh | 612 +++++ mmdb-shim/include/mmdb2/_shim_impl.hh | 2698 +------------------- mmdb-shim/include/mmdb2/_shim_inline.hh | 1061 ++++++++ mmdb-shim/include/mmdb2/_shim_manager.hh | 533 ++++ mmdb-shim/include/mmdb2/_shim_types.hh | 513 ++++ 6 files changed, 3074 insertions(+), 2672 deletions(-) create mode 100644 mmdb-shim/ARCHITECTURE.md create mode 100644 mmdb-shim/include/mmdb2/_shim_hierarchy.hh create mode 100644 mmdb-shim/include/mmdb2/_shim_inline.hh create mode 100644 mmdb-shim/include/mmdb2/_shim_manager.hh create mode 100644 mmdb-shim/include/mmdb2/_shim_types.hh diff --git a/mmdb-shim/ARCHITECTURE.md b/mmdb-shim/ARCHITECTURE.md new file mode 100644 index 0000000000..13f821689c --- /dev/null +++ b/mmdb-shim/ARCHITECTURE.md @@ -0,0 +1,329 @@ +# mmdb-shim architecture + +A drop-in replacement for the MMDB2 C++ API (`mmdb::*`) backed by +[gemmi](https://gemmi.readthedocs.io). Coot is built against this +shim instead of libmmdb2: the public headers under `include/mmdb2/` present +MMDB's classes, but every object is a thin wrapper over a live +`gemmi::Structure`. The goal is to remove the MMDB2 dependency while reproducing +MMDB's observable behaviour exactly. + + +--- + +## 1. Why a wrapper tree, not a live proxy + +A live proxy over `gemmi::Structure` (translate every call on demand) is not +possible, because Coot: + +- **writes MMDB public data members directly** — `atom->x`, `->occupancy`, + `residue->seqNum`, etc. (hundreds of sites); +- relies on **UDData** (`GetUDData`/`PutUDData`, hundreds of call sites) and the + **handle-based selection engine** — neither of which gemmi has; +- keys ~1000 containers on raw `mmdb::T*` and assumes **pointer identity and + stability** across edits (`AddAtom`, mid-list insert, `delete atom`). + +So the shim **owns an MMDB-shaped wrapper hierarchy** over the gemmi structure +and **reimplements selection + UDData**. gemmi is used only where it does the +real work well (I/O, symmetry, neighbour search, chemistry) — see §6. + +Field access is handled by making every MMDB public scalar an **accessor**: +`atom->x` was mechanically rewritten to `atom->x()` — this was a **one-time, +in-place edit of the Coot source tree** (§2), not a header trick. `x()` returns +`gemmi::Atom::pos.x` by reference so both reads and writes flow through to gemmi. +Narrower gemmi types (float `occ`/`b_iso`, `signed char charge`, single-char +`altloc`) use value-get + `set_*`. + +--- + +## 2. The one-time Coot source rewrite (`->x` → `->x()`) + +MMDB exposes atom/residue state as **public data members**; gemmi does not, and a +member cannot transparently become a method. So before Coot could build against +the shim, its source tree was rewritten once: every access to a rewritten MMDB +field was turned into a call, e.g. + +``` +atom->x -> atom->x() +atom->x = 1.2 -> atom->x() = 1.2 // ref-returning accessor: write still works +strcpy(at->name,s) -> at->SetAtomName(s) // char[] fields go through a setter +``` + +**This is a real, committed change to the Coot `.cc`/`.hh` sources** — not +something the headers do at compile time. The shim then defines the matching +accessors (§1). + +**The tool.** `mmdb-recon/ast/mmdb_tool.cpp` is a clang **libTooling / +AST-matcher** program (the same Phase-0 recon tool that emitted +`mmdb-recon/ast/mmdb_surface.json`; run with `--rewrite-fields` it becomes a +`RefactoringTool`). Build it with `mmdb-recon/ast/build.sh` (needs +`brew install llvm` — Apple clang lacks the libTooling dev headers). It is +**class-aware**: a config table (`kRules` / `kSetters` in `mmdb_tool.cpp`) lists +exactly which fields on which classes to rewrite — + +- `mmdb::Atom`: `x y z occupancy tempFactor charge altLoc serNum`, the ESD + fields `sigX…sigTemp`, the aniso tensor `u11…u23` (all ref-returning); + `name`→`GetAtomName`, `element`→`GetElementName`, `residue`→`GetResidue`; + `strcpy(name…)`→`SetAtomName`, `strcpy(element…)`→`SetElementName`. +- `mmdb::Residue`: `name`→`GetResName`, `seqNum`→`GetSeqNum`, + `insCode`→`GetInsCode`, `index`→`GetIndex`; `strcpy(name…)`→`SetResName`. + +Fields not in the table are left untouched — they surface as compile errors when +building Coot against the shim and are added to the table (or the shim) as they +appear. + +**Driver + guardrails** (`rewrite.sh` at the repo root): + +- **Rewrite against *real* MMDB, build against the shim.** The tool matches + `atom->x` as a real-mmdb *field*; if the compile DB pointed at the shim, `->x` + would already be a method and nothing would match. `rewrite.sh` aborts if the + `compile_commands.json` contains `mmdb-shim/include`. +- **Dedup across TUs.** A header is parsed once per includer; point-insertions of + `()` don't conflict in clang's `Replacements`, so without a guard they *stack* + (`x()()()…`). `firstRewriteAt(file,offset)` records each site so only the first + wins; `rewrite.sh` also greps the diff for `()()` as a safety net. +- **Do it on a dedicated branch** — it touches hundreds of files; the tool writes + all edits at the end of the run (after parsing every TU), and it is reversible + with `git checkout`. + +The synthetic fixture in `mmdb-shim/test/rewrite/` exercises the Atom+Residue +rules in the standalone suite. + +--- + +## 3. File layout + +Public API headers (what Coot includes) are macro-guarded veneers: + +``` +include/mmdb2/mmdb_manager.h, mmdb_atom.h, … (14 headers) + #ifdef COOT_USE_MMDB_SHIM -> #include "_shim_impl.hh" (this shim) + #else -> #include_next (real MMDB) +``` + +`#include_next` lets the same tree fall through to real MMDB with the macro off, +for A/B comparison. The implementation is header-only (so the accessor rewrite +and inline hot paths cross TU boundaries) and split into four dependency-ordered +layers, each opening its own `namespace mmdb`: + +| Header | Contents | +|---|---| +| `_shim_types.hh` | typedefs, enums, `UDStore` base, forward decls, leaf record classes (LINK/CisPep/Cryst/Helix/Sheet/SymOps/Title), free helpers | +| `_shim_hierarchy.hh` | `Atom` / `Residue` / `Chain` / `Model` class definitions | +| `_shim_manager.hh` | `Manager` (MMDB Root + CoorManager + SelManager) and nested `Selection` / `UDReg` | +| `_shim_inline.hh` | `g()` resolvers, UDData helpers, all out-of-line method bodies, the `detail::` selection matchers, free functions | +| `_shim_impl.hh` | umbrella: includes the four layers in order, then the two subsystems below | + +Two subsystems have their own headers, included last (they need a complete +`Atom`/`Residue`): + +- `_mmcif_impl.hh` — `mmdb::mmcif::*` over `gemmi::cif`. +- `_graph_impl.hh` — `mmdb::math::{Vertex,Edge,Graph,GraphMatch}` graph matching. + +Two heavyweight operations are compiled once in `src/*.cc` (built into +`lib/libmmdbshim.a`) rather than inlined, to keep gemmi's large read/write and +neighbour-search headers out of the ~230 Coot TUs that include +``: + +- `src/io.cc` — `Manager::Read*/Write*` via gemmi. +- `src/contacts.cc` — `Manager::SeekContacts` / `SelectNeighbours` via gemmi + `NeighborSearch`. + +--- + +## 4. The wrapper node and `g()` resolution + +Each hierarchy class (`Atom`/`Residue`/`Chain`/`Model`) is a stable node holding: + +- `Manager* mgr` — owning manager; +- a **parent pointer** (`res` / `chain` / `model` / — ; null ⇒ *detached*); +- a **cached sibling index** (`ai` / `ri` / `ci` / `mi`); +- a canonical `std::vector` — this doubles as the **identity cache** and + as the `PPAtom`/`PPResidue` table MMDB hands back; +- a `gemmi::T _local` used only while detached. + +`g()` resolves a wrapper to its live gemmi object **by index through the parent +chain**: + +```cpp +gemmi::Atom& Atom::g() { return res->chain->model->mgr->st + .models[mi].chains[ci].residues[ri].atoms[ai]; } +``` + +Index-based (not pointer-based) resolution is the key trick: when a +`std::vector` push reallocates, sibling wrappers stay valid — only the affected +container's indices are patched. This is what gives Coot the pointer stability it +assumes while gemmi's vectors move underneath. + +**Detached construction.** Coot's ubiquitous idiom is `new mmdb::Atom; set +fields…; residue->AddAtom(at)`. A wrapper with no parent stores its data in +`_local`; `g()` returns `_local`. `Add*()` copies `_local` into the parent's +gemmi vector, sets the parent pointer + index, and cascades `mgr` down the +subtree that was built while detached. + +--- + +## 5. Memory management + +MMDB owns hierarchy nodes with `new`/`delete` and Coot exploits this directly +(`delete atom;`, `delete residue_p;`). The shim matches that contract: + +**Ownership.** +- The `Manager` owns the one `gemmi::Structure st` — the single source of truth. +- **Atoms and residues are individually heap-allocated** (`Manager::newAtom` / + `newRes`) and tracked in `std::set _atom_allocs` / `_res_allocs`, so a + single `delete atom;` frees exactly one node. +- Chains and models are pooled in `std::deque/` (stable addresses, + never individually deleted by Coot). +- gemmi-derived metadata records (LINK/CISPEP/HELIX/SHEET/author) live in + per-`Manager` `std::deque` pools; the `Model` containers hold bare pointers + into them. + +**Deletion of a live atom** (`~Atom`, i.e. Coot's `delete atom;`): detach from +the parent residue's wrapper+gemmi vectors (kept in lockstep), remove from the +manager/model flat atom lists and any selections, reindex trailing siblings, then +drop from `_atom_allocs`. No dangling pointer survives. + +**Deferred residue deletion.** MMDB's `DeleteResidue` (and `delete residue_p;`) +is *deferred*: it frees the residue's atoms and **tombstones** the slot (nulls +the wrapper pointer, keeps a gemmi placeholder residue) without changing +`nResidues`, until `FinishStructEdit`/`TrimResidueTable`. Coot depends on this +(e.g. `change_chain_id` iterates to the original count while deleting). The +placeholder keeps surviving siblings' `ri` valid; `_compact_residues()` later +drops the null wrapper slot and its gemmi placeholder in lockstep and reindexes. + +**Teardown.** `~Manager` sets `_bulk_free = true` and frees the alloc sets +wholesale; `~Atom`/`~Residue` see the flag and skip all the detach bookkeeping +(memory is going away anyway), avoiding O(n²) teardown. + +**Returned arrays.** `SeekContacts` returns `Contact*` allocated with `new[]`; +the caller `delete[]`s it — the MMDB contract. Borrowed C-strings from accessors +(`GetAtomName`, UDData strings) are backed by per-object buffers / `deque` +and are never freed by Coot. + +--- + +## 6. How gemmi is used (the boundaries) + +The rule is **prefer gemmi**: never reimplement what gemmi provides. Mapping: + +| MMDB surface | gemmi backing | +|---|---| +| PDB / mmCIF read + write | `read_pdb_file` / `read_structure_file` / `write_pdb` / `make_mmcif_document`; `merge_chain_parts()` on read for MMDB one-chain-per-ID parity | +| coordinates, occ, B, aniso, altLoc, element, serial | `gemmi::Atom` fields via `g()` | +| cell / fractionalisation | `gemmi::UnitCell` (`fractionalize`/`orthogonalize`) | +| symmetry (`GetTMatrix`, sym ops) | `SpaceGroup::operations()` composed with the cell frac↔orth transforms | +| neighbour / contact search | `gemmi::NeighborSearch` (grid-accelerated) | +| element data (`getVdWaalsRadius`, `isMetal`) | `gemmi::Element` | +| residue classification (`isAminoacid`/`isSolvent`/`isSugar`/`Get1LetterCode`) | `gemmi::find_tabulated_residue` | +| LINK / CISPEP / HELIX / SHEET / authors | `Structure::{connections,cispeps,helices,sheets}`, `meta.authors` | +| `mmdb::mmcif::*` | `gemmi::cif` (Document/Block/Loop/Table) | + +`Manager::_load_metadata()` reshapes gemmi's structure-level metadata into the +MMDB per-`Model` record containers on load. + +--- + +## 7. What the shim implements itself (no gemmi equivalent) + +These are hand-written because gemmi has nothing to map onto. They are kept +minimal. + +- **UDData slots.** Each object derives from `UDStore` (contiguous + `int`/`double`/`string` vectors + selection-membership bits). `Manager` holds a + 1-based handle registry (`ud_regs`); registering a handle assigns a per-(type, + kind) slot; `PutUDData`/`GetUDData` index into the object's vectors. + Handle `0` means "not registered" — Coot relies on `if (h==0) Register…`. + +- **Selection engine.** `Manager` owns a vector of `Selection`s (1-based + handles). `Select` walks the wrapper tree filtering on model/chain/(seqNum, + insCode)-range/resname/atom-name/element/altLoc, supporting `SKEY_*` set + combinators and MMDB's `"!X"` negation and `"*"` wildcard. Membership is + mirrored in each object's `_inSel` bits so deletion can scrub stale pointers. + CID strings (`"/1/A/10-20/CA"`) are parsed by a pragmatic tokeniser into that + same filter call. + +- **Pointer-stable wrapper identity.** The whole `vector` + + index-locator scheme in §4 exists because gemmi's containers move and have no + spare identity field; MMDB code cannot tolerate that. + +- **Contacts (illustrative).** The common path *does* use gemmi + `NeighborSearch` — but where gemmi doesn't fit, the shim fills the gap + in-house. `SeekContacts` with an MMDB `TMatrix` needs contacts against an + arbitrarily **symmetry-transformed** copy of the second atom set; gemmi's + search indexes the model's own atoms, not a caller-supplied transformed set. So + that path (`contacts_transformed` in `src/contacts.cc`) transforms the set and + runs a small hand-rolled **uniform-grid** neighbour search. The + `NeighborSearch::Mark`→wrapper mapping goes back through the parallel tree + (`chains[chain_idx].residues[residue_idx].atoms[atom_idx]`). + +- **Graph / subgraph matching** (`_graph_impl.hh`). `mmdb::math::Graph`/ + `GraphMatch` is a branch-and-bound maximum-common-**induced**-subgraph matcher + (element + bond-type constrained). gemmi has no subgraph isomorphism, so this + is genuinely shim-owned (design: `../mmdb-graph-matching-for-gemmi.md`). + +- **Sequence alignment** (`math::Alignment`). A faithful re-creation of MMDB's + Needleman-Wunsch with **identity scoring** (match=1/mismatch=0/linear gap). + gemmi *has* an aligner, but only with substitution-matrix scoring, which would + change which residues Coot calls mutations vs indels — so matching the MMDB + baseline requires MMDB's specific scoring, which gemmi does not offer. + +- **PDB-column name alignment.** MMDB returns 4-char aligned atom names + (`" CA "`) and 2-char right-justified upper-case elements (`" C"`, `"NA"`); + gemmi stores trimmed/mixed-case. `GetAtomName`/`GetElementName` re-pad, and + matchers trim both sides, because Coot's specs and colour/element tests depend + on the padded form. + +--- + +## 8. External dependency walls + +MMDB is also used by libraries Coot links that are **precompiled against real +MMDB 2.0.22** (different ABI). Passing shim objects across those boundaries is +UB. Handled by shadowing headers (the shim include dir precedes theirs on `-I`): + +- **`include/gemmi/mmdb.hpp`** shadows gemmi's own MMDB bridge. The real one + copies field-by-field through real-mmdb public fields (incompatible with + accessors). The shim's `copy_to_mmdb`/`copy_from_mmdb` are trivial because + `Manager` already owns a `gemmi::Structure`. + +- **`include/ssm/ssm_align.h`** shadows libssm (structural superposition) with a + self-contained **no-op `ssm::Align`** — `align()` returns `RC_NoHits` with an + identity matrix, so callers take their no-superposition path. SSM is being + removed; its real headers pull the full real-mmdb binary-serialization API. + +- **clipper `MMDBAtom_list`**: clipper's prebuilt dylib reads `mmdb::Atom` x/y/z/ + occ/B as *data fields* → garbage on shim atoms. The fix lives in Coot + (`coot-utils/mmdb-to-clipper-atom-list.hh`): build the `clipper::Atom_list` + through the shim's *method* accessors. `clipper::Atom_list` is pure clipper with + no mmdb ABI dependency. + +--- + +## 9. Intentionally inert / mocked + +Documented in-source; each is a deliberate decision, not an omission: + +- **Secondary-structure assignment** (`CalcSecStructure`) returns the non-OK code + — gemmi's DSSP has SS prediction disabled upstream, so there is no gemmi SS to + forward and residues keep `SSE_None`. +- **`MakeBonds`** is a no-op — Coot's only caller recomputes bonds from geometry + and ignores the MMDB bond table. +- **`Cryst::GetTMatrix`** on a bare `Cryst` is identity (no structure ref); + `Manager::GetTMatrix` is the live symmetry path. +- `PutPDBString`, `InitMatType`, `SetFlag` are no-ops (behaviour is fixed by the + gemmi reader/writer). + +--- + +## 10. Build and test + +- **Standalone suite** (seconds): `bash mmdb-shim/build.sh` — compiles the + `test/*.cc` against the shim (core, hierarchy, UDData, selection, contacts, + I/O, audit, leaf integration, rewriter) plus a macro-off real-MMDB coexistence + check. +- **Static lib**: `bash mmdb-shim/build-shimlib.sh` → `lib/libmmdbshim.a` + (rebuild only when `src/*.cc` change; header-only edits don't need it). +- **Full Coot** (the real integration test): `cd ~/lmb/build-coot-mmdb-shim && + cmake --build . -j6` (never bare `-j`). Reaches 100% building libcootapi, the + CLI tools, `test-molecules-container`, and the `coot_headless_api` python + module. diff --git a/mmdb-shim/include/mmdb2/_shim_hierarchy.hh b/mmdb-shim/include/mmdb2/_shim_hierarchy.hh new file mode 100644 index 0000000000..27ccf45dd2 --- /dev/null +++ b/mmdb-shim/include/mmdb2/_shim_hierarchy.hh @@ -0,0 +1,612 @@ +// mmdb-shim — layer 2 of 4: the coordinate hierarchy (Atom / Residue / Chain / +// Model). +// +// These classes ARE the stable wrapper nodes: each holds Manager* + parent* + a +// cached sibling index, resolves to the live gemmi object via g(), and exposes its +// children as a canonical vector that doubles as the identity cache AND the +// PPAtom/PPResidue table MMDB hands back. A wrapper with no parent is "detached" +// and backs onto a wrapper-owned _local gemmi object until Add*() adopts it. +// +// Only class definitions live here; method bodies that need a complete Manager (or +// sibling class) are declared here and defined out-of-line in _shim_inline.hh. +#pragma once + +#include "_shim_types.hh" + +namespace mmdb { + + // =========================================================================== + class Atom : public UDStore { + public: + Manager *mgr = nullptr; + Residue *res = nullptr; // parent; null => detached (use _local) + int ai = 0; // cached index within parent residue's atoms + bool alive = true; + gemmi::Atom _local; // backing store while detached (see g() resolvers) + int Het = 0; // heteroatom flag (MMDB public field; Coot sets it) + int Ter = 0; // chain-terminator flag (gemmi has none -> always 0) + word WhatIsSet = 0; // ASET_* mask; ASET_Anis_tFac set on load if aniso present + AtomName label_atom_id{}; // mmcif label_atom_id (shim-owned; Coot sets on build) + + Atom() = default; + explicit Atom(Residue *r); // construct + add to residue (out-of-line) + // MMDB owns atoms via `new`/`delete`: Coot writes `delete atom;` to remove an + // atom from the hierarchy (coot-molecule.cc et al.). So atoms are individually + // heap-allocated (Manager::newAtom) and tracked in Manager::_atom_allocs; this + // destructor detaches from the parent residue + flat lists + selections when a + // live atom is deleted, and is a no-op during Manager teardown (_bulk_free). + ~Atom(); // out-of-line (needs complete Manager/Residue) + + gemmi::Atom &g() const; // resolve to live gemmi (defined after Manager) + + // --- rewritten field accessors (pure B) --- + // Scalar fields -> reference-returning accessors, so a uniform `->field`-> + // `->field()` rewrite covers both reads and writes. (occ/b_iso/charge are + // narrower than realtype in gemmi, so those refs are float/schar-typed — the + // rare take-address-of-realtype sites surface at Coot build time.) + // non-const (writable ref) + const (by value) overloads, so reads work on a + // `const mmdb::Atom` and writes work through `->x() = v` on a non-const one. + realtype &x() { return g().pos.x; } + realtype x() const { return g().pos.x; } + realtype &y() { return g().pos.y; } + realtype y() const { return g().pos.y; } + realtype &z() { return g().pos.z; } + realtype z() const { return g().pos.z; } + float &occupancy() { return g().occ; } + float occupancy() const { return g().occ; } + float &tempFactor() { return g().b_iso; } + float tempFactor() const { return g().b_iso; } + signed char &charge() { return g().charge; } + signed char charge() const { return g().charge; } + int &serNum() { return g().serial; } + int serNum() const { return g().serial; } + // altLoc is a char[] (C-string) in MMDB; gemmi stores a single char. Return a + // buffer-backed C-string ("" when unset) so strcmp/strcpy-style code works. + // The non-const overload returns a WRITABLE buffer so `strncpy(at->altLoc(),..)` + // compiles; the buffer's first char is pushed back into gemmi by Residue::AddAtom + // (the buffer is refreshed from gemmi on entry, so reads stay correct). + pstr altLoc() { + _altloc_buf[0] = g().altloc; + _altloc_buf[1] = '\0'; + return _altloc_buf; + } + const char *altLoc() const { + _altloc_buf[0] = g().altloc; + _altloc_buf[1] = '\0'; + return _altloc_buf; + } + void set_occupancy(realtype v) { g().occ = (float)v; } + void set_tempFactor(realtype v) { g().b_iso = (float)v; } + void set_altLoc(char c) { g().altloc = c; } + void SetCharge(realtype ch) { g().charge = (signed char)ch; } + // coordinate/occupancy/B ESDs (MMDB public fields) — gemmi has none, so shim- + // owned; reference-returning so the rewritten `->sigX` covers reads and writes. + float &sigX() { return _sigx; } + float &sigY() { return _sigy; } + float &sigZ() { return _sigz; } + float &sigOcc() { return _sigocc; } + float &sigTemp() { return _sigtemp; } + bool isMetal() const { return gemmi::Element(g().element).is_metal(); } + // anisotropic B tensor — gemmi's SMat33 aniso. Reference-returning so the + // rewritten `->u11` covers both reads and writes. The mutable accessor marks the + // tensor present (ASET_Anis_tFac) so a write (e.g. SHELX import) sets the flag as + // real MMDB does. Const reads never set it; a non-const read over-approximates, + // which is harmless — the PDB/mmCIF writer emits ANISOU on the actual values. + float &u11() { + WhatIsSet |= ASET_Anis_tFac; + return g().aniso.u11; + } + float &u22() { + WhatIsSet |= ASET_Anis_tFac; + return g().aniso.u22; + } + float &u33() { + WhatIsSet |= ASET_Anis_tFac; + return g().aniso.u33; + } + float &u12() { + WhatIsSet |= ASET_Anis_tFac; + return g().aniso.u12; + } + float &u13() { + WhatIsSet |= ASET_Anis_tFac; + return g().aniso.u13; + } + float &u23() { + WhatIsSet |= ASET_Anis_tFac; + return g().aniso.u23; + } + float u11() const { return g().aniso.u11; } + float u22() const { return g().aniso.u22; } + float u33() const { return g().aniso.u33; } + float u12() const { return g().aniso.u12; } + float u13() const { return g().aniso.u13; } + float u23() const { return g().aniso.u23; } + // bonds — not modelled yet (gemmi connections); report none. + int GetNBonds() { return 0; } + void GetBonds(PAtomBond &atomBond, int &n) { + atomBond = nullptr; + n = 0; + } + int AddBond(PAtom /*a*/, int /*order*/, int /*nAdd*/ = 1) { return 0; } + SegID segID{}; // shim-owned (gemmi has no segID); MMDB public char[] field + + // --- method surface (hot subset; rest stubbed) --- + pstr GetAtomName() const; // aligned name, MMDB semantics (const: called on const Atom) + void SetAtomName(const AtomName aName); + pstr GetElementName(); + void SetElementName(const Element elName); + pstr GetChainID(); + int GetSeqNum(); + pstr GetInsCode(); + pstr GetResName(); + Residue *&GetResidue() { return res; } // ref: rewritten `->residue` is assignable + void SetResidue(Residue *r) { res = r; } + Chain *GetChain(); // out-of-line (needs complete Residue/Chain) + Model *GetModel(); // out-of-line + int GetModelNum(); + // residue-delegating accessors (bound by the Python API); out-of-line. + pstr GetLabelCompID(); + pstr GetLabelAsymID(); + int GetLabelSeqID(); + int GetLabelEntityID(); + int GetResidueNo(); + int GetSSEType(); + bool isSolvent(); + bool isNTerminus(); + bool isCTerminus(); + bool isTer() const { return false; } // gemmi has no TER atoms; see notes + void SetCoordinates(realtype xx, realtype yy, realtype zz, + realtype occ, realtype tF); + int GetIndex(); + void MakeTer() { Ter = 1; } // mark as chain terminator + pstr GetAtomID(pstr S); // "/mdl/chain/seq(res).ins/name[elem]:alt" (out-of-line) + int GetUDData(int h, pstr &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } + // copy another atom's data into this one (mmdb Atom::Copy — no hierarchy refs) + void Copy(PAtom a) { + g() = a->g(); + Het = a->Het; + WhatIsSet = a->WhatIsSet; + std::memcpy(segID, a->segID, sizeof segID); + } + // apply a 4x4 (rot+trans) or 3x3+vec to the coordinates (mmdb Atom::Transform) + void Transform(const mat44 &tm) { + gemmi::Position &p = g().pos; + double x = p.x, y = p.y, z = p.z; + p.x = tm[0][0] * x + tm[0][1] * y + tm[0][2] * z + tm[0][3]; + p.y = tm[1][0] * x + tm[1][1] * y + tm[1][2] * z + tm[1][3]; + p.z = tm[2][0] * x + tm[2][1] * y + tm[2][2] * z + tm[2][3]; + } + void Transform(const mat33 &tm, vect3 &v) { + gemmi::Position &p = g().pos; + double x = p.x, y = p.y, z = p.z; + p.x = tm[0][0] * x + tm[0][1] * y + tm[0][2] * z + v[0]; + p.y = tm[1][0] * x + tm[1][1] * y + tm[1][2] * z + v[1]; + p.z = tm[2][0] * x + tm[2][1] * y + tm[2][2] * z + v[2]; + } + // UDData + int PutUDData(int h, int v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } + int PutUDData(int h, realtype v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } + int PutUDData(int h, cpstr v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } + int GetUDData(int h, int &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } + int GetUDData(int h, realtype &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } + + private: + friend class Residue; // AddAtom pushes the strncpy'd altLoc buffer to gemmi + mutable AtomName _name_buf{}; + Element _elem_buf{}; + mutable char _altloc_buf[4]{}; + float _sigx = 0, _sigy = 0, _sigz = 0, _sigocc = 0, _sigtemp = 0; + }; + + // =========================================================================== + class Residue : public UDStore { + public: + Manager *mgr = nullptr; + Chain *chain = nullptr; // parent; null => detached (use _local) + int ri = 0; + bool alive = true; + gemmi::Residue _local; // backing store while detached + std::vector atoms; // canonical child wrappers == PPAtom table + PPAtom atom = nullptr; // MMDB public atom-table field; kept = atoms.data() + int nAtoms = 0; // MMDB public field; kept = atoms.size() + void _sync_atom() { + atom = atoms.data(); + nAtoms = (int)atoms.size(); + } + // mmcif label_* (shim-owned; Coot sets when building dictionary residues) + ResName label_comp_id{}; + ChainID label_asym_id{}; + int label_seq_id = 0, label_entity_id = 0; + pstr GetLabelCompID() { return label_comp_id; } + pstr GetLabelAsymID() { return label_asym_id; } + int GetLabelSeqID() { return label_seq_id; } + int GetLabelEntityID() { return label_entity_id; } + int GetResidueNo() { return ri; } // 0-based index within its chain + int GetNofAltLocations() { // distinct non-blank altLocs + std::set a; + for (Atom *at : atoms) { + char c = at->g().altloc; + if (c && c != ' ') a.insert(c); + } + return a.empty() ? 1 : (int)a.size(); + } + // sugar / modified-residue classification via gemmi's tabulated residues. + bool isSugar() { + gemmi::ResidueKind k = gemmi::find_tabulated_residue(g().name).kind; + return k == gemmi::ResidueKind::PYR || k == gemmi::ResidueKind::KET; + } + // MMDB isModRes reflects PDB MODRES records (a non-standard, modified form of a + // standard residue). gemmi has no per-residue MODRES flag on the model tree, so + // approximate: an amino/nucleic residue whose one-letter code is lower-case + // (gemmi marks non-standard monomers that way). Water/ligands are excluded. + bool isModRes() { + const gemmi::ResidueInfo ri = gemmi::find_tabulated_residue(g().name); + return ri.found() && !ri.is_standard() && + (ri.is_amino_acid() || ri.is_nucleic_acid()); + } + + Residue() = default; + explicit Residue(Chain *c); // construct + add to chain (out-of-line) + // MMDB owns residues via `new`/`delete` (Coot writes `delete residue_p;`). Like + // ~Atom, this frees the residue's atoms, then DEFERS structural removal: it nulls + // this residue's slot in the parent chain (a tombstone) but leaves the gemmi + // placeholder residue in place so siblings' `ri` stays valid — _compact_residues + // drops both later. No-op during Manager teardown (_bulk_free). + ~Residue(); // out-of-line (needs complete Manager/Chain) + + // MMDB public char-array fields. Coot reads `residue->name` and writes + // `strncpy(residue->insCode,..)`. Kept as the interface: synced gemmi->buffer on + // load (_load_id, in build_from_gemmi) and buffer->gemmi at the adopt point + // (_store_id, in Chain::Add/InsResidue). SetResName/SetResID keep both in step. + ResName name{}; + InsCode insCode{}; + void _load_id() { + std::snprintf(name, sizeof name, "%s", g().name.c_str()); + insCode[0] = g().seqid.icode && g().seqid.icode != ' ' ? g().seqid.icode : '\0'; + insCode[1] = '\0'; + } + void _store_id() { + g().name = name; + g().seqid.icode = insCode[0] ? insCode[0] : ' '; + } + + gemmi::Residue &g() const; + + int GetNumberOfAtoms() { return (int)atoms.size(); } + int GetNumberOfAtoms(bool /*countTers*/) { return (int)atoms.size(); } + PAtom GetAtom(int atomNo) { + return (atomNo >= 0 && atomNo < (int)atoms.size()) ? atoms[atomNo] : nullptr; + } + PAtom GetAtom(const AtomName aname, const Element elname = nullptr, + const AltLoc aloc = nullptr); + void GetAtomTable(PPAtom &atomTable, int &n) { + atomTable = atoms.data(); + n = (int)atoms.size(); + } + PAtom AddAtom(Manager &m, gemmi::Atom a); // append: O(1) + // Adopt a detached atom (Coot's `new mmdb::Atom` idiom). Copies the atom's + // local gemmi into this residue's gemmi (detached or bound, via g()) and + // rebinds the wrapper. Pushes the strncpy'd altLoc buffer back into gemmi. + int AddAtom(PAtom atm); // out-of-line: needs complete Manager (_atom_allocs) + void DeleteAtom(int pos); + void _detach_atom(Atom *a); // unlink (no free); used by ~Atom on Coot `delete atom` + void TrimAtomTable() {} // compact after deletions — shim keeps them in sync + + pstr GetResName(); + void SetResName(const ResName n) { + g().name = n ? n : ""; + std::snprintf(name, sizeof name, "%s", n ? n : ""); + } + void SetResID(const ResName resName, int seqNo, const InsCode ic) { + g().name = resName ? resName : ""; + g().seqid.num.value = seqNo; + g().seqid.icode = (ic && ic[0]) ? ic[0] : ' '; + std::snprintf(name, sizeof name, "%s", resName ? resName : ""); + insCode[0] = (ic && ic[0]) ? ic[0] : '\0'; + insCode[1] = '\0'; + } + int &GetSeqNum(); // writable (rewrite maps `->seqNum` reads and writes) + pstr GetInsCode(); + pstr GetChainID(); + int GetModelNum(); + int &GetIndex() { return ri; } // ref: rewritten `->index` is assignable + Chain *GetChain() { return chain; } + Model *GetModel(); // out-of-line (Chain incomplete here) + // terminus tests — peptide-bond-aware: N-terminus if no preceding residue's C is + // within bonding distance of this N, C-terminus if this C bonds no following N + // (out-of-line: need Chain + backbone atom geometry). + bool isNTerminus(); + bool isCTerminus(); + pstr GetResidueID(pstr S) { // "seqnum(name):inscode" + if (S) std::snprintf(S, 100, "%d(%s):%s", GetSeqNum(), name, insCode); + return S; + } + Residue *next = nullptr; // MMDB has this; wired lazily if needed + int SSE = SSE_None; // secondary-structure element (shim-owned public field) + bool isAminoacid() { return gemmi::find_tabulated_residue(g().name).is_amino_acid(); } + bool isNucleotide() { return gemmi::find_tabulated_residue(g().name).is_nucleic_acid(); } + bool isDNARNA() { return isNucleotide(); } + bool isSolvent() { return gemmi::find_tabulated_residue(g().name).is_water(); } + // UDData + int PutUDData(int h, int v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } + int PutUDData(int h, realtype v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } + int PutUDData(int h, cpstr v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } + int GetUDData(int h, int &v) { return ud_get(mgr, UDR_RESIDUE, *this, h, v); } + int GetUDData(int h, realtype &v) { return ud_get(mgr, UDR_RESIDUE, *this, h, v); } + + private: + ResName _resname_buf{}; + InsCode _inscode_buf{}; + }; + + // =========================================================================== + class Chain : public UDStore { + public: + Manager *mgr = nullptr; + Model *model = nullptr; // parent; null => detached (use _local) + int ci = 0; + bool alive = true; + gemmi::Chain _local; // backing store while detached + std::vector residues; + + gemmi::Chain &g() const; + + int GetNumberOfResidues() { return (int)residues.size(); } + PResidue GetResidue(int resNo) { + return (resNo >= 0 && resNo < (int)residues.size()) ? residues[resNo] : nullptr; + } + // find by (seqNum, insCode) — MMDB's 2-arg overload. Skips deferred-delete + // tombstone (null) slots. + PResidue GetResidue(int seqNum, const InsCode insCode) { + char ic = (insCode && insCode[0]) ? insCode[0] : ' '; + for (Residue *r : residues) { + if (!r) continue; // tombstone + gemmi::Residue &gr = r->g(); + char ric = gr.seqid.icode ? gr.seqid.icode : ' '; + if (gr.seqid.num.value == seqNum && ric == ic) return r; + } + return nullptr; + } + void GetResidueTable(PPResidue &t, int &n) { + t = residues.data(); + n = (int)residues.size(); + } + // MMDB DeleteResidue is DEFERRED: it frees the residue and leaves a NULL slot + // (nResidues unchanged) until TrimResidueTable/FinishStructEdit. `delete residue` + // (via ~Residue) does the same. Coot relies on this (e.g. change_chain_id iterates + // to the original count while deleting). We keep the gemmi placeholder residue too + // so surviving residues' `ri` stays aligned; _compact_residues() drops both later. + void DeleteResidue(int resNo) { + if (resNo < 0 || resNo >= (int)residues.size()) return; + if (residues[resNo]) delete residues[resNo]; // ~Residue nulls the slot + } + void DeleteResidue(int seqNum, const InsCode ic) { // by (seqNum, insCode) + PResidue r = GetResidue(seqNum, ic); + if (r) delete r; // ~Residue nulls its slot; keeps the gemmi placeholder + } + void TrimResidueTable() { _compact_residues(); } + // Drop tombstoned (null) residue slots and their gemmi placeholder residues in + // lock-step, then reindex ri. Out-of-line: needs a complete Residue. + void _compact_residues(); + pstr GetChainID(); + pstr GetChainID(pstr buf) { + if (buf) std::snprintf(buf, sizeof(ChainID), "%s", g().name.c_str()); + return buf; + } + Manager *GetCoordHierarchy() { return mgr; } // parent manager + void SetChainID(const ChainID id) { g().name = id ? id : ""; } + Chain() = default; + Chain(Model *m, const ChainID id); // construct + add to model (out-of-line) + void Copy(PChain src); // deep-copy subtree (out-of-line: needs Manager) + // Reorder residues (and their gemmi backing) ascending by (seqNum, insCode), + // MMDB's default. Keeps the wrapper vector and gemmi vector in lock-step and + // re-indexes ri. sortKey variants beyond ascending-by-number are uncommon in + // Coot and treated as the default. + void SortResidues(int /*sortKey*/ = 0) { + _compact_residues(); // never sort across deferred-delete tombstones + int n = (int)residues.size(); + if (n < 2) return; + std::vector ord(n); + for (int i = 0; i < n; ++i) ord[i] = i; + gemmi::Chain &gc = g(); + std::stable_sort(ord.begin(), ord.end(), [&](int a, int b) { + const gemmi::Residue &ra = gc.residues[a], &rb = gc.residues[b]; + if (ra.seqid.num.value != rb.seqid.num.value) return ra.seqid.num.value < rb.seqid.num.value; + char ia = ra.seqid.icode ? ra.seqid.icode : ' ', ib = rb.seqid.icode ? rb.seqid.icode : ' '; + return ia < ib; + }); + std::vector gnew; + gnew.reserve(n); + std::vector wnew; + wnew.reserve(n); + for (int k = 0; k < n; ++k) { + gnew.push_back(std::move(gc.residues[ord[k]])); + wnew.push_back(residues[ord[k]]); + } + gc.residues = std::move(gnew); + residues = std::move(wnew); + for (int k = 0; k < n; ++k) residues[k]->ri = k; + } + bool isAminoacidChain(); // defined out-of-line (needs Residue predicates) + bool isNucleotideChain(); + bool isSolventChain(); + PResidue AddResidue(Manager &m, gemmi::Residue r); // append + PResidue InsResidue(Manager &m, int pos, gemmi::Residue r); + // Adopt a detached residue (its atom wrappers already point at it, so they + // ride along once its gemmi is copied in and the wrapper is rebound). + int AddResidue(PResidue res) { + res->_store_id(); // push name/insCode buffers into gemmi + g().residues.push_back(res->g()); // res detached -> its _local (with atoms) + res->chain = this; + res->mgr = mgr; + res->ri = (int)residues.size(); + residues.push_back(res); + return 0; + } + int InsResidue(PResidue res, int pos) { + _compact_residues(); // don't insert/reindex across tombstones + if (pos < 0) pos = 0; + if (pos > (int)residues.size()) pos = (int)residues.size(); + res->_store_id(); + g().residues.insert(g().residues.begin() + pos, res->g()); + res->chain = this; + res->mgr = mgr; + res->ri = pos; + residues.insert(residues.begin() + pos, res); + for (int k = pos + 1; k < (int)residues.size(); ++k) residues[k]->ri = k; + return 0; + } + + private: + ChainID _chainid_buf{}; + }; + + // =========================================================================== + class Model : public UDStore { + public: + Manager *mgr = nullptr; // null => detached (use _local) + int mi = 0; // 0-based internal; GetModel is 1-based externally + gemmi::Model _local{1}; // backing store while detached (gemmi Model num is int) + std::vector chains; + + gemmi::Model &g() const; + + int GetNumberOfChains() { return (int)chains.size(); } + PChain GetChain(int chainNo) { + return (chainNo >= 0 && chainNo < (int)chains.size()) ? chains[chainNo] : nullptr; + } + PChain GetChain(const ChainID chID); + // Adopt a detached chain (Coot's `new mmdb::Chain` idiom): copy its local + // gemmi (with any residues/atoms) into this model and rebind, cascading mgr + // to the sub-tree that was built while detached (mgr was null). + int AddChain(PChain chn) { + g().chains.push_back(chn->g()); + chn->model = this; + chn->mgr = mgr; + chn->ci = (int)chains.size(); + chains.push_back(chn); + for (Residue *r : chn->residues) { + r->mgr = mgr; + for (Atom *a : r->atoms) a->mgr = mgr; + } + return 0; + } + int GetSerNum() { return mi + 1; } + // delete chain at index: erase gemmi + wrapper, reindex the tail + void DeleteChain(int chainNo) { + if (chainNo < 0 || chainNo >= (int)chains.size()) return; + g().chains.erase(g().chains.begin() + chainNo); + chains.erase(chains.begin() + chainNo); + for (int k = chainNo; k < (int)chains.size(); ++k) chains[k]->ci = k; + } + void DeleteChain(const ChainID chainID) { + for (int i = 0; i < (int)chains.size(); ++i) + if (chains[i]->g().name == (chainID ? chainID : "")) { + DeleteChain(i); + return; + } + } + void GetChainTable(PPChain &t, int &n) { + t = chains.data(); + n = (int)chains.size(); + } + std::vector all_atoms; // flat, filled by build_from_gemmi + PPAtom GetAllAtoms() { return all_atoms.data(); } + int GetNumberOfAtoms() { return (int)all_atoms.size(); } + int GetNumberOfAtoms(bool /*countTers*/) { return (int)all_atoms.size(); } + // Secondary-structure assignment: mocked. gemmi's DSSP has its SS prediction + // disabled upstream ("commented out ... wasn't correct anyway"), so there is no + // gemmi-backed SS to forward to. Return the non-OK code so callers treat SS as + // unavailable rather than trusting a bogus assignment. (residue SSE stays None.) + int CalcSecStructure(bool /*flag*/) { return SSERC_noResidues; } + // LINK records — gemmi-loaded (Manager::_load_metadata) plus Coot-created ones + // (AddLink) stored here; GetLink is 1-based like MMDB. + std::vector _links; + int GetNumberOfLinks() { return (int)_links.size(); } + PLink GetLink(int i) { return (i >= 1 && i <= (int)_links.size()) ? _links[i - 1] : nullptr; } + void AddLink(PLink link) { + if (link) _links.push_back(link); + } + // Refmac LINKR records — gemmi Connections that carry a link_id (_load_metadata). + std::vector _linkrs; + int GetNumberOfLinkRs() { return (int)_linkrs.size(); } + PLinkR GetLinkR(int i) { return (i >= 1 && i <= (int)_linkrs.size()) ? _linkrs[i - 1] : nullptr; } + void AddLinkR(PLinkR lr) { + if (lr) _linkrs.push_back(lr); + } + std::vector _cispeps; + int GetNumberOfCisPeps() { return (int)_cispeps.size(); } + PCisPep GetCisPep(int i) { return (i >= 1 && i <= (int)_cispeps.size()) ? _cispeps[i - 1] : nullptr; } + void AddCisPep(PCisPep cp) { + if (cp) _cispeps.push_back(cp); + } + void RemoveCisPeps() { _cispeps.clear(); } + // secondary structure. Records live in `helices`/`sheets` below, populated + // either from gemmi on load (build_from_gemmi) or by Coot's own SS computation + // via the access_model subclass (which reaches these public members directly). + // 1-based indexing to match MMDB. + int GetNumberOfHelices() { return (int)helices.data.size(); } + PHelix GetHelix(int i) { return (i >= 1 && i <= (int)helices.data.size()) ? helices.data[i - 1] : nullptr; } + int GetNumberOfSheets() { return sheets.nSheets; } + PSheet GetSheet(int i) { return (i >= 1 && i <= sheets.nSheets && sheets.sheet) ? sheets.sheet[i - 1] : nullptr; } + Sheets sheets; // SS records (gemmi-backed on load; access_model fills) + Helices helices; // " " " + std::vector _sheet_ptrs; // backing array for sheets.sheet (gemmi load) + PSheets GetSheets() { return &sheets; } + int GetModelID() { return mi + 1; } + pstr GetModelID(pstr buf) { + if (buf) std::snprintf(buf, 16, "%d", mi + 1); + return buf; + } + int CalcSecStructure(int /*flag*/, int /*selHnd*/) { return SSERC_noResidues; } // mocked; see bool overload + void Copy(PModel src); // deep-copy subtree (out-of-line) + Manager *GetCoordHierarchy() { return mgr; } // parent manager + int GetNumberOfResidues() { + int n = 0; + for (Chain *c : chains) n += c->GetNumberOfResidues(); + return n; + } + LinkContainer _linkc; + PLinkContainer GetLinks() { + _linkc.data.assign(_links.begin(), _links.end()); + return &_linkc; + } + void RemoveLinks() { _links.clear(); } + // Reorder chains (and gemmi backing) by chain ID. sortKey selects ascending + // (default) or descending; other MMDB sort keys collapse to ID order. + void SortChains(int sortKey = 0) { + int n = (int)chains.size(); + if (n < 2) return; + bool desc = (sortKey == SORT_CHAIN_ChainID_Desc); + std::vector ord(n); + for (int i = 0; i < n; ++i) ord[i] = i; + gemmi::Model &gm = g(); + std::stable_sort(ord.begin(), ord.end(), [&](int a, int b) { + return desc ? (gm.chains[a].name > gm.chains[b].name) + : (gm.chains[a].name < gm.chains[b].name); + }); + std::vector gnew; + gnew.reserve(n); + std::vector wnew; + wnew.reserve(n); + for (int k = 0; k < n; ++k) { + gnew.push_back(std::move(gm.chains[ord[k]])); + wnew.push_back(chains[ord[k]]); + } + gm.chains = std::move(gnew); + chains = std::move(wnew); + for (int k = 0; k < n; ++k) chains[k]->ci = k; + } + PChain CreateChain(const ChainID id); // add empty chain (out-of-line: needs Manager) + int GetNumberOfStrands(int sheetNo) { + PSheet s = GetSheet(sheetNo); + return s ? s->nStrands : 0; + } + PStrand GetStrand(int sheetNo, int strandNo) { + PSheet s = GetSheet(sheetNo); + return (s && strandNo >= 1 && strandNo <= s->nStrands && s->strand) ? s->strand[strandNo - 1] : nullptr; + } + }; + +} // namespace mmdb diff --git a/mmdb-shim/include/mmdb2/_shim_impl.hh b/mmdb-shim/include/mmdb2/_shim_impl.hh index 211f086660..789877652c 100644 --- a/mmdb-shim/include/mmdb2/_shim_impl.hh +++ b/mmdb-shim/include/mmdb2/_shim_impl.hh @@ -1,2682 +1,36 @@ -// mmdb-shim — architecture B implementation header (single unit; sub-headers -// below are thin macro-guarded wrappers around this). See MMDB_SHIM_Recon_and_Plan.md. +// mmdb-shim — architecture B implementation umbrella. Every public mmdb2/*.h +// wrapper resolves here (when COOT_USE_MMDB_SHIM is defined); this file just +// stitches the implementation layers together. See MMDB_SHIM_Recon_and_Plan.md. // -// The mmdb:: hierarchy classes ARE the stable wrapper nodes from the hardened -// core (mmdb-recon/spike -> mmdb-shim/core): each holds Manager* + parent* + a -// cached sibling index, resolves to live gemmi via g(), and exposes children as -// a canonical vector (= the identity cache AND the PPAtom/PPResidue table). +// The shim presents MMDB's API but is backed by a live gemmi::Structure. The +// mmdb:: hierarchy classes are stable wrapper nodes over that structure (each holds +// Manager* + parent* + a cached sibling index, resolves to gemmi via g(), and +// exposes children as a vector that is both the identity cache and the +// PPAtom/PPResidue table). Field access is via accessors: numeric -> +// reference-returning x()/…; float occ/b_iso -> value get + set_*; char[] -> pstr +// getter + set_*. gemmi is used at the boundaries (I/O, symmetry, neighbour search) +// and the shim hand-implements only what gemmi lacks (UDData slots, the +// selection-handle engine, the stable-pointer wrapper tree, subgraph matching). // -// Field access is via accessors (pure B): numeric -> reference-returning x()/...; -// float occ/b_iso -> value get + set_*; char[] -> pstr getter + set_*. +// The implementation is split into four dependency-ordered layers (each opens its +// own `namespace mmdb`); this file must include them in order: +// 1. _shim_types.hh — typedefs, enums, UDStore, forward decls, record classes +// 2. _shim_hierarchy.hh — Atom / Residue / Chain / Model class definitions +// 3. _shim_manager.hh — Manager (+ nested Selection / UDReg) +// 4. _shim_inline.hh — g() resolvers, UDData helpers, out-of-line method bodies, +// the detail:: selection matchers, and free functions +// then the two sibling subsystems that build on the completed hierarchy. #pragma once -#include -#include // trim_str — normalise MMDB-padded names to gemmi's trimmed form -#include -#include // space-group / symmetry operators - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace mmdb { - - // ---- basic MMDB scalar/typedefs (real MMDB: mmdb_mattype.h / mmdb_defs.h) ---- - typedef double realtype; - typedef char *pstr; - typedef const char *cpstr; - typedef unsigned short word; - typedef char AtomName[20]; - typedef char ResName[20]; - typedef char InsCode[10]; - typedef char ChainID[10]; - typedef char Element[10]; - typedef char AltLoc[20]; - typedef char SegID[10]; - typedef char LinkRID[20]; // Refmac link ID - typedef unsigned char byte; // mmdb_mattype.h - typedef int *ivector; // mmdb_mattype.h 1-based vectors/matrices - typedef realtype *rvector; - typedef ivector *imatrix; - typedef rvector *rmatrix; - typedef char maxMMDBName[40]; - - // WhatIsSet mask flags (mmdb_atom.h ASET_FLAG) - enum ASET_FLAG { - ASET_Coordinates = 0x00000001, - ASET_Occupancy = 0x00000002, - ASET_tempFactor = 0x00000004, - ASET_CoordSigma = 0x00000010, - ASET_OccSigma = 0x00000020, - ASET_tFacSigma = 0x00000040, - ASET_Charge = 0x00000080, - ASET_Anis_tFac = 0x00000100, - ASET_Anis_tFSigma = 0x00001000, - ASET_All = 0x000FFFFF - }; - - // vector/matrix types (mmdb_defs.h) — plain fixed-size arrays of realtype - typedef realtype vect3[3]; - typedef realtype vect4[4]; - typedef vect3 mat33[3]; // realtype[3][3] - typedef vect4 mat44[4]; // realtype[4][4] - typedef mat44 *pmat44; - typedef mat44 &rmat44; - - enum ERROR_CODE { - Error_NoError = 0, - Error_CantOpenFile = 12, // matches real MMDB's value - Error_GeneralError1 = 1 - }; - - // ---- UDData (user-defined data) — real MMDB values (mmdb_uddata.h) ---- - enum UDR_TYPE { UDR_ATOM = 0, - UDR_RESIDUE = 1, - UDR_CHAIN = 2, - UDR_MODEL = 3, - UDR_HIERARCHY = 4 }; - enum UDDATA_CODE { UDDATA_Ok = 0, - UDDATA_WrongHandle = -1, - UDDATA_WrongUDRType = -2, - UDDATA_NoData = -3 }; - - // ---- Selection (real MMDB values: mmdb_selmngr.h) ---- - enum SELECTION_TYPE { STYPE_INVALID = -1, - STYPE_UNDEFINED = 0, - STYPE_ATOM = 1, - STYPE_RESIDUE = 2, - STYPE_CHAIN = 3, - STYPE_MODEL = 4 }; - enum SELECTION_KEY { SKEY_NEW = 0, - SKEY_OR = 1, - SKEY_AND = 2, - SKEY_XOR = 3, - SKEY_CLR = 4, - SKEY_XAND = 100 }; - inline const long int MinInt4 = -2147483647; - inline const long int MaxInt4 = 2147483647; - inline const int ANY_RES = -2147483647; // real MMDB: extern const == MinInt4 - inline const double Pi = 3.14159265358979323846; - - // PDB/CIF read flags (mmdb_io_file.h). Values are arbitrary distinct bits — the - // shim's SetFlag is a no-op, so only distinctness matters for Coot's bit ops. - enum MMDB_READ_FLAG { - MMDBF_AutoSerials = 0x00000001, - MMDBF_IgnoreDuplSeqNum = 0x00000002, - MMDBF_IgnoreBlankLines = 0x00000004, - MMDBF_IgnoreRemarks = 0x00000008, - MMDBF_IgnoreHash = 0x00000010, - MMDBF_IgnoreNonCoorPDBErrors = 0x00000020, - MMDBF_PrintCIFWarnings = 0x00000040, - MMDBF_All = 0x0000FFFF - }; - enum MMDB_FCM { MMDBFCM_None = 0, - MMDBFCM_All = 1, - MMDBFCM_Coord = 2, - MMDBFCM_Cryst = 4, - MMDBFCM_SC = 8 }; - typedef int COPY_MASK; // Coot uses `COPY_MASK cm = MMDBFCM_All` + bit arithmetic - - // Per-object UDData slots + selection membership bits. Each registered UDData - // handle maps to a (type,kind,slot); the object stores contiguous vectors - // indexed by slot. `_inSel[selHnd-1]` = is this object in selection selHnd - // (maintained by Manager::Select/SelectSphere/DeleteSelection). - struct UDStore { - std::vector _udi; - std::vector _udr; - std::vector _uds; - std::vector _inSel; - bool isInSelection(int selHnd) const { - return selHnd >= 1 && selHnd <= (int)_inSel.size() && _inSel[selHnd - 1]; - } - void _setInSel(int selHnd, bool v) { - if ((int)_inSel.size() < selHnd) _inSel.resize(selHnd, false); - _inSel[selHnd - 1] = v; - } - }; - - class Atom; - class Residue; - class Chain; - class Model; - class Manager; - typedef Atom *PAtom; - typedef Atom **PPAtom; - typedef Residue *PResidue; - typedef Residue **PPResidue; - typedef Chain *PChain; - typedef Chain **PPChain; - typedef Model *PModel; - typedef Model **PPModel; - typedef Manager *PManager; - typedef Manager **PPManager; - - struct Contact { - int id1, id2; - long group; - realtype dist; - }; - typedef Contact *PContact; - - // base for records held in MMDB containers (Title compound/author, LINK, …) - class ContainerClass { - public: - virtual ~ContainerClass() {} - }; - typedef ContainerClass *PContainerClass; - - // LINK record. Public data members mirror real MMDB (Coot reads them directly). - // Populated from gemmi Structure::connections on load (Manager::_load_metadata); - // Coot-created links are appended via Model::AddLink. - class Link : public ContainerClass { - public: - AtomName atName1{}, atName2{}; - AltLoc aloc1{}, aloc2{}; - ResName resName1{}, resName2{}; - ChainID chainID1{}, chainID2{}; - InsCode insCode1{}, insCode2{}; - int seqNum1 = 0, seqNum2 = 0; - int s1 = 1, i1 = 0, j1 = 0, k1 = 0; // symmetry id of 1st atom - int s2 = 1, i2 = 0, j2 = 0, k2 = 0; // symmetry id of 2nd atom - realtype dist = 0; - void Copy(PContainerClass o) { - if (auto *l = dynamic_cast(o)) *this = *l; - } - }; - typedef Link *PLink; - typedef Link **PPLink; - - // Refmac LINK record (mmdb_model.h LinkR). Public members mirror real MMDB; - // populated from gemmi Connections carrying a link_id (Manager::_load_metadata). - class LinkR { - public: - LinkRID linkRID{}; - AtomName atName1{}, atName2{}; - AltLoc aloc1{}, aloc2{}; - ResName resName1{}, resName2{}; - ChainID chainID1{}, chainID2{}; - int seqNum1 = 0, seqNum2 = 0; - InsCode insCode1{}, insCode2{}; - realtype dist = 0; - }; - typedef LinkR *PLinkR; - typedef LinkR **PPLinkR; - - // CIS-peptide record (mmdb_model.h CisPep). Public members mirror real MMDB; - // populated from gemmi Structure::cispeps on load (Manager::_load_metadata). - class CisPep { - public: - int serNum = 0; - ResName pep1{}; - ChainID chainID1{}; - int seqNum1 = 0; - InsCode icode1{}; - ResName pep2{}; - ChainID chainID2{}; - int seqNum2 = 0; - InsCode icode2{}; - int modNum = 0; - realtype measure = 0; - }; - typedef CisPep *PCisPep; - - // Container of LINK records (mmdb_model.h LinkContainer). Minimal: Coot only - // declares `empty_links_container()` returning one by value; never dereferenced. - class LinkContainer { - public: - std::vector data; - int Length() { return (int)data.size(); } - PContainerClass GetContainerClass(int i) { return (i >= 0 && i < (int)data.size()) ? data[i] : nullptr; } - }; - typedef LinkContainer *PLinkContainer; - - // PDB title records (mmdb_title.h). Coot subclasses Manager & Title to reach the - // COMPND/AUTHOR line containers. The AUTHOR container is filled from gemmi - // meta.authors on load and the TITLE string comes from Structure::get_info - // ("_struct.title"); COMPND/JRNL have no structured gemmi home, so those - // containers stay empty. - class Compound : public ContainerClass { - public: - char Line[256] = {0}; - }; - typedef Compound *PCompound; - class Author : public ContainerClass { - public: - char Line[256] = {0}; - }; - typedef Author *PAuthor; - class Journal : public ContainerClass { - public: - char Line[256] = {0}; - }; - typedef Journal *PJournal; - class TitleContainer { - public: - std::vector data; - int Length() { return (int)data.size(); } - PContainerClass GetContainerClass(int i) { - return (i >= 0 && i < (int)data.size()) ? data[i] : nullptr; - } - }; - class Title { - public: - TitleContainer compound, author, journal; // public so Coot's access_title can reach them - TitleContainer *GetCompound() { return &compound; } // real Title exposes these - TitleContainer *GetAuthor() { return &author; } // publicly; access_title - TitleContainer *GetJournal() { return &journal; } // inherits GetJournal() - }; - - // gzip mode flag (mmdb_io_file.h). Minimal mmdb::io — the shim does I/O via gemmi, - // so only this compression-mode enum is provided (Coot passes it to write calls). - namespace io { - enum GZ_MODE { GZM_NONE = 0, - GZM_CHECK = 1, - GZM_ENFORCE = 2 }; - } - - // initialise a 4x4 matrix to identity (mmdb_mattype.h Mat4Init) - inline void Mat4Init(mat44 &A) { - for (int i = 0; i < 4; ++i) - for (int j = 0; j < 4; ++j) A[i][j] = (i == j) ? 1.0 : 0.0; - } - - // Orthogonal symmetry transformation for operator Nop (0-based) + integer cell - // shifts, from a gemmi cell + space group. The op acts in fractional space; we - // conjugate it with the cell frac<->orth transforms so TMatrix maps orthogonal - // coordinates directly (MMDB semantics). Returns 0 on success, 1 if there is no - // usable space group / the operator is out of range. Shared by Manager and Cryst. - inline int gemmi_sym_tmatrix(const gemmi::UnitCell &cell, const std::string &sg_name, - mat44 &TMatrix, int Nop, int a, int b, int c) { - Mat4Init(TMatrix); - const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(sg_name); - if (!sg || !cell.is_crystal()) return 1; - gemmi::GroupOps gops = sg->operations(); - if (Nop < 0 || Nop >= (int)gops.order()) return 1; - int i = 0; - gemmi::Op op; - for (gemmi::Op o : gops) { - if (i++ == Nop) { - op = o; - break; - } - } - gemmi::Transform sym{gemmi::rot_as_mat33(op), - gemmi::tran_as_vec3(op) + gemmi::Vec3(a, b, c)}; - gemmi::Transform t = cell.orth.combine(sym).combine(cell.frac); - for (int r = 0; r < 3; ++r) { - for (int cc = 0; cc < 3; ++cc) TMatrix[r][cc] = t.mat.a[r][cc]; - TMatrix[r][3] = t.vec.at(r); - } - return 0; - } - - // Crystal/symmetry record (mmdb_cryst.h). Holds a gemmi cell + space-group name - // and computes symmetry through the shared helper — same result as Manager for a - // populated Cryst (Manager is the usual live symmetry path). - class Cryst { - public: - gemmi::UnitCell cell; - std::string spaceGroup; - virtual ~Cryst() {} - int GetTMatrix(mat44 &T, int Nop, int a, int b, int c) { - return gemmi_sym_tmatrix(cell, spaceGroup, T, Nop, a, b, c); - } - int GetNumberOfSymOps() { - const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(spaceGroup); - return sg ? (int)sg->operations().order() : 0; - } - pstr GetSymOp(int Nop) { - const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(spaceGroup); - if (!sg) return nullptr; - int i = 0; - for (gemmi::Op op : sg->operations()) - if (i++ == Nop) { - _symop_buf = op.triplet(); - return (pstr)_symop_buf.c_str(); - } - return nullptr; - } - - private: - std::string _symop_buf; - }; - typedef Cryst *PCryst; - - // mmdb::math graph-matching subsystem — full classes defined in _graph_impl.hh - // (included at end of this file, after Atom/Residue are complete). Only the - // Alignment class (unused by the cootapi build) stays a forward decl. - namespace math { - class Alignment; - } - - struct AtomBond { - PAtom atom = nullptr; - int order = 0; - }; - typedef AtomBond *PAtomBond; - typedef AtomBond **PPAtomBond; - - struct AtomStat { // selection coordinate statistics (mmdb_atom.h) - int nAtoms = 0; - realtype xmin = 0, ymin = 0, zmin = 0, xmax = 0, ymax = 0, zmax = 0; - realtype xm = 0, ym = 0, zm = 0; // coordinate means (centroid) - realtype GetMaxSize() { - realtype dx = xmax - xmin, dy = ymax - ymin, dz = zmax - zmin; - return dx > dy ? (dx > dz ? dx : dz) : (dy > dz ? dy : dz); - } - }; - typedef AtomStat &RAtomStat; - - // secondary-structure element codes (mmdb_tables.h) - enum SSE_CODE { SSE_None = 0, - SSE_Strand = 1, - SSE_Bulge = 2, - SSE_3Turn = 3, - SSE_4Turn = 4, - SSE_5Turn = 5, - SSE_Helix = 6 }; - - // PDBCleanup flags (mmdb_root.h) — bit flags OR'd into PDBCleanup(word) - // misc return-code / sort-key enums (mmdb_cryst.h / mmdb_selmngr.h / mmdb_tables.h) - enum { SYMOP_Ok = 0, - SYMOP_NoLibFile = -1, - SYMOP_UnknownSpaceGroup = -2 }; - enum { SSERC_Ok = 0, - SSERC_noResidues = 1 }; - enum { SORT_CHAIN_ChainID_Asc = 0, - SORT_CHAIN_ChainID_Desc = 1 }; - enum { CNSORT_OFF = 0, - CNSORT_1INC = 1, - CNSORT_1DEC = 2, - CNSORT_2INC = 3, - CNSORT_2DEC = 4 }; - - enum PDB_CLEAN_FLAG { - PDBCLEAN_ATNAME = 0x00000001, - PDBCLEAN_TER = 0x00000002, - PDBCLEAN_CHAIN = 0x00000004, - PDBCLEAN_CHAIN_STRONG = 0x00000008, - PDBCLEAN_ALTCODE = 0x00000010, - PDBCLEAN_ALTCODE_STRONG = 0x00000020, - PDBCLEAN_SERIAL = 0x00000040, - PDBCLEAN_SEQNUM = 0x00000080, - PDBCLEAN_INDEX = 0x00000800, - PDBCLEAN_ELEMENT = 0x00001000, - PDBCLEAN_ELEMENT_STRONG = 0x00002000 - }; - - // SS records — public-member structs. Model::GetNumberOf{Helices,Sheets} are - // populated from gemmi Structure::{helices,sheets} on load (_load_metadata) and - // also fillable by Coot's own SS computation via the access_model subclass. - class Helix { - public: - ChainID initChainID{}, endChainID{}; - int initSeqNum = 0, endSeqNum = 0, serNum = 0, helixClass = 0, length = 0; - ResName initResName{}, endResName{}; - InsCode initICode{}, endICode{}; - char helixID[20]{}, comment[80]{}; - }; - class Strand { - public: - ChainID initChainID{}, endChainID{}; - int initSeqNum = 0, endSeqNum = 0, strandNo = 0, sense = 0; - ResName initResName{}, endResName{}; - InsCode initICode{}, endICode{}; - char sheetID[20]{}; - }; - class Sheet { - public: - int nStrands = 0; - Strand **strand = nullptr; - char sheetID[20]{}; - }; - class Sheets { - public: - int nSheets = 0; - Sheet **sheet = nullptr; - }; // filled from gemmi in _load_metadata - typedef Helix *PHelix; - typedef Strand *PStrand; - typedef Sheet *PSheet; - typedef Sheets *PSheets; - // container of helices (Model.helices); Coot's access_model subclass fills it. - class Helices { - public: - std::vector data; - void AddData(PHelix h) { - if (h) data.push_back(h); - } - int nHelices = 0; - }; - - // container of symmetry operators (mmdb_symop.h SymOps). Coot fills it from a - // space group; ops are xyz-triplet strings. - class SymOps { - std::vector ops; - std::deque buf; - - public: - int AddSymOp(cpstr xyz) { - ops.push_back(xyz ? xyz : ""); - return 0; - } - int GetNofSymOps() { return (int)ops.size(); } - pstr GetSymOp(int n) { - if (n < 0 || n >= (int)ops.size()) return nullptr; - buf.push_back(ops[n]); - return (pstr)buf.back().c_str(); - } - void FreeMemory() { ops.clear(); } - }; - - [[noreturn]] inline void unimpl(const char *w) { - throw std::logic_error(std::string("mmdb-shim: unimplemented: ") + w); - } - - // ---- free functions (mmdb_tables.h / mmdb_mattype.h) ---- - inline void InitMatType() {} // real MMDB inits static matrix-type tables; no-op here - inline cpstr GetErrorDescription(ERROR_CODE ec) { - switch (ec) { - case Error_NoError: - return "no error"; - case Error_CantOpenFile: - return "cannot open file"; - default: - return "MMDB error"; - } - } - inline realtype getVdWaalsRadius(cpstr element) { - return gemmi::Element(element ? element : "X").vdw_r(); - } - - // Borrowed empty C-string, returned by the delegating accessors when an object - // is detached (no parent) — real MMDB yields safe defaults, not a crash. - inline pstr mmdb_empty_pstr() { - static char e[1] = {0}; - return e; - } - - // UDData helpers (defined after Manager); each class forwards with its UDR type. - int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int v); - int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype v); - int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, cpstr v); - int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int &v); - int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype &v); - int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, pstr &v); - - // =========================================================================== - class Atom : public UDStore { - public: - Manager *mgr = nullptr; - Residue *res = nullptr; // parent; null => detached (use _local) - int ai = 0; // cached index within parent residue's atoms - bool alive = true; - gemmi::Atom _local; // backing store while detached (see g() resolvers) - int Het = 0; // heteroatom flag (MMDB public field; Coot sets it) - int Ter = 0; // chain-terminator flag (gemmi has none -> always 0) - word WhatIsSet = 0; // ASET_* mask; ASET_Anis_tFac set on load if aniso present - AtomName label_atom_id{}; // mmcif label_atom_id (shim-owned; Coot sets on build) - - Atom() = default; - explicit Atom(Residue *r); // construct + add to residue (out-of-line) - // MMDB owns atoms via `new`/`delete`: Coot writes `delete atom;` to remove an - // atom from the hierarchy (coot-molecule.cc et al.). So atoms are individually - // heap-allocated (Manager::newAtom) and tracked in Manager::_atom_allocs; this - // destructor detaches from the parent residue + flat lists + selections when a - // live atom is deleted, and is a no-op during Manager teardown (_bulk_free). - ~Atom(); // out-of-line (needs complete Manager/Residue) - - gemmi::Atom &g() const; // resolve to live gemmi (defined after Manager) - - // --- rewritten field accessors (pure B) --- - // Scalar fields -> reference-returning accessors, so a uniform `->field`-> - // `->field()` rewrite covers both reads and writes. (occ/b_iso/charge are - // narrower than realtype in gemmi, so those refs are float/schar-typed — the - // rare take-address-of-realtype sites surface at Coot build time.) - // non-const (writable ref) + const (by value) overloads, so reads work on a - // `const mmdb::Atom` and writes work through `->x() = v` on a non-const one. - realtype &x() { return g().pos.x; } - realtype x() const { return g().pos.x; } - realtype &y() { return g().pos.y; } - realtype y() const { return g().pos.y; } - realtype &z() { return g().pos.z; } - realtype z() const { return g().pos.z; } - float &occupancy() { return g().occ; } - float occupancy() const { return g().occ; } - float &tempFactor() { return g().b_iso; } - float tempFactor() const { return g().b_iso; } - signed char &charge() { return g().charge; } - signed char charge() const { return g().charge; } - int &serNum() { return g().serial; } - int serNum() const { return g().serial; } - // altLoc is a char[] (C-string) in MMDB; gemmi stores a single char. Return a - // buffer-backed C-string ("" when unset) so strcmp/strcpy-style code works. - // The non-const overload returns a WRITABLE buffer so `strncpy(at->altLoc(),..)` - // compiles; the buffer's first char is pushed back into gemmi by Residue::AddAtom - // (the buffer is refreshed from gemmi on entry, so reads stay correct). - pstr altLoc() { - _altloc_buf[0] = g().altloc; - _altloc_buf[1] = '\0'; - return _altloc_buf; - } - const char *altLoc() const { - _altloc_buf[0] = g().altloc; - _altloc_buf[1] = '\0'; - return _altloc_buf; - } - void set_occupancy(realtype v) { g().occ = (float)v; } - void set_tempFactor(realtype v) { g().b_iso = (float)v; } - void set_altLoc(char c) { g().altloc = c; } - void SetCharge(realtype ch) { g().charge = (signed char)ch; } - // coordinate/occupancy/B ESDs (MMDB public fields) — gemmi has none, so shim- - // owned; reference-returning so the rewritten `->sigX` covers reads and writes. - float &sigX() { return _sigx; } - float &sigY() { return _sigy; } - float &sigZ() { return _sigz; } - float &sigOcc() { return _sigocc; } - float &sigTemp() { return _sigtemp; } - bool isMetal() const { return gemmi::Element(g().element).is_metal(); } - // anisotropic B tensor — gemmi's SMat33 aniso. Reference-returning so the - // rewritten `->u11` covers both reads and writes. The mutable accessor marks the - // tensor present (ASET_Anis_tFac) so a write (e.g. SHELX import) sets the flag as - // real MMDB does. Const reads never set it; a non-const read over-approximates, - // which is harmless — the PDB/mmCIF writer emits ANISOU on the actual values. - float &u11() { - WhatIsSet |= ASET_Anis_tFac; - return g().aniso.u11; - } - float &u22() { - WhatIsSet |= ASET_Anis_tFac; - return g().aniso.u22; - } - float &u33() { - WhatIsSet |= ASET_Anis_tFac; - return g().aniso.u33; - } - float &u12() { - WhatIsSet |= ASET_Anis_tFac; - return g().aniso.u12; - } - float &u13() { - WhatIsSet |= ASET_Anis_tFac; - return g().aniso.u13; - } - float &u23() { - WhatIsSet |= ASET_Anis_tFac; - return g().aniso.u23; - } - float u11() const { return g().aniso.u11; } - float u22() const { return g().aniso.u22; } - float u33() const { return g().aniso.u33; } - float u12() const { return g().aniso.u12; } - float u13() const { return g().aniso.u13; } - float u23() const { return g().aniso.u23; } - // bonds — not modelled yet (gemmi connections); report none. - int GetNBonds() { return 0; } - void GetBonds(PAtomBond &atomBond, int &n) { - atomBond = nullptr; - n = 0; - } - int AddBond(PAtom /*a*/, int /*order*/, int /*nAdd*/ = 1) { return 0; } - SegID segID{}; // shim-owned (gemmi has no segID); MMDB public char[] field - - // --- method surface (hot subset; rest stubbed) --- - pstr GetAtomName() const; // aligned name, MMDB semantics (const: called on const Atom) - void SetAtomName(const AtomName aName); - pstr GetElementName(); - void SetElementName(const Element elName); - pstr GetChainID(); - int GetSeqNum(); - pstr GetInsCode(); - pstr GetResName(); - Residue *&GetResidue() { return res; } // ref: rewritten `->residue` is assignable - void SetResidue(Residue *r) { res = r; } - Chain *GetChain(); // out-of-line (needs complete Residue/Chain) - Model *GetModel(); // out-of-line - int GetModelNum(); - // residue-delegating accessors (bound by the Python API); out-of-line. - pstr GetLabelCompID(); - pstr GetLabelAsymID(); - int GetLabelSeqID(); - int GetLabelEntityID(); - int GetResidueNo(); - int GetSSEType(); - bool isSolvent(); - bool isNTerminus(); - bool isCTerminus(); - bool isTer() const { return false; } // gemmi has no TER atoms; see notes - void SetCoordinates(realtype xx, realtype yy, realtype zz, - realtype occ, realtype tF); - int GetIndex(); - void MakeTer() { Ter = 1; } // mark as chain terminator - pstr GetAtomID(pstr S); // "/mdl/chain/seq(res).ins/name[elem]:alt" (out-of-line) - int GetUDData(int h, pstr &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } - // copy another atom's data into this one (mmdb Atom::Copy — no hierarchy refs) - void Copy(PAtom a) { - g() = a->g(); - Het = a->Het; - WhatIsSet = a->WhatIsSet; - std::memcpy(segID, a->segID, sizeof segID); - } - // apply a 4x4 (rot+trans) or 3x3+vec to the coordinates (mmdb Atom::Transform) - void Transform(const mat44 &tm) { - gemmi::Position &p = g().pos; - double x = p.x, y = p.y, z = p.z; - p.x = tm[0][0] * x + tm[0][1] * y + tm[0][2] * z + tm[0][3]; - p.y = tm[1][0] * x + tm[1][1] * y + tm[1][2] * z + tm[1][3]; - p.z = tm[2][0] * x + tm[2][1] * y + tm[2][2] * z + tm[2][3]; - } - void Transform(const mat33 &tm, vect3 &v) { - gemmi::Position &p = g().pos; - double x = p.x, y = p.y, z = p.z; - p.x = tm[0][0] * x + tm[0][1] * y + tm[0][2] * z + v[0]; - p.y = tm[1][0] * x + tm[1][1] * y + tm[1][2] * z + v[1]; - p.z = tm[2][0] * x + tm[2][1] * y + tm[2][2] * z + v[2]; - } - // UDData - int PutUDData(int h, int v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } - int PutUDData(int h, realtype v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } - int PutUDData(int h, cpstr v) { return ud_put(mgr, UDR_ATOM, *this, h, v); } - int GetUDData(int h, int &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } - int GetUDData(int h, realtype &v) { return ud_get(mgr, UDR_ATOM, *this, h, v); } - - private: - friend class Residue; // AddAtom pushes the strncpy'd altLoc buffer to gemmi - mutable AtomName _name_buf{}; - Element _elem_buf{}; - mutable char _altloc_buf[4]{}; - float _sigx = 0, _sigy = 0, _sigz = 0, _sigocc = 0, _sigtemp = 0; - }; - - // =========================================================================== - class Residue : public UDStore { - public: - Manager *mgr = nullptr; - Chain *chain = nullptr; // parent; null => detached (use _local) - int ri = 0; - bool alive = true; - gemmi::Residue _local; // backing store while detached - std::vector atoms; // canonical child wrappers == PPAtom table - PPAtom atom = nullptr; // MMDB public atom-table field; kept = atoms.data() - int nAtoms = 0; // MMDB public field; kept = atoms.size() - void _sync_atom() { - atom = atoms.data(); - nAtoms = (int)atoms.size(); - } - // mmcif label_* (shim-owned; Coot sets when building dictionary residues) - ResName label_comp_id{}; - ChainID label_asym_id{}; - int label_seq_id = 0, label_entity_id = 0; - pstr GetLabelCompID() { return label_comp_id; } - pstr GetLabelAsymID() { return label_asym_id; } - int GetLabelSeqID() { return label_seq_id; } - int GetLabelEntityID() { return label_entity_id; } - int GetResidueNo() { return ri; } // 0-based index within its chain - int GetNofAltLocations() { // distinct non-blank altLocs - std::set a; - for (Atom *at : atoms) { - char c = at->g().altloc; - if (c && c != ' ') a.insert(c); - } - return a.empty() ? 1 : (int)a.size(); - } - // sugar / modified-residue classification via gemmi's tabulated residues. - bool isSugar() { - gemmi::ResidueKind k = gemmi::find_tabulated_residue(g().name).kind; - return k == gemmi::ResidueKind::PYR || k == gemmi::ResidueKind::KET; - } - // MMDB isModRes reflects PDB MODRES records (a non-standard, modified form of a - // standard residue). gemmi has no per-residue MODRES flag on the model tree, so - // approximate: an amino/nucleic residue whose one-letter code is lower-case - // (gemmi marks non-standard monomers that way). Water/ligands are excluded. - bool isModRes() { - const gemmi::ResidueInfo ri = gemmi::find_tabulated_residue(g().name); - return ri.found() && !ri.is_standard() && - (ri.is_amino_acid() || ri.is_nucleic_acid()); - } - - Residue() = default; - explicit Residue(Chain *c); // construct + add to chain (out-of-line) - // MMDB owns residues via `new`/`delete` (Coot writes `delete residue_p;`). Like - // ~Atom, this frees the residue's atoms, then DEFERS structural removal: it nulls - // this residue's slot in the parent chain (a tombstone) but leaves the gemmi - // placeholder residue in place so siblings' `ri` stays valid — _compact_residues - // drops both later. No-op during Manager teardown (_bulk_free). - ~Residue(); // out-of-line (needs complete Manager/Chain) - - // MMDB public char-array fields. Coot reads `residue->name` and writes - // `strncpy(residue->insCode,..)`. Kept as the interface: synced gemmi->buffer on - // load (_load_id, in build_from_gemmi) and buffer->gemmi at the adopt point - // (_store_id, in Chain::Add/InsResidue). SetResName/SetResID keep both in step. - ResName name{}; - InsCode insCode{}; - void _load_id() { - std::snprintf(name, sizeof name, "%s", g().name.c_str()); - insCode[0] = g().seqid.icode && g().seqid.icode != ' ' ? g().seqid.icode : '\0'; - insCode[1] = '\0'; - } - void _store_id() { - g().name = name; - g().seqid.icode = insCode[0] ? insCode[0] : ' '; - } - - gemmi::Residue &g() const; - - int GetNumberOfAtoms() { return (int)atoms.size(); } - int GetNumberOfAtoms(bool /*countTers*/) { return (int)atoms.size(); } - PAtom GetAtom(int atomNo) { - return (atomNo >= 0 && atomNo < (int)atoms.size()) ? atoms[atomNo] : nullptr; - } - PAtom GetAtom(const AtomName aname, const Element elname = nullptr, - const AltLoc aloc = nullptr); - void GetAtomTable(PPAtom &atomTable, int &n) { - atomTable = atoms.data(); - n = (int)atoms.size(); - } - PAtom AddAtom(Manager &m, gemmi::Atom a); // append: O(1) - // Adopt a detached atom (Coot's `new mmdb::Atom` idiom). Copies the atom's - // local gemmi into this residue's gemmi (detached or bound, via g()) and - // rebinds the wrapper. Pushes the strncpy'd altLoc buffer back into gemmi. - int AddAtom(PAtom atm); // out-of-line: needs complete Manager (_atom_allocs) - void DeleteAtom(int pos); - void _detach_atom(Atom *a); // unlink (no free); used by ~Atom on Coot `delete atom` - void TrimAtomTable() {} // compact after deletions — shim keeps them in sync - - pstr GetResName(); - void SetResName(const ResName n) { - g().name = n ? n : ""; - std::snprintf(name, sizeof name, "%s", n ? n : ""); - } - void SetResID(const ResName resName, int seqNo, const InsCode ic) { - g().name = resName ? resName : ""; - g().seqid.num.value = seqNo; - g().seqid.icode = (ic && ic[0]) ? ic[0] : ' '; - std::snprintf(name, sizeof name, "%s", resName ? resName : ""); - insCode[0] = (ic && ic[0]) ? ic[0] : '\0'; - insCode[1] = '\0'; - } - int &GetSeqNum(); // writable (rewrite maps `->seqNum` reads and writes) - pstr GetInsCode(); - pstr GetChainID(); - int GetModelNum(); - int &GetIndex() { return ri; } // ref: rewritten `->index` is assignable - Chain *GetChain() { return chain; } - Model *GetModel(); // out-of-line (Chain incomplete here) - // terminus tests — peptide-bond-aware: N-terminus if no preceding residue's C is - // within bonding distance of this N, C-terminus if this C bonds no following N - // (out-of-line: need Chain + backbone atom geometry). - bool isNTerminus(); - bool isCTerminus(); - pstr GetResidueID(pstr S) { // "seqnum(name):inscode" - if (S) std::snprintf(S, 100, "%d(%s):%s", GetSeqNum(), name, insCode); - return S; - } - Residue *next = nullptr; // MMDB has this; wired lazily if needed - int SSE = SSE_None; // secondary-structure element (shim-owned public field) - bool isAminoacid() { return gemmi::find_tabulated_residue(g().name).is_amino_acid(); } - bool isNucleotide() { return gemmi::find_tabulated_residue(g().name).is_nucleic_acid(); } - bool isDNARNA() { return isNucleotide(); } - bool isSolvent() { return gemmi::find_tabulated_residue(g().name).is_water(); } - // UDData - int PutUDData(int h, int v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } - int PutUDData(int h, realtype v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } - int PutUDData(int h, cpstr v) { return ud_put(mgr, UDR_RESIDUE, *this, h, v); } - int GetUDData(int h, int &v) { return ud_get(mgr, UDR_RESIDUE, *this, h, v); } - int GetUDData(int h, realtype &v) { return ud_get(mgr, UDR_RESIDUE, *this, h, v); } - - private: - ResName _resname_buf{}; - InsCode _inscode_buf{}; - }; - - // =========================================================================== - class Chain : public UDStore { - public: - Manager *mgr = nullptr; - Model *model = nullptr; // parent; null => detached (use _local) - int ci = 0; - bool alive = true; - gemmi::Chain _local; // backing store while detached - std::vector residues; - - gemmi::Chain &g() const; - - int GetNumberOfResidues() { return (int)residues.size(); } - PResidue GetResidue(int resNo) { - return (resNo >= 0 && resNo < (int)residues.size()) ? residues[resNo] : nullptr; - } - // find by (seqNum, insCode) — MMDB's 2-arg overload. Skips deferred-delete - // tombstone (null) slots. - PResidue GetResidue(int seqNum, const InsCode insCode) { - char ic = (insCode && insCode[0]) ? insCode[0] : ' '; - for (Residue *r : residues) { - if (!r) continue; // tombstone - gemmi::Residue &gr = r->g(); - char ric = gr.seqid.icode ? gr.seqid.icode : ' '; - if (gr.seqid.num.value == seqNum && ric == ic) return r; - } - return nullptr; - } - void GetResidueTable(PPResidue &t, int &n) { - t = residues.data(); - n = (int)residues.size(); - } - // MMDB DeleteResidue is DEFERRED: it frees the residue and leaves a NULL slot - // (nResidues unchanged) until TrimResidueTable/FinishStructEdit. `delete residue` - // (via ~Residue) does the same. Coot relies on this (e.g. change_chain_id iterates - // to the original count while deleting). We keep the gemmi placeholder residue too - // so surviving residues' `ri` stays aligned; _compact_residues() drops both later. - void DeleteResidue(int resNo) { - if (resNo < 0 || resNo >= (int)residues.size()) return; - if (residues[resNo]) delete residues[resNo]; // ~Residue nulls the slot - } - void DeleteResidue(int seqNum, const InsCode ic) { // by (seqNum, insCode) - PResidue r = GetResidue(seqNum, ic); - if (r) delete r; // ~Residue nulls its slot; keeps the gemmi placeholder - } - void TrimResidueTable() { _compact_residues(); } - // Drop tombstoned (null) residue slots and their gemmi placeholder residues in - // lock-step, then reindex ri. Out-of-line: needs a complete Residue. - void _compact_residues(); - pstr GetChainID(); - pstr GetChainID(pstr buf) { - if (buf) std::snprintf(buf, sizeof(ChainID), "%s", g().name.c_str()); - return buf; - } - Manager *GetCoordHierarchy() { return mgr; } // parent manager - void SetChainID(const ChainID id) { g().name = id ? id : ""; } - Chain() = default; - Chain(Model *m, const ChainID id); // construct + add to model (out-of-line) - void Copy(PChain src); // deep-copy subtree (out-of-line: needs Manager) - // Reorder residues (and their gemmi backing) ascending by (seqNum, insCode), - // MMDB's default. Keeps the wrapper vector and gemmi vector in lock-step and - // re-indexes ri. sortKey variants beyond ascending-by-number are uncommon in - // Coot and treated as the default. - void SortResidues(int /*sortKey*/ = 0) { - _compact_residues(); // never sort across deferred-delete tombstones - int n = (int)residues.size(); - if (n < 2) return; - std::vector ord(n); - for (int i = 0; i < n; ++i) ord[i] = i; - gemmi::Chain &gc = g(); - std::stable_sort(ord.begin(), ord.end(), [&](int a, int b) { - const gemmi::Residue &ra = gc.residues[a], &rb = gc.residues[b]; - if (ra.seqid.num.value != rb.seqid.num.value) return ra.seqid.num.value < rb.seqid.num.value; - char ia = ra.seqid.icode ? ra.seqid.icode : ' ', ib = rb.seqid.icode ? rb.seqid.icode : ' '; - return ia < ib; - }); - std::vector gnew; - gnew.reserve(n); - std::vector wnew; - wnew.reserve(n); - for (int k = 0; k < n; ++k) { - gnew.push_back(std::move(gc.residues[ord[k]])); - wnew.push_back(residues[ord[k]]); - } - gc.residues = std::move(gnew); - residues = std::move(wnew); - for (int k = 0; k < n; ++k) residues[k]->ri = k; - } - bool isAminoacidChain(); // defined out-of-line (needs Residue predicates) - bool isNucleotideChain(); - bool isSolventChain(); - PResidue AddResidue(Manager &m, gemmi::Residue r); // append - PResidue InsResidue(Manager &m, int pos, gemmi::Residue r); - // Adopt a detached residue (its atom wrappers already point at it, so they - // ride along once its gemmi is copied in and the wrapper is rebound). - int AddResidue(PResidue res) { - res->_store_id(); // push name/insCode buffers into gemmi - g().residues.push_back(res->g()); // res detached -> its _local (with atoms) - res->chain = this; - res->mgr = mgr; - res->ri = (int)residues.size(); - residues.push_back(res); - return 0; - } - int InsResidue(PResidue res, int pos) { - _compact_residues(); // don't insert/reindex across tombstones - if (pos < 0) pos = 0; - if (pos > (int)residues.size()) pos = (int)residues.size(); - res->_store_id(); - g().residues.insert(g().residues.begin() + pos, res->g()); - res->chain = this; - res->mgr = mgr; - res->ri = pos; - residues.insert(residues.begin() + pos, res); - for (int k = pos + 1; k < (int)residues.size(); ++k) residues[k]->ri = k; - return 0; - } - - private: - ChainID _chainid_buf{}; - }; - - // =========================================================================== - class Model : public UDStore { - public: - Manager *mgr = nullptr; // null => detached (use _local) - int mi = 0; // 0-based internal; GetModel is 1-based externally - gemmi::Model _local{1}; // backing store while detached (gemmi Model num is int) - std::vector chains; - - gemmi::Model &g() const; - - int GetNumberOfChains() { return (int)chains.size(); } - PChain GetChain(int chainNo) { - return (chainNo >= 0 && chainNo < (int)chains.size()) ? chains[chainNo] : nullptr; - } - PChain GetChain(const ChainID chID); - // Adopt a detached chain (Coot's `new mmdb::Chain` idiom): copy its local - // gemmi (with any residues/atoms) into this model and rebind, cascading mgr - // to the sub-tree that was built while detached (mgr was null). - int AddChain(PChain chn) { - g().chains.push_back(chn->g()); - chn->model = this; - chn->mgr = mgr; - chn->ci = (int)chains.size(); - chains.push_back(chn); - for (Residue *r : chn->residues) { - r->mgr = mgr; - for (Atom *a : r->atoms) a->mgr = mgr; - } - return 0; - } - int GetSerNum() { return mi + 1; } - // delete chain at index: erase gemmi + wrapper, reindex the tail - void DeleteChain(int chainNo) { - if (chainNo < 0 || chainNo >= (int)chains.size()) return; - g().chains.erase(g().chains.begin() + chainNo); - chains.erase(chains.begin() + chainNo); - for (int k = chainNo; k < (int)chains.size(); ++k) chains[k]->ci = k; - } - void DeleteChain(const ChainID chainID) { - for (int i = 0; i < (int)chains.size(); ++i) - if (chains[i]->g().name == (chainID ? chainID : "")) { - DeleteChain(i); - return; - } - } - void GetChainTable(PPChain &t, int &n) { - t = chains.data(); - n = (int)chains.size(); - } - std::vector all_atoms; // flat, filled by build_from_gemmi - PPAtom GetAllAtoms() { return all_atoms.data(); } - int GetNumberOfAtoms() { return (int)all_atoms.size(); } - int GetNumberOfAtoms(bool /*countTers*/) { return (int)all_atoms.size(); } - // Secondary-structure assignment: mocked. gemmi's DSSP has its SS prediction - // disabled upstream ("commented out ... wasn't correct anyway"), so there is no - // gemmi-backed SS to forward to. Return the non-OK code so callers treat SS as - // unavailable rather than trusting a bogus assignment. (residue SSE stays None.) - int CalcSecStructure(bool /*flag*/) { return SSERC_noResidues; } - // LINK records — gemmi-loaded (Manager::_load_metadata) plus Coot-created ones - // (AddLink) stored here; GetLink is 1-based like MMDB. - std::vector _links; - int GetNumberOfLinks() { return (int)_links.size(); } - PLink GetLink(int i) { return (i >= 1 && i <= (int)_links.size()) ? _links[i - 1] : nullptr; } - void AddLink(PLink link) { - if (link) _links.push_back(link); - } - // Refmac LINKR records — gemmi Connections that carry a link_id (_load_metadata). - std::vector _linkrs; - int GetNumberOfLinkRs() { return (int)_linkrs.size(); } - PLinkR GetLinkR(int i) { return (i >= 1 && i <= (int)_linkrs.size()) ? _linkrs[i - 1] : nullptr; } - void AddLinkR(PLinkR lr) { - if (lr) _linkrs.push_back(lr); - } - std::vector _cispeps; - int GetNumberOfCisPeps() { return (int)_cispeps.size(); } - PCisPep GetCisPep(int i) { return (i >= 1 && i <= (int)_cispeps.size()) ? _cispeps[i - 1] : nullptr; } - void AddCisPep(PCisPep cp) { - if (cp) _cispeps.push_back(cp); - } - void RemoveCisPeps() { _cispeps.clear(); } - // secondary structure. Records live in `helices`/`sheets` below, populated - // either from gemmi on load (build_from_gemmi) or by Coot's own SS computation - // via the access_model subclass (which reaches these public members directly). - // 1-based indexing to match MMDB. - int GetNumberOfHelices() { return (int)helices.data.size(); } - PHelix GetHelix(int i) { return (i >= 1 && i <= (int)helices.data.size()) ? helices.data[i - 1] : nullptr; } - int GetNumberOfSheets() { return sheets.nSheets; } - PSheet GetSheet(int i) { return (i >= 1 && i <= sheets.nSheets && sheets.sheet) ? sheets.sheet[i - 1] : nullptr; } - Sheets sheets; // SS records (gemmi-backed on load; access_model fills) - Helices helices; // " " " - std::vector _sheet_ptrs; // backing array for sheets.sheet (gemmi load) - PSheets GetSheets() { return &sheets; } - int GetModelID() { return mi + 1; } - pstr GetModelID(pstr buf) { - if (buf) std::snprintf(buf, 16, "%d", mi + 1); - return buf; - } - int CalcSecStructure(int /*flag*/, int /*selHnd*/) { return SSERC_noResidues; } // mocked; see bool overload - void Copy(PModel src); // deep-copy subtree (out-of-line) - Manager *GetCoordHierarchy() { return mgr; } // parent manager - int GetNumberOfResidues() { - int n = 0; - for (Chain *c : chains) n += c->GetNumberOfResidues(); - return n; - } - LinkContainer _linkc; - PLinkContainer GetLinks() { - _linkc.data.assign(_links.begin(), _links.end()); - return &_linkc; - } - void RemoveLinks() { _links.clear(); } - // Reorder chains (and gemmi backing) by chain ID. sortKey selects ascending - // (default) or descending; other MMDB sort keys collapse to ID order. - void SortChains(int sortKey = 0) { - int n = (int)chains.size(); - if (n < 2) return; - bool desc = (sortKey == SORT_CHAIN_ChainID_Desc); - std::vector ord(n); - for (int i = 0; i < n; ++i) ord[i] = i; - gemmi::Model &gm = g(); - std::stable_sort(ord.begin(), ord.end(), [&](int a, int b) { - return desc ? (gm.chains[a].name > gm.chains[b].name) - : (gm.chains[a].name < gm.chains[b].name); - }); - std::vector gnew; - gnew.reserve(n); - std::vector wnew; - wnew.reserve(n); - for (int k = 0; k < n; ++k) { - gnew.push_back(std::move(gm.chains[ord[k]])); - wnew.push_back(chains[ord[k]]); - } - gm.chains = std::move(gnew); - chains = std::move(wnew); - for (int k = 0; k < n; ++k) chains[k]->ci = k; - } - PChain CreateChain(const ChainID id); // add empty chain (out-of-line: needs Manager) - int GetNumberOfStrands(int sheetNo) { - PSheet s = GetSheet(sheetNo); - return s ? s->nStrands : 0; - } - PStrand GetStrand(int sheetNo, int strandNo) { - PSheet s = GetSheet(sheetNo); - return (s && strandNo >= 1 && strandNo <= s->nStrands && s->strand) ? s->strand[strandNo - 1] : nullptr; - } - }; - - // =========================================================================== - class Manager { - public: - gemmi::Structure st; - // Atoms are heap-allocated individually (not pooled) so Coot's MMDB idiom - // `delete atom;` frees exactly one node. The manager owns every atom it hands - // out and frees the survivors at teardown; `~Atom` removes itself from this set - // when Coot deletes it early. `_bulk_free` tells `~Atom` to skip detach work - // while the manager is tearing everything down. - std::set _atom_allocs; - std::set _res_allocs; // residues heap-allocated too (Coot `delete residue_p`) - bool _bulk_free = false; - ~Manager() { - _bulk_free = true; - for (Atom *a : _atom_allocs) delete a; - _atom_allocs.clear(); - for (Residue *r : _res_allocs) delete r; - _res_allocs.clear(); - } - // stable-address pools (Chain/Model still pooled — see _atom_allocs / _res_allocs note) - std::deque chain_pool; - std::deque model_pool; - std::vector models; - // stable-address pools for gemmi-derived metadata records (LINK / CISPEP / - // HELIX / SHEET). Filled by build_from_gemmi -> _load_metadata(); owned here so - // the Model containers can hold bare pointers into them. - std::deque link_pool; - std::deque linkr_pool; - std::deque cispep_pool; - std::deque helix_pool; - std::deque sheet_pool; - std::deque strand_pool; - std::deque> strandarr_pool; // backing for Sheet::strand (Strand**) - std::deque author_pool; // backing for title.author records - void _load_metadata(); // out-of-line: needs complete gemmi metadata types - - Atom *newAtom() { - Atom *a = new Atom(); - a->mgr = this; - _atom_allocs.insert(a); - return a; - } - Residue *newRes() { - Residue *r = new Residue(); - r->mgr = this; - _res_allocs.insert(r); - return r; - } - Chain *newChain() { - chain_pool.emplace_back(); - return &chain_pool.back(); - } - Model *newModel() { - model_pool.emplace_back(); - return &model_pool.back(); - } - - int GetNumberOfModels() { return (int)models.size(); } - PModel GetModel(int modelNo) { // MMDB: 1 <= modelNo <= nModels - int i = modelNo - 1; - return (i >= 0 && i < (int)models.size()) ? models[i] : nullptr; - } - // per-model chain access (modelNo is 1-based, chainNo 0-based) — mmdb_coormngr.h - int GetNumberOfChains(int modelNo) { - PModel m = GetModel(modelNo); - return m ? m->GetNumberOfChains() : 0; - } - PChain GetChain(int modelNo, int chainNo) { - PModel m = GetModel(modelNo); - return m ? m->GetChain(chainNo) : nullptr; - } - // Re-index/renumber after edits. Sibling indices are kept in sync as the shim - // mutates (so PDBCLEAN_INDEX is implicit); PDBCLEAN_SERIAL renumbers atom serials - // 1..N in hierarchy order. Other clean flags are not needed by the shim. - word PDBCleanup(word CleanKey) { - // INDEX cleanup compacts deferred residue deletions (drops tombstones) — do it - // before renumbering so serials/indices count only surviving atoms. - if (CleanKey & PDBCLEAN_INDEX) { - for (Model *mw : models) - for (Chain *cw : mw->chains) cw->_compact_residues(); - _rebuild_all_atoms(); - } - if (CleanKey & (PDBCLEAN_SERIAL | PDBCLEAN_INDEX)) { - int s = 1; - for (Atom *a : all_atoms) a->g().serial = s++; - } - return 0; - } - - // PDB title records — Coot reaches `title` via an access_mol subclass; the - // TITLE string comes from gemmi (_struct.title), authors are filled on load. - Title title; - pstr GetStructureTitle(pstr T) { - if (T) std::strcpy(T, st.get_info("_struct.title").c_str()); // caller allocates (MMDB contract) - return T; - } - - // Orthogonal symmetry transformation for operator Nop (0-based) + cell shifts, - // via gemmi's space group + unit cell (shared helper). Returns 0 on success, - // nonzero if there is no usable space group / the operator is out of range. - int GetTMatrix(mat44 &TMatrix, int Nop, int cellshift_a, int cellshift_b, int cellshift_c) { - return gemmi_sym_tmatrix(st.cell, st.spacegroup_hm, TMatrix, Nop, - cellshift_a, cellshift_b, cellshift_c); - } - - void build_from_gemmi(); - - // adopt a detached model (Coot: `new mmdb::Model` -> AddChain… -> AddModel). - // Copy its local gemmi into st, rebind, cascade mgr through the sub-tree. - int AddModel(PModel mw) { - st.models.push_back(mw->g()); - mw->mgr = this; - mw->mi = (int)models.size(); - models.push_back(mw); - for (Chain *cw : mw->chains) { - cw->mgr = this; - for (Residue *rw : cw->residues) { - rw->mgr = this; - for (Atom *aw : rw->atoms) { - aw->mgr = this; - all_atoms.push_back(aw); - mw->all_atoms.push_back(aw); - } - } - } - return 0; - } - - // clone another manager's structure (mmdb Manager::Copy(PManager, COPY_MASK)). - // Copies the whole gemmi Structure and rebuilds all wrappers — clean & correct. - void Copy(PManager m, int /*CopyMask*/) { - if (m) { - st = m->st; - build_from_gemmi(); - } - } - - // ---- crystal cell & symmetry (gemmi UnitCell / SpaceGroup) ---- - std::string _sg_buf, _symop_buf; - void GetCell(realtype &a, realtype &b, realtype &c, realtype &al, realtype &be, - realtype &ga, realtype &vol, int &orthcode) { - const gemmi::UnitCell &u = st.cell; - a = u.a; - b = u.b; - c = u.c; - al = u.alpha; - be = u.beta; - ga = u.gamma; - vol = u.volume; - orthcode = 1; - } - void GetCell(realtype &a, realtype &b, realtype &c, realtype &al, realtype &be, - realtype &ga, realtype &vol) { - int oc; - GetCell(a, b, c, al, be, ga, vol, oc); - } - void SetCell(realtype a, realtype b, realtype c, realtype al, realtype be, - realtype ga, int /*OrthCode*/ = 1) { st.cell.set(a, b, c, al, be, ga); } - void Orth2Frac(realtype x, realtype y, realtype z, realtype &u, realtype &v, realtype &w) { - gemmi::Fractional f = st.cell.fractionalize(gemmi::Position(x, y, z)); - u = f.x; - v = f.y; - w = f.z; - } - void Frac2Orth(realtype u, realtype v, realtype w, realtype &x, realtype &y, realtype &z) { - gemmi::Position p = st.cell.orthogonalize(gemmi::Fractional(u, v, w)); - x = p.x; - y = p.y; - z = p.z; - } - pstr GetSpaceGroup() { - _sg_buf = st.spacegroup_hm; - return (pstr)_sg_buf.c_str(); - } - pstr GetSpaceGroupFix() { return GetSpaceGroup(); } - int SetSpaceGroup(cpstr sg) { - st.spacegroup_hm = sg ? sg : ""; - return 0; - } - int GetNumberOfSymOps() { - const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(st.spacegroup_hm); - return sg ? (int)sg->operations().order() : 0; - } - pstr GetSymOp(int Nop) { - const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(st.spacegroup_hm); - if (!sg) return nullptr; - int i = 0; - for (gemmi::Op op : sg->operations()) { - if (i++ == Nop) { - _symop_buf = op.triplet(); - return (pstr)_symop_buf.c_str(); - } - } - return nullptr; - } - - // ---- selection ---- - struct Selection { - SELECTION_TYPE type = STYPE_UNDEFINED; - std::vector atoms; - std::vector residues; - std::vector chains; - }; - std::vector selections; // handle is 1-based index - - int NewSelection() { - selections.emplace_back(); - return (int)selections.size(); - } - void DeleteSelection(int selHnd) { - if (selHnd < 1 || selHnd > (int)selections.size()) return; - Selection &s = selections[selHnd - 1]; - for (Atom *a : s.atoms) a->_setInSel(selHnd, false); - for (Residue *r : s.residues) r->_setInSel(selHnd, false); - for (Chain *c : s.chains) c->_setInSel(selHnd, false); - s = Selection(); - } - void GetSelIndex(int selHnd, PPAtom &SelAtom, int &n) { - Selection &s = selections[selHnd - 1]; - SelAtom = s.atoms.data(); - n = (int)s.atoms.size(); - } - void GetSelIndex(int selHnd, PPResidue &SelRes, int &n) { - Selection &s = selections[selHnd - 1]; - SelRes = s.residues.data(); - n = (int)s.residues.size(); - } - void GetSelIndex(int selHnd, PPChain &SelChain, int &n) { - Selection &s = selections[selHnd - 1]; - SelChain = s.chains.data(); - n = (int)s.chains.size(); - } - // select atoms by serial-number range (iSer1..iSer2; 0,0 => all). - void SelectAtoms(int selHnd, int iSer1, int iSer2, SELECTION_KEY key) { - if (selHnd < 1 || selHnd > (int)selections.size()) return; - Selection &s = selections[selHnd - 1]; - std::vector pick; - for (Atom *a : all_atoms) { - int sn = a->g().serial; - if ((iSer1 == 0 && iSer2 == 0) || (sn >= iSer1 && sn <= iSer2)) pick.push_back(a); - } - if (key == SKEY_OR) { - for (Atom *a : pick) - if (!a->isInSelection(selHnd)) s.atoms.push_back(a); - } else { - for (Atom *a : s.atoms) a->_setInSel(selHnd, false); - s.atoms = pick; - } - s.type = STYPE_ATOM; - for (Atom *a : s.atoms) a->_setInSel(selHnd, true); - } - - // full spatial+CID atom selection (mmdb_selmngr.h) — sphere around (x,y,z) with - // chain/resname/atomname/element filters ("!X" = exclusion, "*" = any). - void SelectAtoms(int selHnd, int /*iModel*/, cpstr Chains, int ResNo1, cpstr /*Ins1*/, - int ResNo2, cpstr /*Ins2*/, cpstr RNames, cpstr ANames, cpstr Elements, - cpstr /*altLocs*/, cpstr /*segIDs*/, cpstr /*charges*/, - realtype /*occ1*/, realtype /*occ2*/, realtype x, realtype y, realtype z, - realtype radius, SELECTION_KEY key) { - if (selHnd < 1 || selHnd > (int)selections.size()) return; - Selection &s = selections[selHnd - 1]; - // self-contained comma-list matcher ("*"=any, "!X"=exclude); `detail::` is - // declared after Manager, so don't depend on it in this inline body. - auto trimws = [](const std::string &s) -> std::string { - size_t a = s.find_first_not_of(' '), b = s.find_last_not_of(' '); - return a == std::string::npos ? std::string() : s.substr(a, b - a + 1); - }; - auto inlist = [&trimws](cpstr list, const std::string &v) -> bool { - if (!list || !*list || std::strcmp(list, "*") == 0) return true; - std::string vt = trimws(v); - for (const char *p = list; *p;) { - const char *c = std::strchr(p, ','); - std::string tok(p, c ? (size_t)(c - p) : std::strlen(p)); - if (trimws(tok) == vt) return true; - if (!c) break; - p = c + 1; - } - return false; - }; - auto match = [&](cpstr list, const std::string &v) -> bool { - if (!list || !*list || std::strcmp(list, "*") == 0) return true; - if (list[0] == '!') return !inlist(list + 1, v); - return inlist(list, v); - }; - gemmi::Position pt(x, y, z); - double r2 = radius * radius; - std::vector pick; - for (Atom *a : all_atoms) { - if (radius > 0 && a->g().pos.dist_sq(pt) > r2) continue; - Residue *r = a->res; - int sn = r->GetSeqNum(); - if (ResNo1 != ANY_RES && sn < ResNo1) continue; - if (ResNo2 != ANY_RES && sn > ResNo2) continue; - if (!match(Chains, r->chain->g().name)) continue; - if (!match(RNames, std::string(r->GetResName()))) continue; - if (!match(ANames, std::string(a->GetAtomName()))) continue; - if (!match(Elements, gemmi::Element(a->g().element).name())) continue; - pick.push_back(a); - } - if (key == SKEY_OR) { - for (Atom *a : pick) - if (!a->isInSelection(selHnd)) s.atoms.push_back(a); - } else { - for (Atom *a : s.atoms) a->_setInSel(selHnd, false); - s.atoms = pick; - } - s.type = STYPE_ATOM; - for (Atom *a : s.atoms) a->_setInSel(selHnd, true); - } - - // --- misc hierarchy/bond/UDData ops used by Coot --- - void RemoveBonds() {} // gemmi has no persistent bond table - // Partial-hierarchy delete (mmdb Manager::Delete). Coot's use is - // Delete(MMDBFCM_SC) to drop secondary-structure/connectivity records before - // writing; also honour Coord (atoms) and Cryst (cell/SG) for completeness. - void Delete(int DelKey) { - bool all = DelKey == MMDBFCM_All; - if (all || (DelKey & MMDBFCM_SC)) { - for (Model *m : models) { - m->_links.clear(); - m->_linkrs.clear(); - m->_cispeps.clear(); - m->helices.data.clear(); - m->sheets.nSheets = 0; - m->sheets.sheet = nullptr; - m->_sheet_ptrs.clear(); - } - link_pool.clear(); - linkr_pool.clear(); - cispep_pool.clear(); - helix_pool.clear(); - sheet_pool.clear(); - strand_pool.clear(); - strandarr_pool.clear(); - } - if (all || (DelKey & MMDBFCM_Cryst)) { - st.cell = gemmi::UnitCell(); - st.spacegroup_hm.clear(); - } - if (all || (DelKey & MMDBFCM_Coord)) { - st.models.clear(); - build_from_gemmi(); - } - } - void DeleteAllModels() { - st.models.clear(); - build_from_gemmi(); - } // clears the hierarchy - void DeleteModel(int modelNo) { // 1-based; erase model + rebuild wrappers - int i = modelNo - 1; - if (i >= 0 && i < (int)st.models.size()) { - st.models.erase(st.models.begin() + i); - build_from_gemmi(); - } - } - pstr GetInputBuffer(pstr buf, int &count) { - count = 0; - if (buf) buf[0] = '\0'; - return buf; - } - // Insert (a copy of) an atom into the hierarchy (mmdb Manager::PutAtom). MMDB - // keeps a flat atom array with a parallel hierarchy rebuilt by FinishStructEdit; - // the shim's storage IS the hierarchy, so PutAtom finds/creates the chain and - // residue implied by the atom's source residue and appends a copy there. Only - // append (index<=0 or top) is supported — the semantics Coot relies on - // (create_mmdbmanager_from_atom_selection_straight). Returns the atom's 1-based - // position (so GetAtomI(pos) returns it). Defined out-of-line (needs Add*). - int PutAtom(int index, PAtom atom, int serNum = 0); - // hierarchy-level UDData (UDR_HIERARCHY) — Manager owns its own UDStore. - UDStore _ud; - int PutUDData(int h, int v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } - int PutUDData(int h, realtype v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } - int PutUDData(int h, cpstr v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } - int GetUDData(int h, int &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } - int GetUDData(int h, realtype &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } - int GetUDData(int h, pstr &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } - // primary CID-range selection (STYPE via Select; SelectAtoms forwards as STYPE_ATOM) - void Select(int selHnd, SELECTION_TYPE sType, int iModel, cpstr Chains, - int ResNo1, cpstr Ins1, int ResNo2, cpstr Ins2, cpstr RNames, - cpstr ANames, cpstr Elements, cpstr altLocs, SELECTION_KEY selKey = SKEY_OR); - void SelectAtoms(int selHnd, int iModel, cpstr Chains, int ResNo1, cpstr Ins1, - int ResNo2, cpstr Ins2, cpstr RNames, cpstr ANames, - cpstr Elements, cpstr altLocs, SELECTION_KEY selKey = SKEY_OR) { - Select(selHnd, STYPE_ATOM, iModel, Chains, ResNo1, Ins1, ResNo2, Ins2, - RNames, ANames, Elements, altLocs, selKey); - } - void SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, realtype y, - realtype z, realtype r, SELECTION_KEY sKey = SKEY_OR); - // select-from-selection: combine selHnd2's contents into selHnd1 per sKey - void Select(int selHnd1, SELECTION_TYPE sType, int selHnd2, SELECTION_KEY sKey); - // atoms within [d1,d2] of any atom in the given set (defined in contacts.cc) - void SelectNeighbours(int selHnd, SELECTION_TYPE sType, PPAtom atoms, int nAtoms, - realtype d1, realtype d2, SELECTION_KEY sKey = SKEY_OR); - void SetFlag(int /*flags*/) {} // no-op: read/write behaviour is fixed - void SetFlag(cpstr /*flags*/) {} - int PutPDBString(cpstr /*card*/) { return Error_NoError; } // no-op - // No persistent bond table. Verified safe: Coot's only caller (make_bonds in - // coot-utils/bonded-atoms.cc) ignores the mmdb bond table and recomputes bonds - // itself from geometry, so a no-op here matches observed Coot behaviour. - int MakeBonds(bool /*calc*/) { return 0; } - - // flat atom access (across the whole hierarchy) - std::vector all_atoms; - int GetNumberOfAtoms() { return (int)all_atoms.size(); } - int GetNumberOfAtoms(bool /*countTers*/) { return (int)all_atoms.size(); } - int GetNumberOfAtoms(cpstr CID); // count atoms matching CID (defined below) - // MMDB GetAtomI is 1-based: returns Atom[index-1]. - PAtom GetAtomI(int i) { return (i >= 1 && i <= (int)all_atoms.size()) ? all_atoms[i - 1] : nullptr; } - void GetAtomTable(PPAtom &t, int &n) { - t = all_atoms.data(); - n = (int)all_atoms.size(); - } - void GetModelTable(PPModel &t, int &n) { - t = models.data(); - n = (int)models.size(); - } - void GetAtomStatistics(int selHnd, RAtomStat AS); // defined below - int MakeSelIndex(int selHnd) { - return (selHnd >= 1 && selHnd <= (int)selections.size()) - ? (int)selections[selHnd - 1].atoms.size() - : 0; - } - void SelectAtom(int selHnd, PAtom atom, SELECTION_KEY sKey, bool makeIndex = true); - // CID-string selection, e.g. "/1/A/10-20/CA" - void Select(int selHnd, SELECTION_TYPE sType, cpstr CID, SELECTION_KEY sKey); - - // ---- contacts (gemmi NeighborSearch; TMatrix path uses a uniform grid) ---- - // TMatrix is MMDB's optional symmetry transform applied to the 2nd set: when - // given, contacts.cc transforms that set and searches against it (symmetry - // mates); when null, gemmi NeighborSearch over the untransformed model is used. - void SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, - realtype d2, int seqDist, PContact &contact, int &ncontacts, - int maxlen = 0, pmat44 TMatrix = nullptr, long group = 0); - void SeekContacts(PPAtom A, int n, realtype d1, realtype d2, int seqDist, - PContact &contact, int &ncontacts, int maxlen = 0, - pmat44 TMatrix = nullptr, long group = 0); - // single-atom vs selection (forwards to the array overload with a 1-elem array) - void SeekContacts(PAtom a, PPAtom A2, int n2, realtype d1, realtype d2, int seqDist, - PContact &contact, int &ncontacts, int maxlen = 0, - pmat44 TMatrix = nullptr, long group = 0) { - PAtom a1[1] = {a}; - SeekContacts(a1, 1, A2, n2, d1, d2, seqDist, contact, ncontacts, maxlen, TMatrix, group); - } - - // Compact deferred residue deletions across the whole hierarchy: MMDB defers - // DeleteResidue (tombstone the slot, keep the count) until FinishStructEdit, so - // here we drop the null tombstone slots + their gemmi placeholder residues and - // rebuild the flat atom lists. (Atoms already stay in sync eagerly.) - void _rebuild_all_atoms() { - all_atoms.clear(); - for (Model *mw : models) { - mw->mgr = this; - mw->all_atoms.clear(); - for (Chain *cw : mw->chains) { - cw->mgr = this; - for (Residue *rw : cw->residues) - if (rw) { - rw->mgr = this; - for (Atom *aw : rw->atoms) { - // Rebind ownership pointers: residues added via AddResidue/ - // InsResidue (e.g. add_terminal_residue) carry atoms whose mgr - // still points at the deep-copy temporary (or is null). Atom - // UDData routes through Atom::mgr, so without this the new atoms - // fail Put/GetUDData with WrongHandle — which drops their bonds - // (the atom-index UDD never lands) and any UD colouring. - aw->mgr = this; - aw->res = rw; - all_atoms.push_back(aw); - mw->all_atoms.push_back(aw); - } - } - } - } - } - int FinishStructEdit() { - for (Model *mw : models) - for (Chain *cw : mw->chains) cw->_compact_residues(); - _rebuild_all_atoms(); - return 0; - } - - // ---- UDData registry ---- - struct UDReg { - UDR_TYPE type; - int kind; - std::string name; - int slot; - }; // kind:0=int,1=real,2=str - std::vector ud_regs; - int ud_counts[5][3] = {{0}}; // [UDR_TYPE][kind] -> next slot - - int RegisterUDInteger(UDR_TYPE t, cpstr name) { return _regUD(t, 0, name); } - int RegisterUDReal(UDR_TYPE t, cpstr name) { return _regUD(t, 1, name); } - int RegisterUDString(UDR_TYPE t, cpstr name) { return _regUD(t, 2, name); } - int GetUDDHandle(UDR_TYPE t, cpstr name) { - for (int i = 0; i < (int)ud_regs.size(); ++i) - if (ud_regs[i].type == t && ud_regs[i].name == name) return i + 1; - return 0; // MMDB: 0 == "not registered" — Coot relies on `if (handle == 0) Register…` - } - - private: - // MMDB UDData handles are 1-based (0 is reserved for "not registered", see - // GetUDDHandle). Return a 1-based handle; _ud_desc maps back with handle-1. - int _regUD(UDR_TYPE t, int kind, cpstr name) { - ud_regs.push_back({t, kind, name ? name : "", ud_counts[t][kind]++}); - return (int)ud_regs.size(); - } - - public: - // ---- I/O (defined in mmdb-shim/src/io.cc; keeps heavy gemmi write/read - // headers out of the ~229 Coot TUs that include mmdb_manager.h) ---- - ERROR_CODE ReadPDBASCII(cpstr fname); - ERROR_CODE ReadCoorFile(cpstr fname); // auto-detects PDB / mmCIF - ERROR_CODE WritePDBASCII(cpstr fname); - ERROR_CODE WriteCIFASCII(cpstr fname); - }; - - // ---- g() resolvers ---- - // A wrapper with no parent is "detached" (Coot's `new mmdb::Atom` idiom: build - // standalone, set fields, then Add*() into a parent). While detached, g() - // resolves to a wrapper-owned local gemmi object; Add*() copies that local into - // the parent's gemmi vector and rebinds (sets parent + index). Index-based - // resolution makes the vector push/reallocation harmless for siblings. - inline gemmi::Model &Model::g() const { return mgr ? mgr->st.models[mi] : const_cast(this)->_local; } - inline gemmi::Chain &Chain::g() const { return model ? model->g().chains[ci] : const_cast(this)->_local; } - inline gemmi::Residue &Residue::g() const { return chain ? chain->g().residues[ri] : const_cast(this)->_local; } - inline gemmi::Atom &Atom::g() const { - if (res && res->chain && res->chain->model && res->chain->model->mgr) { - auto &mgr = *res->chain->model->mgr; - int mi = res->chain->model->mi; - if (mi >= 0 && mi < (int)mgr.st.models.size()) { - return res->g().atoms[ai]; - } - } - return const_cast(this)->_local; - } - - // ---- UDData helpers ---- - inline Manager::UDReg *_ud_desc(Manager *mgr, UDR_TYPE myType, int handle, int kind, - int &err) { - if (!mgr || handle < 1 || handle > (int)mgr->ud_regs.size()) { - err = UDDATA_WrongHandle; - return nullptr; - } - Manager::UDReg &d = mgr->ud_regs[handle - 1]; // handles are 1-based (see _regUD) - if (d.type != myType || d.kind != kind) { - err = UDDATA_WrongUDRType; - return nullptr; - } - err = UDDATA_Ok; - return &d; - } - inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, int v) { - int e; - auto *d = _ud_desc(mgr, t, h, 0, e); - if (!d) return e; - if ((int)s._udi.size() <= d->slot) s._udi.resize(d->slot + 1, 0); - s._udi[d->slot] = v; - return UDDATA_Ok; - } - inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, realtype v) { - int e; - auto *d = _ud_desc(mgr, t, h, 1, e); - if (!d) return e; - if ((int)s._udr.size() <= d->slot) s._udr.resize(d->slot + 1, 0.0); - s._udr[d->slot] = v; - return UDDATA_Ok; - } - inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, cpstr v) { - int e; - auto *d = _ud_desc(mgr, t, h, 2, e); - if (!d) return e; - if ((int)s._uds.size() <= d->slot) s._uds.resize(d->slot + 1); - s._uds[d->slot] = v ? v : ""; - return UDDATA_Ok; - } - inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, int &v) { - int e; - auto *d = _ud_desc(mgr, t, h, 0, e); - if (!d) return e; - if ((int)s._udi.size() <= d->slot) return UDDATA_NoData; - v = s._udi[d->slot]; - return UDDATA_Ok; - } - inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, realtype &v) { - int e; - auto *d = _ud_desc(mgr, t, h, 1, e); - if (!d) return e; - if ((int)s._udr.size() <= d->slot) return UDDATA_NoData; - v = s._udr[d->slot]; - return UDDATA_Ok; - } - inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, pstr &v) { - int e; - auto *d = _ud_desc(mgr, t, h, 2, e); - if (!d) return e; - if ((int)s._uds.size() <= d->slot) return UDDATA_NoData; - v = (pstr)s._uds[d->slot].c_str(); - return UDDATA_Ok; // borrowed - } - - // ---- Atom out-of-line ---- - inline pstr Atom::GetAtomName() const { - // MMDB returns the PDB-column-aligned 4-char atom name (e.g. " N ", " CA ", - // " CG2"); gemmi stores the trimmed name ("N"/"CA"/"CG2"). Reproduce MMDB - // alignment via gemmi's padded_name() (left-pad by element) + right-pad to 4 - // — the exact rule gemmi's own mmdb.hpp bridge uses. Coot's atom_spec_t names - // are these 4-char strings, so returning the trimmed name breaks every lookup. - std::string padded = g().padded_name(); - if (padded.size() < 4) padded.resize(4, ' '); - std::snprintf(_name_buf, sizeof(_name_buf), "%s", padded.c_str()); - return _name_buf; - } - // Coot passes MMDB-aligned 4-char names (" CA "); gemmi stores trimmed names - // ("CA") and re-pads on output (GetAtomName / PDB write) — store trimmed so - // gemmi's own formatting stays correct. - inline void Atom::SetAtomName(const AtomName aName) { g().name = aName ? gemmi::trim_str(aName) : ""; } - inline pstr Atom::GetElementName() { - // MMDB returns the PDB-column-aligned element: 2 chars, right-justified, - // UPPERCASE (" H", " C", "NA", "FE"). gemmi's Element::name() is unpadded and - // mixed-case ("H"/"C"/"Na"/"Fe"), so Coot's element tests — e.g. - // get_number_of_hydrogen_atoms() comparing `ele == " H"` — never match. Align - // to MMDB: uppercase then right-pad into a 2-wide field. - std::string e = g().element.name(); - for (char &c : e) c = std::toupper((unsigned char)c); - if (e.size() < 2) e.insert(e.begin(), 2 - e.size(), ' '); - std::snprintf(_elem_buf, sizeof(_elem_buf), "%s", e.c_str()); - return _elem_buf; - } - inline void Atom::SetElementName(const Element elName) { g().element = gemmi::Element(elName); } - inline pstr Atom::GetChainID() { return res ? res->GetChainID() : mmdb_empty_pstr(); } - inline int Atom::GetSeqNum() { return res ? res->GetSeqNum() : 0; } - inline Chain *Atom::GetChain() { return res ? res->GetChain() : nullptr; } - inline Model *Atom::GetModel() { return (res && res->chain) ? res->chain->model : nullptr; } - inline pstr Atom::GetLabelCompID() { return res ? res->GetLabelCompID() : nullptr; } - inline pstr Atom::GetLabelAsymID() { return res ? res->GetLabelAsymID() : nullptr; } - inline int Atom::GetLabelSeqID() { return res ? res->GetLabelSeqID() : 0; } - inline int Atom::GetLabelEntityID() { return res ? res->GetLabelEntityID() : 0; } - inline int Atom::GetResidueNo() { return res ? res->GetResidueNo() : 0; } - inline int Atom::GetSSEType() { return res ? res->SSE : SSE_None; } - inline bool Atom::isSolvent() { return res ? res->isSolvent() : false; } - inline bool Atom::isNTerminus() { return res ? res->isNTerminus() : false; } - inline bool Atom::isCTerminus() { return res ? res->isCTerminus() : false; } - inline pstr Atom::GetInsCode() { return res ? res->GetInsCode() : mmdb_empty_pstr(); } - inline pstr Atom::GetResName() { return res ? res->GetResName() : mmdb_empty_pstr(); } - inline int Atom::GetModelNum() { return res ? res->GetModelNum() : 0; } - inline int Atom::GetIndex() { return ai; } - inline void Atom::SetCoordinates(realtype xx, realtype yy, realtype zz, - realtype occ, realtype tF) { - auto &a = g(); - a.pos = gemmi::Position(xx, yy, zz); - a.occ = (float)occ; - a.b_iso = (float)tF; - } - - // ---- Residue out-of-line ---- - inline pstr Residue::GetResName() { - std::snprintf(_resname_buf, sizeof(_resname_buf), "%s", g().name.c_str()); - return _resname_buf; - } - inline int &Residue::GetSeqNum() { return g().seqid.num.value; } - inline pstr Residue::GetInsCode() { - _inscode_buf[0] = g().seqid.icode == ' ' ? '\0' : g().seqid.icode; - _inscode_buf[1] = '\0'; - return _inscode_buf; - } - inline pstr Residue::GetChainID() { return chain ? chain->GetChainID() : mmdb_empty_pstr(); } - inline int Residue::GetModelNum() { return (chain && chain->model) ? chain->model->GetSerNum() : 0; } - inline PAtom Residue::GetAtom(const AtomName aname, const Element elname, const AltLoc aloc) { - // MMDB matches the PDB-column-aligned 4-char name (real Coot calls - // `GetAtom(" CA ")`), but gemmi stores names trimmed ("CA"). Trim the query so - // both padded and unpadded lookups resolve — mirrors the selection matchers - // (detail::inList / SelectAtoms), which already trim both sides. Element/altLoc - // still disambiguate when supplied (e.g. carbon-alpha " CA " vs calcium "CA ", - // which share a trimmed name). - const std::string want = aname ? gemmi::trim_str(aname) : std::string(); - for (Atom *a : atoms) { - if (std::string(a->g().name) != want) continue; - if (elname && *elname && a->g().element.name() != std::string(elname)) continue; - if (aloc && *aloc && a->g().altloc != aloc[0]) continue; - return a; - } - return nullptr; - } - inline PAtom Residue::AddAtom(Manager &m, gemmi::Atom a) { - g().atoms.push_back(std::move(a)); - Atom *aw = m.newAtom(); - aw->mgr = &m; - aw->res = this; - aw->ai = (int)atoms.size(); - atoms.push_back(aw); - return aw; - } - // Adopt a Coot-`new`d detached atom (the `new mmdb::Atom; …; res->AddAtom(at)` - // idiom). Copy its local gemmi into this residue, rebind the wrapper, and — when - // this residue is manager-bound — transfer ownership to the manager so `~Manager` - // frees it (MMDB semantics); `~Atom` drops it back out on an early Coot `delete`. - inline int Residue::AddAtom(PAtom atm) { - g().atoms.push_back(atm->_local); - atm->res = this; - atm->mgr = mgr; - atm->ai = (int)atoms.size(); - if (atm->_altloc_buf[0]) g().atoms[atm->ai].altloc = atm->_altloc_buf[0]; - atoms.push_back(atm); - if (mgr) mgr->_atom_allocs.insert(atm); - _sync_atom(); - return 0; - } - inline void Residue::DeleteAtom(int pos) { - if (pos < 0 || pos >= (int)atoms.size()) return; - g().atoms.erase(g().atoms.begin() + pos); - atoms[pos]->alive = false; - atoms[pos]->ai = -1; - atoms.erase(atoms.begin() + pos); - for (int k = pos; k < (int)atoms.size(); ++k) atoms[k]->ai = k; - } - - // Unlink one atom wrapper from this residue without freeing it: erase from the - // wrapper table AND the parallel gemmi atom vector (kept in lockstep), then - // reindex trailing atoms. Used by ~Atom when Coot `delete`s a live atom. - inline void Residue::_detach_atom(Atom *a) { - auto it = std::find(atoms.begin(), atoms.end(), a); - if (it == atoms.end()) return; - int pos = (int)(it - atoms.begin()); - if (pos < (int)g().atoms.size()) g().atoms.erase(g().atoms.begin() + pos); - atoms.erase(atoms.begin() + pos); - for (int k = pos; k < (int)atoms.size(); ++k) atoms[k]->ai = k; - } - - // Coot's `delete atom;` removes an atom from the hierarchy. Detach it from the - // parent residue, the manager/model flat lists, and any selections so no stale - // pointer survives; then drop it from the ownership set. A no-op during teardown - // (memory is freed wholesale by ~Manager) and for never-adopted detached atoms. - inline Atom::~Atom() { - if (!mgr || mgr->_bulk_free) return; - Manager *m = mgr; - if (res) { - Model *mod = (res->chain ? res->chain->model : nullptr); - res->_detach_atom(this); - if (mod) { - auto &ma = mod->all_atoms; - ma.erase(std::remove(ma.begin(), ma.end(), this), ma.end()); - } - } - auto &aa = m->all_atoms; - aa.erase(std::remove(aa.begin(), aa.end(), this), aa.end()); - for (int h = 1; h <= (int)m->selections.size(); ++h) { - if (isInSelection(h)) { - auto &sa = m->selections[h - 1].atoms; - sa.erase(std::remove(sa.begin(), sa.end(), this), sa.end()); - } - } - m->_atom_allocs.erase(this); - } - - // Coot's `delete residue_p;` (and Chain::DeleteResidue) removes a residue. Free its - // atoms (MMDB: deleting a residue deletes its atoms), then DEFER the structural - // removal: null this residue's slot in the parent chain but keep the gemmi - // placeholder so siblings' `ri` stays valid; _compact_residues drops both. A no-op - // during Manager teardown (memory is freed wholesale by ~Manager). - inline Residue::~Residue() { - if (!mgr || mgr->_bulk_free) return; - Manager *m = mgr; - // free my atoms: null each atom's res first so ~Atom doesn't mutate this->atoms - // mid-iteration (~Atom still cleans all_atoms/model/selections/registry). - std::vector ats = atoms; - atoms.clear(); - for (Atom *a : ats) { - a->res = nullptr; - delete a; - } - // tombstone my slot in the parent chain (keep the gemmi placeholder residue) - if (chain) { - auto &rv = chain->residues; - for (size_t i = 0; i < rv.size(); ++i) - if (rv[i] == this) { - rv[i] = nullptr; - break; - } - } - m->_res_allocs.erase(this); - } - - inline void Chain::_compact_residues() { - // Drop tombstoned (null) wrapper slots and their gemmi placeholder residues in - // lock-step (wrapper[i] <-> g().residues[i]); then reindex ri to the new order. - bool any_null = false; - for (Residue *r : residues) - if (!r) { - any_null = true; - break; - } - if (!any_null) return; - std::vector keptw; - std::vector keptg; - gemmi::Chain &gc = g(); - keptw.reserve(residues.size()); - keptg.reserve(gc.residues.size()); - for (size_t i = 0; i < residues.size(); ++i) { - if (residues[i]) { - keptw.push_back(residues[i]); - if (i < gc.residues.size()) keptg.push_back(std::move(gc.residues[i])); - } - } - residues.swap(keptw); - gc.residues.swap(keptg); - for (int k = 0; k < (int)residues.size(); ++k) residues[k]->ri = k; - } - - // ---- Chain out-of-line ---- - inline bool Chain::isAminoacidChain() { - for (Residue *r : residues) - if (r && r->isAminoacid()) return true; - return false; - } - inline bool Chain::isNucleotideChain() { - for (Residue *r : residues) - if (r && r->isNucleotide()) return true; - return false; - } - inline bool Chain::isSolventChain() { - if (residues.empty()) return false; - for (Residue *r : residues) - if (r && !r->isSolvent()) return false; - return true; - } - inline pstr Chain::GetChainID() { - std::snprintf(_chainid_buf, sizeof(_chainid_buf), "%s", g().name.c_str()); - return _chainid_buf; - } - inline PResidue Chain::AddResidue(Manager &m, gemmi::Residue r) { - g().residues.push_back(std::move(r)); - Residue *rw = m.newRes(); - rw->mgr = &m; - rw->chain = this; - rw->ri = (int)residues.size(); - for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { - Atom *aw = m.newAtom(); - aw->mgr = &m; - aw->res = rw; - aw->ai = ai; - rw->atoms.push_back(aw); - } - residues.push_back(rw); - return rw; - } - inline PResidue Chain::InsResidue(Manager &m, int pos, gemmi::Residue r) { - _compact_residues(); // don't insert/reindex across deferred-delete tombstones - g().residues.insert(g().residues.begin() + pos, std::move(r)); - Residue *rw = m.newRes(); - rw->mgr = &m; - rw->chain = this; - rw->ri = pos; - residues.insert(residues.begin() + pos, rw); - for (int k = pos + 1; k < (int)residues.size(); ++k) residues[k]->ri = k; - for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { - Atom *aw = m.newAtom(); - aw->mgr = &m; - aw->res = rw; - aw->ai = ai; - rw->atoms.push_back(aw); - } - return rw; - } - - // ---- Model out-of-line ---- - inline PChain Model::GetChain(const ChainID chID) { - for (Chain *c : chains) - if (c->g().name == chID) return c; - return nullptr; - } - - // ---- Manager out-of-line ---- - inline void Manager::build_from_gemmi() { - models.clear(); - all_atoms.clear(); - for (int mi = 0; mi < (int)st.models.size(); ++mi) { - Model *mw = newModel(); - mw->mgr = this; - mw->mi = mi; - auto &gm = st.models[mi]; - for (int ci = 0; ci < (int)gm.chains.size(); ++ci) { - Chain *cw = newChain(); - cw->mgr = this; - cw->model = mw; - cw->ci = ci; - auto &gc = gm.chains[ci]; - for (int ri = 0; ri < (int)gc.residues.size(); ++ri) { - Residue *rw = newRes(); - rw->mgr = this; - rw->chain = cw; - rw->ri = ri; - auto &gr = gc.residues[ri]; - for (int ai = 0; ai < (int)gr.atoms.size(); ++ai) { - Atom *aw = newAtom(); - aw->mgr = this; - aw->res = rw; - aw->ai = ai; - aw->WhatIsSet = ASET_Coordinates | ASET_Occupancy | ASET_tempFactor; - const gemmi::SMat33 &an = gr.atoms[ai].aniso; - if (an.u11 != 0.f || an.u22 != 0.f || an.u33 != 0.f) aw->WhatIsSet |= ASET_Anis_tFac; - rw->atoms.push_back(aw); - all_atoms.push_back(aw); - mw->all_atoms.push_back(aw); - } - rw->_sync_atom(); - rw->_load_id(); - cw->residues.push_back(rw); - } - mw->chains.push_back(cw); - } - models.push_back(mw); - } - _load_metadata(); - } - - // Map gemmi's structure-level metadata (connections / cispeps / helices / - // sheets) onto the MMDB per-Model record containers. gemmi is the reader; the - // shim just re-shapes. Connections/helices/sheets are not model-scoped in gemmi, - // so they go on model 1 (MMDB's usual home); cispeps honour their model_num. - inline void Manager::_load_metadata() { - link_pool.clear(); - linkr_pool.clear(); - cispep_pool.clear(); - helix_pool.clear(); - sheet_pool.clear(); - strand_pool.clear(); - strandarr_pool.clear(); - author_pool.clear(); - - // PDB title AUTHOR records (gemmi meta.authors) - title.author.data.clear(); - for (const std::string &au : st.meta.authors) { - author_pool.emplace_back(); - std::snprintf(author_pool.back().Line, sizeof(author_pool.back().Line), "%s", au.c_str()); - title.author.data.push_back(&author_pool.back()); - } - if (models.empty()) return; - - auto fill_ends = [](const gemmi::AtomAddress &a, ChainID &cid, ResName &rn, - int &seq, InsCode &ic, AtomName *an, AltLoc *al) { - std::snprintf(cid, sizeof(ChainID), "%s", a.chain_name.c_str()); - std::snprintf(rn, sizeof(ResName), "%s", a.res_id.name.c_str()); - seq = a.res_id.seqid.num.value; - ic[0] = (a.res_id.seqid.icode && a.res_id.seqid.icode != ' ') ? a.res_id.seqid.icode : '\0'; - ic[1] = '\0'; - if (an) std::snprintf(*an, sizeof(AtomName), "%s", a.atom_name.c_str()); - if (al) { - (*al)[0] = a.altloc ? a.altloc : '\0'; - (*al)[1] = '\0'; - } - }; - - // --- LINK records (gemmi Connection) -> model 1 --- - Model *m1 = models[0]; - for (const gemmi::Connection &cn : st.connections) { - link_pool.emplace_back(); - Link &l = link_pool.back(); - fill_ends(cn.partner1, l.chainID1, l.resName1, l.seqNum1, l.insCode1, &l.atName1, &l.aloc1); - fill_ends(cn.partner2, l.chainID2, l.resName2, l.seqNum2, l.insCode2, &l.atName2, &l.aloc2); - l.dist = cn.reported_distance; - m1->_links.push_back(&l); - // a connection carrying a Refmac link id is also a LINKR record - if (!cn.link_id.empty()) { - linkr_pool.emplace_back(); - LinkR &lr = linkr_pool.back(); - std::snprintf(lr.linkRID, sizeof(lr.linkRID), "%s", cn.link_id.c_str()); - AtomName an; - AltLoc al; - fill_ends(cn.partner1, lr.chainID1, lr.resName1, lr.seqNum1, lr.insCode1, &an, &al); - std::snprintf(lr.atName1, sizeof(AtomName), "%s", an); - std::snprintf(lr.aloc1, sizeof(AltLoc), "%s", al); - fill_ends(cn.partner2, lr.chainID2, lr.resName2, lr.seqNum2, lr.insCode2, &an, &al); - std::snprintf(lr.atName2, sizeof(AtomName), "%s", an); - std::snprintf(lr.aloc2, sizeof(AltLoc), "%s", al); - lr.dist = cn.reported_distance; - m1->_linkrs.push_back(&lr); - } - } - - // --- CISPEP records (gemmi CisPep) -> model by model_num (default 1) --- - for (const gemmi::CisPep &cp : st.cispeps) { - int mnum = cp.model_num > 0 ? cp.model_num : 1; - Model *mw = GetModel(mnum); - if (!mw) mw = m1; - cispep_pool.emplace_back(); - CisPep &c = cispep_pool.back(); - InsCode ic1, ic2; - int s1, s2; - fill_ends(cp.partner_c, c.chainID1, c.pep1, s1, ic1, nullptr, nullptr); - fill_ends(cp.partner_n, c.chainID2, c.pep2, s2, ic2, nullptr, nullptr); - c.seqNum1 = s1; - std::snprintf(c.icode1, sizeof(InsCode), "%s", ic1); - c.seqNum2 = s2; - std::snprintf(c.icode2, sizeof(InsCode), "%s", ic2); - c.modNum = mnum; - if (!std::isnan(cp.reported_angle)) c.measure = cp.reported_angle; - mw->_cispeps.push_back(&c); - } - - // --- HELIX records (gemmi Helix) -> model 1 --- - for (const gemmi::Helix &gh : st.helices) { - helix_pool.emplace_back(); - Helix &h = helix_pool.back(); - AtomName an; - AltLoc al; - fill_ends(gh.start, h.initChainID, h.initResName, h.initSeqNum, h.initICode, &an, &al); - fill_ends(gh.end, h.endChainID, h.endResName, h.endSeqNum, h.endICode, &an, &al); - h.helixClass = (int)gh.pdb_helix_class; - h.length = gh.length; - h.serNum = (int)helix_pool.size(); - m1->helices.AddData(&h); - } - - // --- SHEET / STRAND records (gemmi Sheet) -> model 1 --- - if (!st.sheets.empty()) { - m1->sheets.nSheets = (int)st.sheets.size(); - m1->_sheet_ptrs.assign(st.sheets.size(), nullptr); // backs Sheets::sheet (Sheet**) - for (size_t is = 0; is < st.sheets.size(); ++is) { - const gemmi::Sheet &gs = st.sheets[is]; - sheet_pool.emplace_back(); - Sheet &sh = sheet_pool.back(); - std::snprintf(sh.sheetID, sizeof(sh.sheetID), "%s", gs.name.c_str()); - sh.nStrands = (int)gs.strands.size(); - strandarr_pool.emplace_back(); - std::vector &sarr = strandarr_pool.back(); - sarr.reserve(gs.strands.size()); - for (const gemmi::Sheet::Strand &gst : gs.strands) { - strand_pool.emplace_back(); - Strand &str = strand_pool.back(); - AtomName an; - AltLoc al; - fill_ends(gst.start, str.initChainID, str.initResName, str.initSeqNum, str.initICode, &an, &al); - fill_ends(gst.end, str.endChainID, str.endResName, str.endSeqNum, str.endICode, &an, &al); - std::snprintf(str.sheetID, sizeof(str.sheetID), "%s", gs.name.c_str()); - str.strandNo = (int)sarr.size() + 1; - str.sense = gst.sense; - sarr.push_back(&str); - } - sh.strand = sarr.data(); - m1->_sheet_ptrs[is] = &sh; - } - m1->sheets.sheet = m1->_sheet_ptrs.data(); - } - } - - // ---- Manager::PutAtom (hierarchy insertion) ---- - inline int Manager::PutAtom(int index, PAtom A, int serNum) { - if (!A) return 0; - Residue *src = A->res; - // ensure a model exists (Coot calls PutAtom on a fresh, empty Manager) - Model *mw = models.empty() ? nullptr : models[0]; - if (!mw) { - st.models.emplace_back(1); - mw = newModel(); - mw->mgr = this; - mw->mi = 0; - models.push_back(mw); - } - // find or create the chain implied by the source atom's chain - std::string cid = (src && src->chain) ? src->chain->g().name : std::string("A"); - Chain *cw = mw->GetChain(cid.c_str()); - if (!cw) cw = mw->CreateChain(cid.c_str()); - // find or create the residue implied by (seqNum, insCode) - int seq = src ? src->g().seqid.num.value : 0; - char ic = src ? src->g().seqid.icode : ' '; - char icn = ic ? ic : ' '; - Residue *rw = nullptr; - for (Residue *r : cw->residues) { - gemmi::Residue &gr = r->g(); - if (gr.seqid.num.value == seq && (gr.seqid.icode ? gr.seqid.icode : ' ') == icn) { - rw = r; - break; - } - } - if (!rw) { - gemmi::Residue gr; - gr.name = src ? src->g().name : std::string("UNK"); - gr.seqid.num = seq; - gr.seqid.icode = icn; - rw = cw->AddResidue(*this, gr); - rw->_load_id(); - } - // append a copy of the atom's gemmi backing + register it in the flat tables - Atom *aw = rw->AddAtom(*this, A->g()); - aw->WhatIsSet = A->WhatIsSet; - aw->Het = A->Het; - std::memcpy(aw->segID, A->segID, sizeof aw->segID); - aw->g().serial = serNum ? serNum : (index > 0 ? index : (int)all_atoms.size() + 1); - rw->_sync_atom(); - all_atoms.push_back(aw); - mw->all_atoms.push_back(aw); - return (int)all_atoms.size(); // 1-based position (GetAtomI(pos) returns aw) - } - - // ---- selection matching ---- - namespace detail { - inline std::string trimws(const std::string &s) { - size_t a = s.find_first_not_of(' '), b = s.find_last_not_of(' '); - return a == std::string::npos ? std::string() : s.substr(a, b - a + 1); - } - // Whitespace-insensitive membership test. MMDB atom names are stored space- - // padded ("_CA_", "_O__"), while CID/selection queries are unpadded ("CA", - // "O"); real MMDB matches them regardless of padding, so trim both sides. - // Harmless for chain IDs / residue / element names (already unpadded). - inline bool inList(cpstr list, const std::string &v) { - if (!list || !*list || std::strcmp(list, "*") == 0) return true; - // MMDB negation: a leading '!' inverts the match (e.g. "!HOH" = any residue - // that is not water). Coot's Select() uses this for chain/residue/element/ - // atom-name filters; without it every residue is (wrongly) excluded. - if (list[0] == '!') return !inList(list + 1, v); - std::string vt = trimws(v); - const char *p = list; - while (*p) { - const char *c = std::strchr(p, ','); - std::string tok(p, c ? (size_t)(c - p) : std::strlen(p)); - if (trimws(tok) == vt) return true; - if (!c) break; - p = c + 1; - } - return false; - } - inline bool altMatch(cpstr list, char alt) { - if (!list || std::strcmp(list, "*") == 0) return true; - std::string a = alt ? std::string(1, alt) : std::string(); - if (!*list) return a.empty(); // "" -> only blank altLoc - return inList(list, a); - } - } // namespace detail - - inline void Manager::Select(int selHnd, SELECTION_TYPE sType, int iModel, - cpstr Chains, int ResNo1, cpstr Ins1, int ResNo2, cpstr Ins2, cpstr RNames, - cpstr ANames, cpstr Elements, cpstr altLocs, SELECTION_KEY selKey) { - Selection &sel = selections[selHnd - 1]; - if (sel.type == STYPE_UNDEFINED) sel.type = sType; - std::vector oldA = sel.atoms; - std::vector oldR = sel.residues; - std::vector oldC = sel.chains; - - std::vector mAtoms; - std::vector mResidues; - std::vector mChains; - for (Model *mw : models) { - if (iModel > 0 && mw->GetSerNum() != iModel) continue; - for (Chain *cw : mw->chains) { - if (!detail::inList(Chains, cw->g().name)) continue; - bool anyResidue = false; - for (Residue *rw : cw->residues) { - int sn = rw->g().seqid.num.value; - char ric = rw->g().seqid.icode ? rw->g().seqid.icode : ' '; - // (seqNum, insCode) range: an explicit insCode only constrains the - // boundary residue; blank/"*" includes every insCode at that seqNum. - if (ResNo1 != ANY_RES) { - if (sn < ResNo1) continue; - if (sn == ResNo1 && Ins1 && Ins1[0] && std::strcmp(Ins1, "*") && ric < Ins1[0]) continue; - } - if (ResNo2 != ANY_RES) { - if (sn > ResNo2) continue; - if (sn == ResNo2 && Ins2 && Ins2[0] && std::strcmp(Ins2, "*") && ric > Ins2[0]) continue; - } - if (!detail::inList(RNames, rw->g().name)) continue; - bool anyAtom = false; - for (Atom *aw : rw->atoms) { - if (!detail::inList(ANames, aw->g().name)) continue; - if (!detail::inList(Elements, aw->g().element.name())) continue; - if (!detail::altMatch(altLocs, aw->g().altloc)) continue; - anyAtom = true; - if (sType == STYPE_ATOM) mAtoms.push_back(aw); - } - if (anyAtom) anyResidue = true; - if (anyAtom && sType == STYPE_RESIDUE) mResidues.push_back(rw); - } - // STYPE_CHAIN: a chain matching the chain filter (and, if given, having a - // residue that passes the residue/atom filters) is selected whole. - if (sType == STYPE_CHAIN && anyResidue) mChains.push_back(cw); - } - } - auto combine = [&](auto &cur, auto &matched) { - using Vec = typename std::decay::type; - std::set curset(cur.begin(), cur.end()); - std::set mset(matched.begin(), matched.end()); - if (selKey == SKEY_NEW) { - cur = matched; - } else if (selKey == SKEY_OR) { - for (auto *x : matched) - if (!curset.count(x)) cur.push_back(x); - } else if (selKey == SKEY_AND) { - Vec o; - for (auto *x : cur) - if (mset.count(x)) o.push_back(x); - cur = o; - } else if (selKey == SKEY_XOR) { - Vec o; - for (auto *x : cur) - if (!mset.count(x)) o.push_back(x); - for (auto *x : matched) - if (!curset.count(x)) o.push_back(x); - cur = o; - } else if (selKey == SKEY_CLR) { - Vec o; - for (auto *x : cur) - if (!mset.count(x)) o.push_back(x); - cur = o; - } - }; - if (sType == STYPE_ATOM) - combine(sel.atoms, mAtoms); - else if (sType == STYPE_RESIDUE) - combine(sel.residues, mResidues); - else if (sType == STYPE_CHAIN) - combine(sel.chains, mChains); - for (Atom *a : oldA) a->_setInSel(selHnd, false); - for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); - for (Residue *r : oldR) r->_setInSel(selHnd, false); - for (Residue *r : sel.residues) r->_setInSel(selHnd, true); - for (Chain *c : oldC) c->_setInSel(selHnd, false); - for (Chain *c : sel.chains) c->_setInSel(selHnd, true); - } - - // select-from-selection: combine selHnd2's contents into selHnd1 - inline void Manager::Select(int selHnd1, SELECTION_TYPE sType, int selHnd2, - SELECTION_KEY sKey) { - Selection &s1 = selections[selHnd1 - 1]; - Selection &s2 = selections[selHnd2 - 1]; - if (s1.type == STYPE_UNDEFINED) s1.type = sType; - std::vector oldA = s1.atoms; - std::vector oldR = s1.residues; - auto combine = [&](auto &cur, auto &m) { - using Vec = typename std::decay::type; - std::set curset(cur.begin(), cur.end()); - std::set mset(m.begin(), m.end()); - if (sKey == SKEY_NEW) - cur = m; - else if (sKey == SKEY_OR) { - for (auto *x : m) - if (!curset.count(x)) cur.push_back(x); - } else if (sKey == SKEY_AND) { - Vec o; - for (auto *x : cur) - if (mset.count(x)) o.push_back(x); - cur = o; - } else if (sKey == SKEY_XOR) { - Vec o; - for (auto *x : cur) - if (!mset.count(x)) o.push_back(x); - for (auto *x : m) - if (!curset.count(x)) o.push_back(x); - cur = o; - } else if (sKey == SKEY_CLR) { - Vec o; - for (auto *x : cur) - if (!mset.count(x)) o.push_back(x); - cur = o; - } - }; - if (sType == STYPE_ATOM) - combine(s1.atoms, s2.atoms); - else if (sType == STYPE_RESIDUE) - combine(s1.residues, s2.residues); - for (Atom *a : oldA) a->_setInSel(selHnd1, false); - for (Atom *a : s1.atoms) a->_setInSel(selHnd1, true); - for (Residue *r : oldR) r->_setInSel(selHnd1, false); - for (Residue *r : s1.residues) r->_setInSel(selHnd1, true); - } - - inline void Manager::SelectAtom(int selHnd, PAtom atom, SELECTION_KEY sKey, bool) { - Selection &sel = selections[selHnd - 1]; - if (sel.type == STYPE_UNDEFINED) sel.type = STYPE_ATOM; - if (sKey == SKEY_NEW) { - for (Atom *a : sel.atoms) a->_setInSel(selHnd, false); - sel.atoms.clear(); - } - if (atom && !atom->isInSelection(selHnd)) { - sel.atoms.push_back(atom); - atom->_setInSel(selHnd, true); - } - } - - // Pragmatic CID parser: "/model/chain/seqNum1[.ins1]-seqNum2[.ins2]/atom" - // (best-effort; strips (resname)/[element]/:altloc suffixes; parses insertion - // codes after '.'). Not the full MMDB CID grammar but covers Coot's usage. - inline void Manager::Select(int selHnd, SELECTION_TYPE sType, cpstr CID, - SELECTION_KEY sKey) { - std::string s = CID ? CID : ""; - std::vector t; - size_t p = (!s.empty() && s[0] == '/') ? 1 : 0; - while (p <= s.size()) { - size_t q = s.find('/', p); - t.push_back(s.substr(p, q == std::string::npos ? std::string::npos : q - p)); - if (q == std::string::npos) break; - p = q + 1; - } - auto tok = [&](size_t i) { return i < t.size() ? t[i] : std::string(); }; - auto strip = [](std::string v, const char *seps) { - size_t c = v.find_first_of(seps); - return c == std::string::npos ? v : v.substr(0, c); - }; - // Assign tokens to model/chain/residue/atom. A leading '/' (or any '/') means - // the model field is present at tok(0). A slash-less CID has NO model/chain - // prefix: MMDB reads a bare numeric token as a residue seqNum ("262" = residue - // 262 in every chain), and a bare non-numeric token as a chain id ("A"). - std::string model_s, chain_s, res_s, atom_s; - if (s.find('/') != std::string::npos) { - model_s = tok(0); - chain_s = tok(1); - res_s = tok(2); - atom_s = tok(3); - } else { - const std::string only = tok(0); - if (!only.empty() && (std::isdigit((unsigned char)only[0]) || only[0] == '-')) - res_s = only; - else - chain_s = only; - } - int iModel = 0; - if (!model_s.empty() && model_s != "*" && model_s != "0") iModel = atoi(model_s.c_str()); - std::string chains = chain_s.empty() ? "*" : chain_s; - int r1 = ANY_RES, r2 = ANY_RES; - std::string ins1 = "*", ins2 = "*"; - // split "num[.ins]" into number + insertion code - auto parse_resid = [](const std::string &v, int &num, std::string &ins) { - size_t dot = v.find('.'); - num = atoi(v.substr(0, dot).c_str()); - ins = (dot == std::string::npos) ? std::string() : v.substr(dot + 1); - }; - std::string rr = strip(res_s, "("); // drop (resname) - if (!rr.empty() && rr != "*") { - size_t dash = rr.find('-', rr[0] == '-' ? 1 : 0); - if (dash == std::string::npos) { - parse_resid(rr, r1, ins1); - r2 = r1; - ins2 = ins1; - } else { - parse_resid(rr.substr(0, dash), r1, ins1); - parse_resid(rr.substr(dash + 1), r2, ins2); - } - } - std::string anames = strip(strip(atom_s, "["), ":"); // drop [element]/:altloc - if (anames.empty()) anames = "*"; - Select(selHnd, sType, iModel, chains.c_str(), r1, ins1.c_str(), r2, ins2.c_str(), "*", - anames.c_str(), "*", "*", sKey); - } - - inline int Manager::GetNumberOfAtoms(cpstr CID) { - int h = NewSelection(); - Select(h, STYPE_ATOM, CID, SKEY_NEW); - int n = (int)selections[h - 1].atoms.size(); - DeleteSelection(h); - return n; - } - - inline void Manager::GetAtomStatistics(int selHnd, RAtomStat AS) { - AS = AtomStat(); - std::vector &atoms = selections[selHnd - 1].atoms; - AS.nAtoms = (int)atoms.size(); - if (atoms.empty()) return; - double sx = 0, sy = 0, sz = 0; - AS.xmin = AS.xmax = atoms[0]->x(); - AS.ymin = AS.ymax = atoms[0]->y(); - AS.zmin = AS.zmax = atoms[0]->z(); - for (Atom *a : atoms) { - double X = a->x(), Y = a->y(), Z = a->z(); - sx += X; - sy += Y; - sz += Z; - AS.xmin = X < AS.xmin ? X : AS.xmin; - AS.xmax = X > AS.xmax ? X : AS.xmax; - AS.ymin = Y < AS.ymin ? Y : AS.ymin; - AS.ymax = Y > AS.ymax ? Y : AS.ymax; - AS.zmin = Z < AS.zmin ? Z : AS.zmin; - AS.zmax = Z > AS.zmax ? Z : AS.zmax; - } - AS.xm = sx / atoms.size(); - AS.ym = sy / atoms.size(); - AS.zm = sz / atoms.size(); - } - - inline void Manager::SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, - realtype y, realtype z, realtype r, SELECTION_KEY sKey) { - Selection &sel = selections[selHnd - 1]; - if (sel.type == STYPE_UNDEFINED) sel.type = sType; - std::vector oldA = sel.atoms; - std::vector oldR = sel.residues; - gemmi::Position c(x, y, z); - double r2 = r * r; - std::vector mAtoms; - std::vector mResidues; - for (Model *mw : models) - for (Chain *cw : mw->chains) - for (Residue *rw : cw->residues) { - bool any = false; - for (Atom *aw : rw->atoms) - if (aw->g().pos.dist_sq(c) <= r2) { - any = true; - if (sType == STYPE_ATOM) mAtoms.push_back(aw); - } - if (any && sType == STYPE_RESIDUE) mResidues.push_back(rw); - } - auto combine = [&](auto &cur, auto &m) { - std::set::type::value_type> cs(cur.begin(), cur.end()); - if (sKey == SKEY_NEW) - cur = m; - else if (sKey == SKEY_OR) { - for (auto *p : m) - if (!cs.count(p)) cur.push_back(p); - } - }; - if (sType == STYPE_ATOM) - combine(sel.atoms, mAtoms); - else if (sType == STYPE_RESIDUE) - combine(sel.residues, mResidues); - for (Atom *a : oldA) a->_setInSel(selHnd, false); - for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); - for (Residue *r : oldR) r->_setInSel(selHnd, false); - for (Residue *r : sel.residues) r->_setInSel(selHnd, true); - } - - // SeekContacts (both overloads) is defined in mmdb-shim/src/contacts.cc using - // gemmi::NeighborSearch — keeps the heavy neighbor.hpp out of Coot's many TUs. - - // ---- detached-construction constructors + subtree ops (need complete types) ---- - inline Atom::Atom(Residue *r) { - if (r) r->AddAtom(this); - } - inline Residue::Residue(Chain *c) { - if (c) c->AddResidue(this); - } - inline Chain::Chain(Model *m, const ChainID id) { - if (m) m->AddChain(this); - SetChainID(id); - } - - // peptide-bond distance threshold for backbone C-N (a real bond is ~1.33 A). - inline bool Residue::isNTerminus() { - if (!chain || ri <= 0) return true; // first (or detached) residue - Residue *prev = chain->residues[ri - 1]; - if (!prev) return true; // previous slot is a deferred-delete tombstone - const gemmi::Atom *N = g().get_n(); - const gemmi::Atom *prevC = prev->g().get_c(); - if (!N || !prevC) return true; // missing backbone -> terminus - return N->pos.dist(prevC->pos) > 1.7; // not bonded to previous C - } - inline bool Residue::isCTerminus() { - if (!chain || ri < 0 || ri >= (int)chain->residues.size() - 1) return true; // last/detached - Residue *next = chain->residues[ri + 1]; - if (!next) return true; // next slot is a deferred-delete tombstone - const gemmi::Atom *C = g().get_c(); - const gemmi::Atom *nextN = next->g().get_n(); - if (!C || !nextN) return true; - return C->pos.dist(nextN->pos) > 1.7; // not bonded to next N - } - inline Model *Residue::GetModel() { return chain ? chain->model : nullptr; } - - inline void Chain::Copy(PChain src) { - Manager *pool = mgr ? mgr : src->mgr; - g() = src->g(); // deep gemmi copy (residues + atoms) - residues.clear(); - if (!pool) return; - gemmi::Chain &gc = g(); - for (int r = 0; r < (int)gc.residues.size(); ++r) { - Residue *rw = pool->newRes(); - rw->mgr = mgr; - rw->chain = this; - rw->ri = r; - for (int a = 0; a < (int)gc.residues[r].atoms.size(); ++a) { - Atom *aw = pool->newAtom(); - aw->mgr = mgr; - aw->res = rw; - aw->ai = a; - rw->atoms.push_back(aw); - } - rw->_sync_atom(); - rw->_load_id(); - residues.push_back(rw); - } - } - - inline void Model::Copy(PModel src) { - Manager *pool = mgr ? mgr : src->mgr; - g() = src->g(); - chains.clear(); - if (!pool) return; - gemmi::Model &gm = g(); - for (int c = 0; c < (int)gm.chains.size(); ++c) { - Chain *cw = pool->newChain(); - cw->mgr = mgr; - cw->model = this; - cw->ci = c; - for (int r = 0; r < (int)gm.chains[c].residues.size(); ++r) { - Residue *rw = pool->newRes(); - rw->mgr = mgr; - rw->chain = cw; - rw->ri = r; - for (int a = 0; a < (int)gm.chains[c].residues[r].atoms.size(); ++a) { - Atom *aw = pool->newAtom(); - aw->mgr = mgr; - aw->res = rw; - aw->ai = a; - rw->atoms.push_back(aw); - } - rw->_sync_atom(); - rw->_load_id(); - cw->residues.push_back(rw); - } - chains.push_back(cw); - } - } - - inline PChain Model::CreateChain(const ChainID id) { - Chain *c = mgr ? mgr->newChain() : new Chain(); - c->mgr = mgr; - c->model = this; - c->ci = (int)chains.size(); - g().chains.emplace_back(id ? id : ""); - chains.push_back(c); - return c; - } - - inline pstr Atom::GetAtomID(pstr S) { - if (S) std::snprintf(S, 100, "/%d/%s/%d(%s)/%s", GetModelNum(), GetChainID(), - res ? res->GetSeqNum() : 0, GetResName(), GetAtomName()); - return S; - } - - // one-letter residue code (mmdb_tables.h) via gemmi's tabulated residues - inline void Get1LetterCode(cpstr res3, pstr res1) { - if (!res1) return; - char c = gemmi::find_tabulated_residue(res3 ? res3 : "").one_letter_code; - res1[0] = c ? (char)std::toupper((unsigned char)c) : 'X'; - res1[1] = '\0'; - } - inline void Get1LetterCode(cpstr res3, char &res1) { - char b[2]; - Get1LetterCode(res3, b); - res1 = b[0]; - } - - // sort a contact array by distance (mmdb_coormngr.h SortContacts) — sortkey ignored - inline void SortContacts(PContact contacts, int nContacts, int /*sortkey*/) { - if (contacts && nContacts > 1) - std::sort(contacts, contacts + nContacts, - [](const Contact &a, const Contact &b) { return a.dist < b.dist; }); - } - - // centroid of an atom array (mmdb_coormngr.h GetMassCenter) - inline void GetMassCenter(PPAtom A, int nA, realtype &xc, realtype &yc, realtype &zc) { - double sx = 0, sy = 0, sz = 0; - int n = 0; - for (int i = 0; i < nA; ++i) - if (A[i]) { - sx += A[i]->x(); - sy += A[i]->y(); - sz += A[i]->z(); - ++n; - } - if (n) { - xc = sx / n; - yc = sy / n; - zc = sz / n; - } else { - xc = yc = zc = 0; - } - } - -} // namespace mmdb +#include "_shim_types.hh" +#include "_shim_hierarchy.hh" +#include "_shim_manager.hh" +#include "_shim_inline.hh" // mmdb::mmcif::* (thin veneer over gemmi::cif) — re-opens mmdb{mmcif{...}}. -// pstr/cpstr/realtype are already in scope from the headers above. +// pstr/cpstr/realtype are already in scope from the layers above. #include "_mmcif_impl.hh" // mmdb::math::{Vertex,Edge,Graph,GraphMatch} — molecular graph + subgraph match. -// Included after the mmdb namespace close so Atom/Residue are complete (MakeGraph). +// Included last so Atom/Residue are complete (MakeGraph). #include "_graph_impl.hh" diff --git a/mmdb-shim/include/mmdb2/_shim_inline.hh b/mmdb-shim/include/mmdb2/_shim_inline.hh new file mode 100644 index 0000000000..fd19356ccb --- /dev/null +++ b/mmdb-shim/include/mmdb2/_shim_inline.hh @@ -0,0 +1,1061 @@ +// mmdb-shim — layer 4 of 4: out-of-line definitions. +// +// Everything here needs one or more complete classes from the layers above: the +// g() resolvers (detached wrapper -> _local, else parent's gemmi vector), the +// UDData put/get helpers, the Atom/Residue/Chain/Model/Manager methods that touch +// siblings or the Manager, the detached-construction constructors, the CID/atom +// selection matchers (namespace detail), and the free helper functions. +#pragma once + +#include "_shim_manager.hh" + +namespace mmdb { + + // ---- g() resolvers ---- + // A wrapper with no parent is "detached" (Coot's `new mmdb::Atom` idiom: build + // standalone, set fields, then Add*() into a parent). While detached, g() + // resolves to a wrapper-owned local gemmi object; Add*() copies that local into + // the parent's gemmi vector and rebinds (sets parent + index). Index-based + // resolution makes the vector push/reallocation harmless for siblings. + inline gemmi::Model &Model::g() const { return mgr ? mgr->st.models[mi] : const_cast(this)->_local; } + inline gemmi::Chain &Chain::g() const { return model ? model->g().chains[ci] : const_cast(this)->_local; } + inline gemmi::Residue &Residue::g() const { return chain ? chain->g().residues[ri] : const_cast(this)->_local; } + inline gemmi::Atom &Atom::g() const { + if (res && res->chain && res->chain->model && res->chain->model->mgr) { + auto &mgr = *res->chain->model->mgr; + int mi = res->chain->model->mi; + if (mi >= 0 && mi < (int)mgr.st.models.size()) { + return res->g().atoms[ai]; + } + } + return const_cast(this)->_local; + } + + // ---- UDData helpers ---- + inline Manager::UDReg *_ud_desc(Manager *mgr, UDR_TYPE myType, int handle, int kind, + int &err) { + if (!mgr || handle < 1 || handle > (int)mgr->ud_regs.size()) { + err = UDDATA_WrongHandle; + return nullptr; + } + Manager::UDReg &d = mgr->ud_regs[handle - 1]; // handles are 1-based (see _regUD) + if (d.type != myType || d.kind != kind) { + err = UDDATA_WrongUDRType; + return nullptr; + } + err = UDDATA_Ok; + return &d; + } + inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, int v) { + int e; + auto *d = _ud_desc(mgr, t, h, 0, e); + if (!d) return e; + if ((int)s._udi.size() <= d->slot) s._udi.resize(d->slot + 1, 0); + s._udi[d->slot] = v; + return UDDATA_Ok; + } + inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, realtype v) { + int e; + auto *d = _ud_desc(mgr, t, h, 1, e); + if (!d) return e; + if ((int)s._udr.size() <= d->slot) s._udr.resize(d->slot + 1, 0.0); + s._udr[d->slot] = v; + return UDDATA_Ok; + } + inline int ud_put(Manager *mgr, UDR_TYPE t, UDStore &s, int h, cpstr v) { + int e; + auto *d = _ud_desc(mgr, t, h, 2, e); + if (!d) return e; + if ((int)s._uds.size() <= d->slot) s._uds.resize(d->slot + 1); + s._uds[d->slot] = v ? v : ""; + return UDDATA_Ok; + } + inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, int &v) { + int e; + auto *d = _ud_desc(mgr, t, h, 0, e); + if (!d) return e; + if ((int)s._udi.size() <= d->slot) return UDDATA_NoData; + v = s._udi[d->slot]; + return UDDATA_Ok; + } + inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, realtype &v) { + int e; + auto *d = _ud_desc(mgr, t, h, 1, e); + if (!d) return e; + if ((int)s._udr.size() <= d->slot) return UDDATA_NoData; + v = s._udr[d->slot]; + return UDDATA_Ok; + } + inline int ud_get(Manager *mgr, UDR_TYPE t, UDStore &s, int h, pstr &v) { + int e; + auto *d = _ud_desc(mgr, t, h, 2, e); + if (!d) return e; + if ((int)s._uds.size() <= d->slot) return UDDATA_NoData; + v = (pstr)s._uds[d->slot].c_str(); + return UDDATA_Ok; // borrowed + } + + // ---- Atom out-of-line ---- + inline pstr Atom::GetAtomName() const { + // MMDB returns the PDB-column-aligned 4-char atom name (e.g. " N ", " CA ", + // " CG2"); gemmi stores the trimmed name ("N"/"CA"/"CG2"). Reproduce MMDB + // alignment via gemmi's padded_name() (left-pad by element) + right-pad to 4 + // — the exact rule gemmi's own mmdb.hpp bridge uses. Coot's atom_spec_t names + // are these 4-char strings, so returning the trimmed name breaks every lookup. + std::string padded = g().padded_name(); + if (padded.size() < 4) padded.resize(4, ' '); + std::snprintf(_name_buf, sizeof(_name_buf), "%s", padded.c_str()); + return _name_buf; + } + // Coot passes MMDB-aligned 4-char names (" CA "); gemmi stores trimmed names + // ("CA") and re-pads on output (GetAtomName / PDB write) — store trimmed so + // gemmi's own formatting stays correct. + inline void Atom::SetAtomName(const AtomName aName) { g().name = aName ? gemmi::trim_str(aName) : ""; } + inline pstr Atom::GetElementName() { + // MMDB returns the PDB-column-aligned element: 2 chars, right-justified, + // UPPERCASE (" H", " C", "NA", "FE"). gemmi's Element::name() is unpadded and + // mixed-case ("H"/"C"/"Na"/"Fe"), so Coot's element tests — e.g. + // get_number_of_hydrogen_atoms() comparing `ele == " H"` — never match. Align + // to MMDB: uppercase then right-pad into a 2-wide field. + std::string e = g().element.name(); + for (char &c : e) c = std::toupper((unsigned char)c); + if (e.size() < 2) e.insert(e.begin(), 2 - e.size(), ' '); + std::snprintf(_elem_buf, sizeof(_elem_buf), "%s", e.c_str()); + return _elem_buf; + } + inline void Atom::SetElementName(const Element elName) { g().element = gemmi::Element(elName); } + inline pstr Atom::GetChainID() { return res ? res->GetChainID() : mmdb_empty_pstr(); } + inline int Atom::GetSeqNum() { return res ? res->GetSeqNum() : 0; } + inline Chain *Atom::GetChain() { return res ? res->GetChain() : nullptr; } + inline Model *Atom::GetModel() { return (res && res->chain) ? res->chain->model : nullptr; } + inline pstr Atom::GetLabelCompID() { return res ? res->GetLabelCompID() : nullptr; } + inline pstr Atom::GetLabelAsymID() { return res ? res->GetLabelAsymID() : nullptr; } + inline int Atom::GetLabelSeqID() { return res ? res->GetLabelSeqID() : 0; } + inline int Atom::GetLabelEntityID() { return res ? res->GetLabelEntityID() : 0; } + inline int Atom::GetResidueNo() { return res ? res->GetResidueNo() : 0; } + inline int Atom::GetSSEType() { return res ? res->SSE : SSE_None; } + inline bool Atom::isSolvent() { return res ? res->isSolvent() : false; } + inline bool Atom::isNTerminus() { return res ? res->isNTerminus() : false; } + inline bool Atom::isCTerminus() { return res ? res->isCTerminus() : false; } + inline pstr Atom::GetInsCode() { return res ? res->GetInsCode() : mmdb_empty_pstr(); } + inline pstr Atom::GetResName() { return res ? res->GetResName() : mmdb_empty_pstr(); } + inline int Atom::GetModelNum() { return res ? res->GetModelNum() : 0; } + inline int Atom::GetIndex() { return ai; } + inline void Atom::SetCoordinates(realtype xx, realtype yy, realtype zz, + realtype occ, realtype tF) { + auto &a = g(); + a.pos = gemmi::Position(xx, yy, zz); + a.occ = (float)occ; + a.b_iso = (float)tF; + } + + // ---- Residue out-of-line ---- + inline pstr Residue::GetResName() { + std::snprintf(_resname_buf, sizeof(_resname_buf), "%s", g().name.c_str()); + return _resname_buf; + } + inline int &Residue::GetSeqNum() { return g().seqid.num.value; } + inline pstr Residue::GetInsCode() { + _inscode_buf[0] = g().seqid.icode == ' ' ? '\0' : g().seqid.icode; + _inscode_buf[1] = '\0'; + return _inscode_buf; + } + inline pstr Residue::GetChainID() { return chain ? chain->GetChainID() : mmdb_empty_pstr(); } + inline int Residue::GetModelNum() { return (chain && chain->model) ? chain->model->GetSerNum() : 0; } + inline PAtom Residue::GetAtom(const AtomName aname, const Element elname, const AltLoc aloc) { + // MMDB matches the PDB-column-aligned 4-char name (real Coot calls + // `GetAtom(" CA ")`), but gemmi stores names trimmed ("CA"). Trim the query so + // both padded and unpadded lookups resolve — mirrors the selection matchers + // (detail::inList / SelectAtoms), which already trim both sides. Element/altLoc + // still disambiguate when supplied (e.g. carbon-alpha " CA " vs calcium "CA ", + // which share a trimmed name). + const std::string want = aname ? gemmi::trim_str(aname) : std::string(); + for (Atom *a : atoms) { + if (std::string(a->g().name) != want) continue; + if (elname && *elname && a->g().element.name() != std::string(elname)) continue; + if (aloc && *aloc && a->g().altloc != aloc[0]) continue; + return a; + } + return nullptr; + } + inline PAtom Residue::AddAtom(Manager &m, gemmi::Atom a) { + g().atoms.push_back(std::move(a)); + Atom *aw = m.newAtom(); + aw->mgr = &m; + aw->res = this; + aw->ai = (int)atoms.size(); + atoms.push_back(aw); + return aw; + } + // Adopt a Coot-`new`d detached atom (the `new mmdb::Atom; …; res->AddAtom(at)` + // idiom). Copy its local gemmi into this residue, rebind the wrapper, and — when + // this residue is manager-bound — transfer ownership to the manager so `~Manager` + // frees it (MMDB semantics); `~Atom` drops it back out on an early Coot `delete`. + inline int Residue::AddAtom(PAtom atm) { + g().atoms.push_back(atm->_local); + atm->res = this; + atm->mgr = mgr; + atm->ai = (int)atoms.size(); + if (atm->_altloc_buf[0]) g().atoms[atm->ai].altloc = atm->_altloc_buf[0]; + atoms.push_back(atm); + if (mgr) mgr->_atom_allocs.insert(atm); + _sync_atom(); + return 0; + } + inline void Residue::DeleteAtom(int pos) { + if (pos < 0 || pos >= (int)atoms.size()) return; + g().atoms.erase(g().atoms.begin() + pos); + atoms[pos]->alive = false; + atoms[pos]->ai = -1; + atoms.erase(atoms.begin() + pos); + for (int k = pos; k < (int)atoms.size(); ++k) atoms[k]->ai = k; + } + + // Unlink one atom wrapper from this residue without freeing it: erase from the + // wrapper table AND the parallel gemmi atom vector (kept in lockstep), then + // reindex trailing atoms. Used by ~Atom when Coot `delete`s a live atom. + inline void Residue::_detach_atom(Atom *a) { + auto it = std::find(atoms.begin(), atoms.end(), a); + if (it == atoms.end()) return; + int pos = (int)(it - atoms.begin()); + if (pos < (int)g().atoms.size()) g().atoms.erase(g().atoms.begin() + pos); + atoms.erase(atoms.begin() + pos); + for (int k = pos; k < (int)atoms.size(); ++k) atoms[k]->ai = k; + } + + // Coot's `delete atom;` removes an atom from the hierarchy. Detach it from the + // parent residue, the manager/model flat lists, and any selections so no stale + // pointer survives; then drop it from the ownership set. A no-op during teardown + // (memory is freed wholesale by ~Manager) and for never-adopted detached atoms. + inline Atom::~Atom() { + if (!mgr || mgr->_bulk_free) return; + Manager *m = mgr; + if (res) { + Model *mod = (res->chain ? res->chain->model : nullptr); + res->_detach_atom(this); + if (mod) { + auto &ma = mod->all_atoms; + ma.erase(std::remove(ma.begin(), ma.end(), this), ma.end()); + } + } + auto &aa = m->all_atoms; + aa.erase(std::remove(aa.begin(), aa.end(), this), aa.end()); + for (int h = 1; h <= (int)m->selections.size(); ++h) { + if (isInSelection(h)) { + auto &sa = m->selections[h - 1].atoms; + sa.erase(std::remove(sa.begin(), sa.end(), this), sa.end()); + } + } + m->_atom_allocs.erase(this); + } + + // Coot's `delete residue_p;` (and Chain::DeleteResidue) removes a residue. Free its + // atoms (MMDB: deleting a residue deletes its atoms), then DEFER the structural + // removal: null this residue's slot in the parent chain but keep the gemmi + // placeholder so siblings' `ri` stays valid; _compact_residues drops both. A no-op + // during Manager teardown (memory is freed wholesale by ~Manager). + inline Residue::~Residue() { + if (!mgr || mgr->_bulk_free) return; + Manager *m = mgr; + // free my atoms: null each atom's res first so ~Atom doesn't mutate this->atoms + // mid-iteration (~Atom still cleans all_atoms/model/selections/registry). + std::vector ats = atoms; + atoms.clear(); + for (Atom *a : ats) { + a->res = nullptr; + delete a; + } + // tombstone my slot in the parent chain (keep the gemmi placeholder residue) + if (chain) { + auto &rv = chain->residues; + for (size_t i = 0; i < rv.size(); ++i) + if (rv[i] == this) { + rv[i] = nullptr; + break; + } + } + m->_res_allocs.erase(this); + } + + inline void Chain::_compact_residues() { + // Drop tombstoned (null) wrapper slots and their gemmi placeholder residues in + // lock-step (wrapper[i] <-> g().residues[i]); then reindex ri to the new order. + bool any_null = false; + for (Residue *r : residues) + if (!r) { + any_null = true; + break; + } + if (!any_null) return; + std::vector keptw; + std::vector keptg; + gemmi::Chain &gc = g(); + keptw.reserve(residues.size()); + keptg.reserve(gc.residues.size()); + for (size_t i = 0; i < residues.size(); ++i) { + if (residues[i]) { + keptw.push_back(residues[i]); + if (i < gc.residues.size()) keptg.push_back(std::move(gc.residues[i])); + } + } + residues.swap(keptw); + gc.residues.swap(keptg); + for (int k = 0; k < (int)residues.size(); ++k) residues[k]->ri = k; + } + + // ---- Chain out-of-line ---- + inline bool Chain::isAminoacidChain() { + for (Residue *r : residues) + if (r && r->isAminoacid()) return true; + return false; + } + inline bool Chain::isNucleotideChain() { + for (Residue *r : residues) + if (r && r->isNucleotide()) return true; + return false; + } + inline bool Chain::isSolventChain() { + if (residues.empty()) return false; + for (Residue *r : residues) + if (r && !r->isSolvent()) return false; + return true; + } + inline pstr Chain::GetChainID() { + std::snprintf(_chainid_buf, sizeof(_chainid_buf), "%s", g().name.c_str()); + return _chainid_buf; + } + inline PResidue Chain::AddResidue(Manager &m, gemmi::Residue r) { + g().residues.push_back(std::move(r)); + Residue *rw = m.newRes(); + rw->mgr = &m; + rw->chain = this; + rw->ri = (int)residues.size(); + for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { + Atom *aw = m.newAtom(); + aw->mgr = &m; + aw->res = rw; + aw->ai = ai; + rw->atoms.push_back(aw); + } + residues.push_back(rw); + return rw; + } + inline PResidue Chain::InsResidue(Manager &m, int pos, gemmi::Residue r) { + _compact_residues(); // don't insert/reindex across deferred-delete tombstones + g().residues.insert(g().residues.begin() + pos, std::move(r)); + Residue *rw = m.newRes(); + rw->mgr = &m; + rw->chain = this; + rw->ri = pos; + residues.insert(residues.begin() + pos, rw); + for (int k = pos + 1; k < (int)residues.size(); ++k) residues[k]->ri = k; + for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { + Atom *aw = m.newAtom(); + aw->mgr = &m; + aw->res = rw; + aw->ai = ai; + rw->atoms.push_back(aw); + } + return rw; + } + + // ---- Model out-of-line ---- + inline PChain Model::GetChain(const ChainID chID) { + for (Chain *c : chains) + if (c->g().name == chID) return c; + return nullptr; + } + + // ---- Manager out-of-line ---- + inline void Manager::build_from_gemmi() { + models.clear(); + all_atoms.clear(); + for (int mi = 0; mi < (int)st.models.size(); ++mi) { + Model *mw = newModel(); + mw->mgr = this; + mw->mi = mi; + auto &gm = st.models[mi]; + for (int ci = 0; ci < (int)gm.chains.size(); ++ci) { + Chain *cw = newChain(); + cw->mgr = this; + cw->model = mw; + cw->ci = ci; + auto &gc = gm.chains[ci]; + for (int ri = 0; ri < (int)gc.residues.size(); ++ri) { + Residue *rw = newRes(); + rw->mgr = this; + rw->chain = cw; + rw->ri = ri; + auto &gr = gc.residues[ri]; + for (int ai = 0; ai < (int)gr.atoms.size(); ++ai) { + Atom *aw = newAtom(); + aw->mgr = this; + aw->res = rw; + aw->ai = ai; + aw->WhatIsSet = ASET_Coordinates | ASET_Occupancy | ASET_tempFactor; + const gemmi::SMat33 &an = gr.atoms[ai].aniso; + if (an.u11 != 0.f || an.u22 != 0.f || an.u33 != 0.f) aw->WhatIsSet |= ASET_Anis_tFac; + rw->atoms.push_back(aw); + all_atoms.push_back(aw); + mw->all_atoms.push_back(aw); + } + rw->_sync_atom(); + rw->_load_id(); + cw->residues.push_back(rw); + } + mw->chains.push_back(cw); + } + models.push_back(mw); + } + _load_metadata(); + } + + // Map gemmi's structure-level metadata (connections / cispeps / helices / + // sheets) onto the MMDB per-Model record containers. gemmi is the reader; the + // shim just re-shapes. Connections/helices/sheets are not model-scoped in gemmi, + // so they go on model 1 (MMDB's usual home); cispeps honour their model_num. + inline void Manager::_load_metadata() { + link_pool.clear(); + linkr_pool.clear(); + cispep_pool.clear(); + helix_pool.clear(); + sheet_pool.clear(); + strand_pool.clear(); + strandarr_pool.clear(); + author_pool.clear(); + + // PDB title AUTHOR records (gemmi meta.authors) + title.author.data.clear(); + for (const std::string &au : st.meta.authors) { + author_pool.emplace_back(); + std::snprintf(author_pool.back().Line, sizeof(author_pool.back().Line), "%s", au.c_str()); + title.author.data.push_back(&author_pool.back()); + } + if (models.empty()) return; + + auto fill_ends = [](const gemmi::AtomAddress &a, ChainID &cid, ResName &rn, + int &seq, InsCode &ic, AtomName *an, AltLoc *al) { + std::snprintf(cid, sizeof(ChainID), "%s", a.chain_name.c_str()); + std::snprintf(rn, sizeof(ResName), "%s", a.res_id.name.c_str()); + seq = a.res_id.seqid.num.value; + ic[0] = (a.res_id.seqid.icode && a.res_id.seqid.icode != ' ') ? a.res_id.seqid.icode : '\0'; + ic[1] = '\0'; + if (an) std::snprintf(*an, sizeof(AtomName), "%s", a.atom_name.c_str()); + if (al) { + (*al)[0] = a.altloc ? a.altloc : '\0'; + (*al)[1] = '\0'; + } + }; + + // --- LINK records (gemmi Connection) -> model 1 --- + Model *m1 = models[0]; + for (const gemmi::Connection &cn : st.connections) { + link_pool.emplace_back(); + Link &l = link_pool.back(); + fill_ends(cn.partner1, l.chainID1, l.resName1, l.seqNum1, l.insCode1, &l.atName1, &l.aloc1); + fill_ends(cn.partner2, l.chainID2, l.resName2, l.seqNum2, l.insCode2, &l.atName2, &l.aloc2); + l.dist = cn.reported_distance; + m1->_links.push_back(&l); + // a connection carrying a Refmac link id is also a LINKR record + if (!cn.link_id.empty()) { + linkr_pool.emplace_back(); + LinkR &lr = linkr_pool.back(); + std::snprintf(lr.linkRID, sizeof(lr.linkRID), "%s", cn.link_id.c_str()); + AtomName an; + AltLoc al; + fill_ends(cn.partner1, lr.chainID1, lr.resName1, lr.seqNum1, lr.insCode1, &an, &al); + std::snprintf(lr.atName1, sizeof(AtomName), "%s", an); + std::snprintf(lr.aloc1, sizeof(AltLoc), "%s", al); + fill_ends(cn.partner2, lr.chainID2, lr.resName2, lr.seqNum2, lr.insCode2, &an, &al); + std::snprintf(lr.atName2, sizeof(AtomName), "%s", an); + std::snprintf(lr.aloc2, sizeof(AltLoc), "%s", al); + lr.dist = cn.reported_distance; + m1->_linkrs.push_back(&lr); + } + } + + // --- CISPEP records (gemmi CisPep) -> model by model_num (default 1) --- + for (const gemmi::CisPep &cp : st.cispeps) { + int mnum = cp.model_num > 0 ? cp.model_num : 1; + Model *mw = GetModel(mnum); + if (!mw) mw = m1; + cispep_pool.emplace_back(); + CisPep &c = cispep_pool.back(); + InsCode ic1, ic2; + int s1, s2; + fill_ends(cp.partner_c, c.chainID1, c.pep1, s1, ic1, nullptr, nullptr); + fill_ends(cp.partner_n, c.chainID2, c.pep2, s2, ic2, nullptr, nullptr); + c.seqNum1 = s1; + std::snprintf(c.icode1, sizeof(InsCode), "%s", ic1); + c.seqNum2 = s2; + std::snprintf(c.icode2, sizeof(InsCode), "%s", ic2); + c.modNum = mnum; + if (!std::isnan(cp.reported_angle)) c.measure = cp.reported_angle; + mw->_cispeps.push_back(&c); + } + + // --- HELIX records (gemmi Helix) -> model 1 --- + for (const gemmi::Helix &gh : st.helices) { + helix_pool.emplace_back(); + Helix &h = helix_pool.back(); + AtomName an; + AltLoc al; + fill_ends(gh.start, h.initChainID, h.initResName, h.initSeqNum, h.initICode, &an, &al); + fill_ends(gh.end, h.endChainID, h.endResName, h.endSeqNum, h.endICode, &an, &al); + h.helixClass = (int)gh.pdb_helix_class; + h.length = gh.length; + h.serNum = (int)helix_pool.size(); + m1->helices.AddData(&h); + } + + // --- SHEET / STRAND records (gemmi Sheet) -> model 1 --- + if (!st.sheets.empty()) { + m1->sheets.nSheets = (int)st.sheets.size(); + m1->_sheet_ptrs.assign(st.sheets.size(), nullptr); // backs Sheets::sheet (Sheet**) + for (size_t is = 0; is < st.sheets.size(); ++is) { + const gemmi::Sheet &gs = st.sheets[is]; + sheet_pool.emplace_back(); + Sheet &sh = sheet_pool.back(); + std::snprintf(sh.sheetID, sizeof(sh.sheetID), "%s", gs.name.c_str()); + sh.nStrands = (int)gs.strands.size(); + strandarr_pool.emplace_back(); + std::vector &sarr = strandarr_pool.back(); + sarr.reserve(gs.strands.size()); + for (const gemmi::Sheet::Strand &gst : gs.strands) { + strand_pool.emplace_back(); + Strand &str = strand_pool.back(); + AtomName an; + AltLoc al; + fill_ends(gst.start, str.initChainID, str.initResName, str.initSeqNum, str.initICode, &an, &al); + fill_ends(gst.end, str.endChainID, str.endResName, str.endSeqNum, str.endICode, &an, &al); + std::snprintf(str.sheetID, sizeof(str.sheetID), "%s", gs.name.c_str()); + str.strandNo = (int)sarr.size() + 1; + str.sense = gst.sense; + sarr.push_back(&str); + } + sh.strand = sarr.data(); + m1->_sheet_ptrs[is] = &sh; + } + m1->sheets.sheet = m1->_sheet_ptrs.data(); + } + } + + // ---- Manager::PutAtom (hierarchy insertion) ---- + inline int Manager::PutAtom(int index, PAtom A, int serNum) { + if (!A) return 0; + Residue *src = A->res; + // ensure a model exists (Coot calls PutAtom on a fresh, empty Manager) + Model *mw = models.empty() ? nullptr : models[0]; + if (!mw) { + st.models.emplace_back(1); + mw = newModel(); + mw->mgr = this; + mw->mi = 0; + models.push_back(mw); + } + // find or create the chain implied by the source atom's chain + std::string cid = (src && src->chain) ? src->chain->g().name : std::string("A"); + Chain *cw = mw->GetChain(cid.c_str()); + if (!cw) cw = mw->CreateChain(cid.c_str()); + // find or create the residue implied by (seqNum, insCode) + int seq = src ? src->g().seqid.num.value : 0; + char ic = src ? src->g().seqid.icode : ' '; + char icn = ic ? ic : ' '; + Residue *rw = nullptr; + for (Residue *r : cw->residues) { + gemmi::Residue &gr = r->g(); + if (gr.seqid.num.value == seq && (gr.seqid.icode ? gr.seqid.icode : ' ') == icn) { + rw = r; + break; + } + } + if (!rw) { + gemmi::Residue gr; + gr.name = src ? src->g().name : std::string("UNK"); + gr.seqid.num = seq; + gr.seqid.icode = icn; + rw = cw->AddResidue(*this, gr); + rw->_load_id(); + } + // append a copy of the atom's gemmi backing + register it in the flat tables + Atom *aw = rw->AddAtom(*this, A->g()); + aw->WhatIsSet = A->WhatIsSet; + aw->Het = A->Het; + std::memcpy(aw->segID, A->segID, sizeof aw->segID); + aw->g().serial = serNum ? serNum : (index > 0 ? index : (int)all_atoms.size() + 1); + rw->_sync_atom(); + all_atoms.push_back(aw); + mw->all_atoms.push_back(aw); + return (int)all_atoms.size(); // 1-based position (GetAtomI(pos) returns aw) + } + + // ---- selection matching ---- + namespace detail { + inline std::string trimws(const std::string &s) { + size_t a = s.find_first_not_of(' '), b = s.find_last_not_of(' '); + return a == std::string::npos ? std::string() : s.substr(a, b - a + 1); + } + // Whitespace-insensitive membership test. MMDB atom names are stored space- + // padded ("_CA_", "_O__"), while CID/selection queries are unpadded ("CA", + // "O"); real MMDB matches them regardless of padding, so trim both sides. + // Harmless for chain IDs / residue / element names (already unpadded). + inline bool inList(cpstr list, const std::string &v) { + if (!list || !*list || std::strcmp(list, "*") == 0) return true; + // MMDB negation: a leading '!' inverts the match (e.g. "!HOH" = any residue + // that is not water). Coot's Select() uses this for chain/residue/element/ + // atom-name filters; without it every residue is (wrongly) excluded. + if (list[0] == '!') return !inList(list + 1, v); + std::string vt = trimws(v); + const char *p = list; + while (*p) { + const char *c = std::strchr(p, ','); + std::string tok(p, c ? (size_t)(c - p) : std::strlen(p)); + if (trimws(tok) == vt) return true; + if (!c) break; + p = c + 1; + } + return false; + } + inline bool altMatch(cpstr list, char alt) { + if (!list || std::strcmp(list, "*") == 0) return true; + std::string a = alt ? std::string(1, alt) : std::string(); + if (!*list) return a.empty(); // "" -> only blank altLoc + return inList(list, a); + } + } // namespace detail + + inline void Manager::Select(int selHnd, SELECTION_TYPE sType, int iModel, + cpstr Chains, int ResNo1, cpstr Ins1, int ResNo2, cpstr Ins2, cpstr RNames, + cpstr ANames, cpstr Elements, cpstr altLocs, SELECTION_KEY selKey) { + Selection &sel = selections[selHnd - 1]; + if (sel.type == STYPE_UNDEFINED) sel.type = sType; + std::vector oldA = sel.atoms; + std::vector oldR = sel.residues; + std::vector oldC = sel.chains; + + std::vector mAtoms; + std::vector mResidues; + std::vector mChains; + for (Model *mw : models) { + if (iModel > 0 && mw->GetSerNum() != iModel) continue; + for (Chain *cw : mw->chains) { + if (!detail::inList(Chains, cw->g().name)) continue; + bool anyResidue = false; + for (Residue *rw : cw->residues) { + int sn = rw->g().seqid.num.value; + char ric = rw->g().seqid.icode ? rw->g().seqid.icode : ' '; + // (seqNum, insCode) range: an explicit insCode only constrains the + // boundary residue; blank/"*" includes every insCode at that seqNum. + if (ResNo1 != ANY_RES) { + if (sn < ResNo1) continue; + if (sn == ResNo1 && Ins1 && Ins1[0] && std::strcmp(Ins1, "*") && ric < Ins1[0]) continue; + } + if (ResNo2 != ANY_RES) { + if (sn > ResNo2) continue; + if (sn == ResNo2 && Ins2 && Ins2[0] && std::strcmp(Ins2, "*") && ric > Ins2[0]) continue; + } + if (!detail::inList(RNames, rw->g().name)) continue; + bool anyAtom = false; + for (Atom *aw : rw->atoms) { + if (!detail::inList(ANames, aw->g().name)) continue; + if (!detail::inList(Elements, aw->g().element.name())) continue; + if (!detail::altMatch(altLocs, aw->g().altloc)) continue; + anyAtom = true; + if (sType == STYPE_ATOM) mAtoms.push_back(aw); + } + if (anyAtom) anyResidue = true; + if (anyAtom && sType == STYPE_RESIDUE) mResidues.push_back(rw); + } + // STYPE_CHAIN: a chain matching the chain filter (and, if given, having a + // residue that passes the residue/atom filters) is selected whole. + if (sType == STYPE_CHAIN && anyResidue) mChains.push_back(cw); + } + } + auto combine = [&](auto &cur, auto &matched) { + using Vec = typename std::decay::type; + std::set curset(cur.begin(), cur.end()); + std::set mset(matched.begin(), matched.end()); + if (selKey == SKEY_NEW) { + cur = matched; + } else if (selKey == SKEY_OR) { + for (auto *x : matched) + if (!curset.count(x)) cur.push_back(x); + } else if (selKey == SKEY_AND) { + Vec o; + for (auto *x : cur) + if (mset.count(x)) o.push_back(x); + cur = o; + } else if (selKey == SKEY_XOR) { + Vec o; + for (auto *x : cur) + if (!mset.count(x)) o.push_back(x); + for (auto *x : matched) + if (!curset.count(x)) o.push_back(x); + cur = o; + } else if (selKey == SKEY_CLR) { + Vec o; + for (auto *x : cur) + if (!mset.count(x)) o.push_back(x); + cur = o; + } + }; + if (sType == STYPE_ATOM) + combine(sel.atoms, mAtoms); + else if (sType == STYPE_RESIDUE) + combine(sel.residues, mResidues); + else if (sType == STYPE_CHAIN) + combine(sel.chains, mChains); + for (Atom *a : oldA) a->_setInSel(selHnd, false); + for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); + for (Residue *r : oldR) r->_setInSel(selHnd, false); + for (Residue *r : sel.residues) r->_setInSel(selHnd, true); + for (Chain *c : oldC) c->_setInSel(selHnd, false); + for (Chain *c : sel.chains) c->_setInSel(selHnd, true); + } + + // select-from-selection: combine selHnd2's contents into selHnd1 + inline void Manager::Select(int selHnd1, SELECTION_TYPE sType, int selHnd2, + SELECTION_KEY sKey) { + Selection &s1 = selections[selHnd1 - 1]; + Selection &s2 = selections[selHnd2 - 1]; + if (s1.type == STYPE_UNDEFINED) s1.type = sType; + std::vector oldA = s1.atoms; + std::vector oldR = s1.residues; + auto combine = [&](auto &cur, auto &m) { + using Vec = typename std::decay::type; + std::set curset(cur.begin(), cur.end()); + std::set mset(m.begin(), m.end()); + if (sKey == SKEY_NEW) + cur = m; + else if (sKey == SKEY_OR) { + for (auto *x : m) + if (!curset.count(x)) cur.push_back(x); + } else if (sKey == SKEY_AND) { + Vec o; + for (auto *x : cur) + if (mset.count(x)) o.push_back(x); + cur = o; + } else if (sKey == SKEY_XOR) { + Vec o; + for (auto *x : cur) + if (!mset.count(x)) o.push_back(x); + for (auto *x : m) + if (!curset.count(x)) o.push_back(x); + cur = o; + } else if (sKey == SKEY_CLR) { + Vec o; + for (auto *x : cur) + if (!mset.count(x)) o.push_back(x); + cur = o; + } + }; + if (sType == STYPE_ATOM) + combine(s1.atoms, s2.atoms); + else if (sType == STYPE_RESIDUE) + combine(s1.residues, s2.residues); + for (Atom *a : oldA) a->_setInSel(selHnd1, false); + for (Atom *a : s1.atoms) a->_setInSel(selHnd1, true); + for (Residue *r : oldR) r->_setInSel(selHnd1, false); + for (Residue *r : s1.residues) r->_setInSel(selHnd1, true); + } + + inline void Manager::SelectAtom(int selHnd, PAtom atom, SELECTION_KEY sKey, bool) { + Selection &sel = selections[selHnd - 1]; + if (sel.type == STYPE_UNDEFINED) sel.type = STYPE_ATOM; + if (sKey == SKEY_NEW) { + for (Atom *a : sel.atoms) a->_setInSel(selHnd, false); + sel.atoms.clear(); + } + if (atom && !atom->isInSelection(selHnd)) { + sel.atoms.push_back(atom); + atom->_setInSel(selHnd, true); + } + } + + // Pragmatic CID parser: "/model/chain/seqNum1[.ins1]-seqNum2[.ins2]/atom" + // (best-effort; strips (resname)/[element]/:altloc suffixes; parses insertion + // codes after '.'). Not the full MMDB CID grammar but covers Coot's usage. + inline void Manager::Select(int selHnd, SELECTION_TYPE sType, cpstr CID, + SELECTION_KEY sKey) { + std::string s = CID ? CID : ""; + std::vector t; + size_t p = (!s.empty() && s[0] == '/') ? 1 : 0; + while (p <= s.size()) { + size_t q = s.find('/', p); + t.push_back(s.substr(p, q == std::string::npos ? std::string::npos : q - p)); + if (q == std::string::npos) break; + p = q + 1; + } + auto tok = [&](size_t i) { return i < t.size() ? t[i] : std::string(); }; + auto strip = [](std::string v, const char *seps) { + size_t c = v.find_first_of(seps); + return c == std::string::npos ? v : v.substr(0, c); + }; + // Assign tokens to model/chain/residue/atom. A leading '/' (or any '/') means + // the model field is present at tok(0). A slash-less CID has NO model/chain + // prefix: MMDB reads a bare numeric token as a residue seqNum ("262" = residue + // 262 in every chain), and a bare non-numeric token as a chain id ("A"). + std::string model_s, chain_s, res_s, atom_s; + if (s.find('/') != std::string::npos) { + model_s = tok(0); + chain_s = tok(1); + res_s = tok(2); + atom_s = tok(3); + } else { + const std::string only = tok(0); + if (!only.empty() && (std::isdigit((unsigned char)only[0]) || only[0] == '-')) + res_s = only; + else + chain_s = only; + } + int iModel = 0; + if (!model_s.empty() && model_s != "*" && model_s != "0") iModel = atoi(model_s.c_str()); + std::string chains = chain_s.empty() ? "*" : chain_s; + int r1 = ANY_RES, r2 = ANY_RES; + std::string ins1 = "*", ins2 = "*"; + // split "num[.ins]" into number + insertion code + auto parse_resid = [](const std::string &v, int &num, std::string &ins) { + size_t dot = v.find('.'); + num = atoi(v.substr(0, dot).c_str()); + ins = (dot == std::string::npos) ? std::string() : v.substr(dot + 1); + }; + std::string rr = strip(res_s, "("); // drop (resname) + if (!rr.empty() && rr != "*") { + size_t dash = rr.find('-', rr[0] == '-' ? 1 : 0); + if (dash == std::string::npos) { + parse_resid(rr, r1, ins1); + r2 = r1; + ins2 = ins1; + } else { + parse_resid(rr.substr(0, dash), r1, ins1); + parse_resid(rr.substr(dash + 1), r2, ins2); + } + } + std::string anames = strip(strip(atom_s, "["), ":"); // drop [element]/:altloc + if (anames.empty()) anames = "*"; + Select(selHnd, sType, iModel, chains.c_str(), r1, ins1.c_str(), r2, ins2.c_str(), "*", + anames.c_str(), "*", "*", sKey); + } + + inline int Manager::GetNumberOfAtoms(cpstr CID) { + int h = NewSelection(); + Select(h, STYPE_ATOM, CID, SKEY_NEW); + int n = (int)selections[h - 1].atoms.size(); + DeleteSelection(h); + return n; + } + + inline void Manager::GetAtomStatistics(int selHnd, RAtomStat AS) { + AS = AtomStat(); + std::vector &atoms = selections[selHnd - 1].atoms; + AS.nAtoms = (int)atoms.size(); + if (atoms.empty()) return; + double sx = 0, sy = 0, sz = 0; + AS.xmin = AS.xmax = atoms[0]->x(); + AS.ymin = AS.ymax = atoms[0]->y(); + AS.zmin = AS.zmax = atoms[0]->z(); + for (Atom *a : atoms) { + double X = a->x(), Y = a->y(), Z = a->z(); + sx += X; + sy += Y; + sz += Z; + AS.xmin = X < AS.xmin ? X : AS.xmin; + AS.xmax = X > AS.xmax ? X : AS.xmax; + AS.ymin = Y < AS.ymin ? Y : AS.ymin; + AS.ymax = Y > AS.ymax ? Y : AS.ymax; + AS.zmin = Z < AS.zmin ? Z : AS.zmin; + AS.zmax = Z > AS.zmax ? Z : AS.zmax; + } + AS.xm = sx / atoms.size(); + AS.ym = sy / atoms.size(); + AS.zm = sz / atoms.size(); + } + + inline void Manager::SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, + realtype y, realtype z, realtype r, SELECTION_KEY sKey) { + Selection &sel = selections[selHnd - 1]; + if (sel.type == STYPE_UNDEFINED) sel.type = sType; + std::vector oldA = sel.atoms; + std::vector oldR = sel.residues; + gemmi::Position c(x, y, z); + double r2 = r * r; + std::vector mAtoms; + std::vector mResidues; + for (Model *mw : models) + for (Chain *cw : mw->chains) + for (Residue *rw : cw->residues) { + bool any = false; + for (Atom *aw : rw->atoms) + if (aw->g().pos.dist_sq(c) <= r2) { + any = true; + if (sType == STYPE_ATOM) mAtoms.push_back(aw); + } + if (any && sType == STYPE_RESIDUE) mResidues.push_back(rw); + } + auto combine = [&](auto &cur, auto &m) { + std::set::type::value_type> cs(cur.begin(), cur.end()); + if (sKey == SKEY_NEW) + cur = m; + else if (sKey == SKEY_OR) { + for (auto *p : m) + if (!cs.count(p)) cur.push_back(p); + } + }; + if (sType == STYPE_ATOM) + combine(sel.atoms, mAtoms); + else if (sType == STYPE_RESIDUE) + combine(sel.residues, mResidues); + for (Atom *a : oldA) a->_setInSel(selHnd, false); + for (Atom *a : sel.atoms) a->_setInSel(selHnd, true); + for (Residue *r : oldR) r->_setInSel(selHnd, false); + for (Residue *r : sel.residues) r->_setInSel(selHnd, true); + } + + // SeekContacts (both overloads) is defined in mmdb-shim/src/contacts.cc using + // gemmi::NeighborSearch — keeps the heavy neighbor.hpp out of Coot's many TUs. + + // ---- detached-construction constructors + subtree ops (need complete types) ---- + inline Atom::Atom(Residue *r) { + if (r) r->AddAtom(this); + } + inline Residue::Residue(Chain *c) { + if (c) c->AddResidue(this); + } + inline Chain::Chain(Model *m, const ChainID id) { + if (m) m->AddChain(this); + SetChainID(id); + } + + // peptide-bond distance threshold for backbone C-N (a real bond is ~1.33 A). + inline bool Residue::isNTerminus() { + if (!chain || ri <= 0) return true; // first (or detached) residue + Residue *prev = chain->residues[ri - 1]; + if (!prev) return true; // previous slot is a deferred-delete tombstone + const gemmi::Atom *N = g().get_n(); + const gemmi::Atom *prevC = prev->g().get_c(); + if (!N || !prevC) return true; // missing backbone -> terminus + return N->pos.dist(prevC->pos) > 1.7; // not bonded to previous C + } + inline bool Residue::isCTerminus() { + if (!chain || ri < 0 || ri >= (int)chain->residues.size() - 1) return true; // last/detached + Residue *next = chain->residues[ri + 1]; + if (!next) return true; // next slot is a deferred-delete tombstone + const gemmi::Atom *C = g().get_c(); + const gemmi::Atom *nextN = next->g().get_n(); + if (!C || !nextN) return true; + return C->pos.dist(nextN->pos) > 1.7; // not bonded to next N + } + inline Model *Residue::GetModel() { return chain ? chain->model : nullptr; } + + inline void Chain::Copy(PChain src) { + Manager *pool = mgr ? mgr : src->mgr; + g() = src->g(); // deep gemmi copy (residues + atoms) + residues.clear(); + if (!pool) return; + gemmi::Chain &gc = g(); + for (int r = 0; r < (int)gc.residues.size(); ++r) { + Residue *rw = pool->newRes(); + rw->mgr = mgr; + rw->chain = this; + rw->ri = r; + for (int a = 0; a < (int)gc.residues[r].atoms.size(); ++a) { + Atom *aw = pool->newAtom(); + aw->mgr = mgr; + aw->res = rw; + aw->ai = a; + rw->atoms.push_back(aw); + } + rw->_sync_atom(); + rw->_load_id(); + residues.push_back(rw); + } + } + + inline void Model::Copy(PModel src) { + Manager *pool = mgr ? mgr : src->mgr; + g() = src->g(); + chains.clear(); + if (!pool) return; + gemmi::Model &gm = g(); + for (int c = 0; c < (int)gm.chains.size(); ++c) { + Chain *cw = pool->newChain(); + cw->mgr = mgr; + cw->model = this; + cw->ci = c; + for (int r = 0; r < (int)gm.chains[c].residues.size(); ++r) { + Residue *rw = pool->newRes(); + rw->mgr = mgr; + rw->chain = cw; + rw->ri = r; + for (int a = 0; a < (int)gm.chains[c].residues[r].atoms.size(); ++a) { + Atom *aw = pool->newAtom(); + aw->mgr = mgr; + aw->res = rw; + aw->ai = a; + rw->atoms.push_back(aw); + } + rw->_sync_atom(); + rw->_load_id(); + cw->residues.push_back(rw); + } + chains.push_back(cw); + } + } + + inline PChain Model::CreateChain(const ChainID id) { + Chain *c = mgr ? mgr->newChain() : new Chain(); + c->mgr = mgr; + c->model = this; + c->ci = (int)chains.size(); + g().chains.emplace_back(id ? id : ""); + chains.push_back(c); + return c; + } + + inline pstr Atom::GetAtomID(pstr S) { + if (S) std::snprintf(S, 100, "/%d/%s/%d(%s)/%s", GetModelNum(), GetChainID(), + res ? res->GetSeqNum() : 0, GetResName(), GetAtomName()); + return S; + } + + // one-letter residue code (mmdb_tables.h) via gemmi's tabulated residues + inline void Get1LetterCode(cpstr res3, pstr res1) { + if (!res1) return; + char c = gemmi::find_tabulated_residue(res3 ? res3 : "").one_letter_code; + res1[0] = c ? (char)std::toupper((unsigned char)c) : 'X'; + res1[1] = '\0'; + } + inline void Get1LetterCode(cpstr res3, char &res1) { + char b[2]; + Get1LetterCode(res3, b); + res1 = b[0]; + } + + // sort a contact array by distance (mmdb_coormngr.h SortContacts) — sortkey ignored + inline void SortContacts(PContact contacts, int nContacts, int /*sortkey*/) { + if (contacts && nContacts > 1) + std::sort(contacts, contacts + nContacts, + [](const Contact &a, const Contact &b) { return a.dist < b.dist; }); + } + + // centroid of an atom array (mmdb_coormngr.h GetMassCenter) + inline void GetMassCenter(PPAtom A, int nA, realtype &xc, realtype &yc, realtype &zc) { + double sx = 0, sy = 0, sz = 0; + int n = 0; + for (int i = 0; i < nA; ++i) + if (A[i]) { + sx += A[i]->x(); + sy += A[i]->y(); + sz += A[i]->z(); + ++n; + } + if (n) { + xc = sx / n; + yc = sy / n; + zc = sz / n; + } else { + xc = yc = zc = 0; + } + } + +} // namespace mmdb diff --git a/mmdb-shim/include/mmdb2/_shim_manager.hh b/mmdb-shim/include/mmdb2/_shim_manager.hh new file mode 100644 index 0000000000..1c30de914f --- /dev/null +++ b/mmdb-shim/include/mmdb2/_shim_manager.hh @@ -0,0 +1,533 @@ +// mmdb-shim — layer 3 of 4: the Manager (MMDB Root/CoorManager/SelManager rolled +// into one). +// +// Manager owns the live gemmi::Structure plus the wrapper trees built over it, the +// individually heap-allocated Atom/Residue nodes (so Coot's `delete atom;` idiom +// works), the stable-address pools for gemmi-derived metadata records, the +// handle-based selection engine, and the UDData registry. I/O, selection matching, +// PutAtom and the gemmi metadata mapping are declared here and defined out-of-line +// in _shim_inline.hh / src/*.cc. +#pragma once + +#include "_shim_hierarchy.hh" + +namespace mmdb { + + // =========================================================================== + class Manager { + public: + gemmi::Structure st; + // Atoms are heap-allocated individually (not pooled) so Coot's MMDB idiom + // `delete atom;` frees exactly one node. The manager owns every atom it hands + // out and frees the survivors at teardown; `~Atom` removes itself from this set + // when Coot deletes it early. `_bulk_free` tells `~Atom` to skip detach work + // while the manager is tearing everything down. + std::set _atom_allocs; + std::set _res_allocs; // residues heap-allocated too (Coot `delete residue_p`) + bool _bulk_free = false; + ~Manager() { + _bulk_free = true; + for (Atom *a : _atom_allocs) delete a; + _atom_allocs.clear(); + for (Residue *r : _res_allocs) delete r; + _res_allocs.clear(); + } + // stable-address pools (Chain/Model still pooled — see _atom_allocs / _res_allocs note) + std::deque chain_pool; + std::deque model_pool; + std::vector models; + // stable-address pools for gemmi-derived metadata records (LINK / CISPEP / + // HELIX / SHEET). Filled by build_from_gemmi -> _load_metadata(); owned here so + // the Model containers can hold bare pointers into them. + std::deque link_pool; + std::deque linkr_pool; + std::deque cispep_pool; + std::deque helix_pool; + std::deque sheet_pool; + std::deque strand_pool; + std::deque> strandarr_pool; // backing for Sheet::strand (Strand**) + std::deque author_pool; // backing for title.author records + void _load_metadata(); // out-of-line: needs complete gemmi metadata types + + Atom *newAtom() { + Atom *a = new Atom(); + a->mgr = this; + _atom_allocs.insert(a); + return a; + } + Residue *newRes() { + Residue *r = new Residue(); + r->mgr = this; + _res_allocs.insert(r); + return r; + } + Chain *newChain() { + chain_pool.emplace_back(); + return &chain_pool.back(); + } + Model *newModel() { + model_pool.emplace_back(); + return &model_pool.back(); + } + + int GetNumberOfModels() { return (int)models.size(); } + PModel GetModel(int modelNo) { // MMDB: 1 <= modelNo <= nModels + int i = modelNo - 1; + return (i >= 0 && i < (int)models.size()) ? models[i] : nullptr; + } + // per-model chain access (modelNo is 1-based, chainNo 0-based) — mmdb_coormngr.h + int GetNumberOfChains(int modelNo) { + PModel m = GetModel(modelNo); + return m ? m->GetNumberOfChains() : 0; + } + PChain GetChain(int modelNo, int chainNo) { + PModel m = GetModel(modelNo); + return m ? m->GetChain(chainNo) : nullptr; + } + // Re-index/renumber after edits. Sibling indices are kept in sync as the shim + // mutates (so PDBCLEAN_INDEX is implicit); PDBCLEAN_SERIAL renumbers atom serials + // 1..N in hierarchy order. Other clean flags are not needed by the shim. + word PDBCleanup(word CleanKey) { + // INDEX cleanup compacts deferred residue deletions (drops tombstones) — do it + // before renumbering so serials/indices count only surviving atoms. + if (CleanKey & PDBCLEAN_INDEX) { + for (Model *mw : models) + for (Chain *cw : mw->chains) cw->_compact_residues(); + _rebuild_all_atoms(); + } + if (CleanKey & (PDBCLEAN_SERIAL | PDBCLEAN_INDEX)) { + int s = 1; + for (Atom *a : all_atoms) a->g().serial = s++; + } + return 0; + } + + // PDB title records — Coot reaches `title` via an access_mol subclass; the + // TITLE string comes from gemmi (_struct.title), authors are filled on load. + Title title; + pstr GetStructureTitle(pstr T) { + if (T) std::strcpy(T, st.get_info("_struct.title").c_str()); // caller allocates (MMDB contract) + return T; + } + + // Orthogonal symmetry transformation for operator Nop (0-based) + cell shifts, + // via gemmi's space group + unit cell (shared helper). Returns 0 on success, + // nonzero if there is no usable space group / the operator is out of range. + int GetTMatrix(mat44 &TMatrix, int Nop, int cellshift_a, int cellshift_b, int cellshift_c) { + return gemmi_sym_tmatrix(st.cell, st.spacegroup_hm, TMatrix, Nop, + cellshift_a, cellshift_b, cellshift_c); + } + + void build_from_gemmi(); + + // adopt a detached model (Coot: `new mmdb::Model` -> AddChain… -> AddModel). + // Copy its local gemmi into st, rebind, cascade mgr through the sub-tree. + int AddModel(PModel mw) { + st.models.push_back(mw->g()); + mw->mgr = this; + mw->mi = (int)models.size(); + models.push_back(mw); + for (Chain *cw : mw->chains) { + cw->mgr = this; + for (Residue *rw : cw->residues) { + rw->mgr = this; + for (Atom *aw : rw->atoms) { + aw->mgr = this; + all_atoms.push_back(aw); + mw->all_atoms.push_back(aw); + } + } + } + return 0; + } + + // clone another manager's structure (mmdb Manager::Copy(PManager, COPY_MASK)). + // Copies the whole gemmi Structure and rebuilds all wrappers — clean & correct. + void Copy(PManager m, int /*CopyMask*/) { + if (m) { + st = m->st; + build_from_gemmi(); + } + } + + // ---- crystal cell & symmetry (gemmi UnitCell / SpaceGroup) ---- + std::string _sg_buf, _symop_buf; + void GetCell(realtype &a, realtype &b, realtype &c, realtype &al, realtype &be, + realtype &ga, realtype &vol, int &orthcode) { + const gemmi::UnitCell &u = st.cell; + a = u.a; + b = u.b; + c = u.c; + al = u.alpha; + be = u.beta; + ga = u.gamma; + vol = u.volume; + orthcode = 1; + } + void GetCell(realtype &a, realtype &b, realtype &c, realtype &al, realtype &be, + realtype &ga, realtype &vol) { + int oc; + GetCell(a, b, c, al, be, ga, vol, oc); + } + void SetCell(realtype a, realtype b, realtype c, realtype al, realtype be, + realtype ga, int /*OrthCode*/ = 1) { st.cell.set(a, b, c, al, be, ga); } + void Orth2Frac(realtype x, realtype y, realtype z, realtype &u, realtype &v, realtype &w) { + gemmi::Fractional f = st.cell.fractionalize(gemmi::Position(x, y, z)); + u = f.x; + v = f.y; + w = f.z; + } + void Frac2Orth(realtype u, realtype v, realtype w, realtype &x, realtype &y, realtype &z) { + gemmi::Position p = st.cell.orthogonalize(gemmi::Fractional(u, v, w)); + x = p.x; + y = p.y; + z = p.z; + } + pstr GetSpaceGroup() { + _sg_buf = st.spacegroup_hm; + return (pstr)_sg_buf.c_str(); + } + pstr GetSpaceGroupFix() { return GetSpaceGroup(); } + int SetSpaceGroup(cpstr sg) { + st.spacegroup_hm = sg ? sg : ""; + return 0; + } + int GetNumberOfSymOps() { + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(st.spacegroup_hm); + return sg ? (int)sg->operations().order() : 0; + } + pstr GetSymOp(int Nop) { + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(st.spacegroup_hm); + if (!sg) return nullptr; + int i = 0; + for (gemmi::Op op : sg->operations()) { + if (i++ == Nop) { + _symop_buf = op.triplet(); + return (pstr)_symop_buf.c_str(); + } + } + return nullptr; + } + + // ---- selection ---- + struct Selection { + SELECTION_TYPE type = STYPE_UNDEFINED; + std::vector atoms; + std::vector residues; + std::vector chains; + }; + std::vector selections; // handle is 1-based index + + int NewSelection() { + selections.emplace_back(); + return (int)selections.size(); + } + void DeleteSelection(int selHnd) { + if (selHnd < 1 || selHnd > (int)selections.size()) return; + Selection &s = selections[selHnd - 1]; + for (Atom *a : s.atoms) a->_setInSel(selHnd, false); + for (Residue *r : s.residues) r->_setInSel(selHnd, false); + for (Chain *c : s.chains) c->_setInSel(selHnd, false); + s = Selection(); + } + void GetSelIndex(int selHnd, PPAtom &SelAtom, int &n) { + Selection &s = selections[selHnd - 1]; + SelAtom = s.atoms.data(); + n = (int)s.atoms.size(); + } + void GetSelIndex(int selHnd, PPResidue &SelRes, int &n) { + Selection &s = selections[selHnd - 1]; + SelRes = s.residues.data(); + n = (int)s.residues.size(); + } + void GetSelIndex(int selHnd, PPChain &SelChain, int &n) { + Selection &s = selections[selHnd - 1]; + SelChain = s.chains.data(); + n = (int)s.chains.size(); + } + // select atoms by serial-number range (iSer1..iSer2; 0,0 => all). + void SelectAtoms(int selHnd, int iSer1, int iSer2, SELECTION_KEY key) { + if (selHnd < 1 || selHnd > (int)selections.size()) return; + Selection &s = selections[selHnd - 1]; + std::vector pick; + for (Atom *a : all_atoms) { + int sn = a->g().serial; + if ((iSer1 == 0 && iSer2 == 0) || (sn >= iSer1 && sn <= iSer2)) pick.push_back(a); + } + if (key == SKEY_OR) { + for (Atom *a : pick) + if (!a->isInSelection(selHnd)) s.atoms.push_back(a); + } else { + for (Atom *a : s.atoms) a->_setInSel(selHnd, false); + s.atoms = pick; + } + s.type = STYPE_ATOM; + for (Atom *a : s.atoms) a->_setInSel(selHnd, true); + } + + // full spatial+CID atom selection (mmdb_selmngr.h) — sphere around (x,y,z) with + // chain/resname/atomname/element filters ("!X" = exclusion, "*" = any). + void SelectAtoms(int selHnd, int /*iModel*/, cpstr Chains, int ResNo1, cpstr /*Ins1*/, + int ResNo2, cpstr /*Ins2*/, cpstr RNames, cpstr ANames, cpstr Elements, + cpstr /*altLocs*/, cpstr /*segIDs*/, cpstr /*charges*/, + realtype /*occ1*/, realtype /*occ2*/, realtype x, realtype y, realtype z, + realtype radius, SELECTION_KEY key) { + if (selHnd < 1 || selHnd > (int)selections.size()) return; + Selection &s = selections[selHnd - 1]; + // self-contained comma-list matcher ("*"=any, "!X"=exclude); `detail::` is + // declared after Manager, so don't depend on it in this inline body. + auto trimws = [](const std::string &s) -> std::string { + size_t a = s.find_first_not_of(' '), b = s.find_last_not_of(' '); + return a == std::string::npos ? std::string() : s.substr(a, b - a + 1); + }; + auto inlist = [&trimws](cpstr list, const std::string &v) -> bool { + if (!list || !*list || std::strcmp(list, "*") == 0) return true; + std::string vt = trimws(v); + for (const char *p = list; *p;) { + const char *c = std::strchr(p, ','); + std::string tok(p, c ? (size_t)(c - p) : std::strlen(p)); + if (trimws(tok) == vt) return true; + if (!c) break; + p = c + 1; + } + return false; + }; + auto match = [&](cpstr list, const std::string &v) -> bool { + if (!list || !*list || std::strcmp(list, "*") == 0) return true; + if (list[0] == '!') return !inlist(list + 1, v); + return inlist(list, v); + }; + gemmi::Position pt(x, y, z); + double r2 = radius * radius; + std::vector pick; + for (Atom *a : all_atoms) { + if (radius > 0 && a->g().pos.dist_sq(pt) > r2) continue; + Residue *r = a->res; + int sn = r->GetSeqNum(); + if (ResNo1 != ANY_RES && sn < ResNo1) continue; + if (ResNo2 != ANY_RES && sn > ResNo2) continue; + if (!match(Chains, r->chain->g().name)) continue; + if (!match(RNames, std::string(r->GetResName()))) continue; + if (!match(ANames, std::string(a->GetAtomName()))) continue; + if (!match(Elements, gemmi::Element(a->g().element).name())) continue; + pick.push_back(a); + } + if (key == SKEY_OR) { + for (Atom *a : pick) + if (!a->isInSelection(selHnd)) s.atoms.push_back(a); + } else { + for (Atom *a : s.atoms) a->_setInSel(selHnd, false); + s.atoms = pick; + } + s.type = STYPE_ATOM; + for (Atom *a : s.atoms) a->_setInSel(selHnd, true); + } + + // --- misc hierarchy/bond/UDData ops used by Coot --- + void RemoveBonds() {} // gemmi has no persistent bond table + // Partial-hierarchy delete (mmdb Manager::Delete). Coot's use is + // Delete(MMDBFCM_SC) to drop secondary-structure/connectivity records before + // writing; also honour Coord (atoms) and Cryst (cell/SG) for completeness. + void Delete(int DelKey) { + bool all = DelKey == MMDBFCM_All; + if (all || (DelKey & MMDBFCM_SC)) { + for (Model *m : models) { + m->_links.clear(); + m->_linkrs.clear(); + m->_cispeps.clear(); + m->helices.data.clear(); + m->sheets.nSheets = 0; + m->sheets.sheet = nullptr; + m->_sheet_ptrs.clear(); + } + link_pool.clear(); + linkr_pool.clear(); + cispep_pool.clear(); + helix_pool.clear(); + sheet_pool.clear(); + strand_pool.clear(); + strandarr_pool.clear(); + } + if (all || (DelKey & MMDBFCM_Cryst)) { + st.cell = gemmi::UnitCell(); + st.spacegroup_hm.clear(); + } + if (all || (DelKey & MMDBFCM_Coord)) { + st.models.clear(); + build_from_gemmi(); + } + } + void DeleteAllModels() { + st.models.clear(); + build_from_gemmi(); + } // clears the hierarchy + void DeleteModel(int modelNo) { // 1-based; erase model + rebuild wrappers + int i = modelNo - 1; + if (i >= 0 && i < (int)st.models.size()) { + st.models.erase(st.models.begin() + i); + build_from_gemmi(); + } + } + pstr GetInputBuffer(pstr buf, int &count) { + count = 0; + if (buf) buf[0] = '\0'; + return buf; + } + // Insert (a copy of) an atom into the hierarchy (mmdb Manager::PutAtom). MMDB + // keeps a flat atom array with a parallel hierarchy rebuilt by FinishStructEdit; + // the shim's storage IS the hierarchy, so PutAtom finds/creates the chain and + // residue implied by the atom's source residue and appends a copy there. Only + // append (index<=0 or top) is supported — the semantics Coot relies on + // (create_mmdbmanager_from_atom_selection_straight). Returns the atom's 1-based + // position (so GetAtomI(pos) returns it). Defined out-of-line (needs Add*). + int PutAtom(int index, PAtom atom, int serNum = 0); + // hierarchy-level UDData (UDR_HIERARCHY) — Manager owns its own UDStore. + UDStore _ud; + int PutUDData(int h, int v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } + int PutUDData(int h, realtype v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } + int PutUDData(int h, cpstr v) { return ud_put(this, UDR_HIERARCHY, _ud, h, v); } + int GetUDData(int h, int &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } + int GetUDData(int h, realtype &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } + int GetUDData(int h, pstr &v) { return ud_get(this, UDR_HIERARCHY, _ud, h, v); } + // primary CID-range selection (STYPE via Select; SelectAtoms forwards as STYPE_ATOM) + void Select(int selHnd, SELECTION_TYPE sType, int iModel, cpstr Chains, + int ResNo1, cpstr Ins1, int ResNo2, cpstr Ins2, cpstr RNames, + cpstr ANames, cpstr Elements, cpstr altLocs, SELECTION_KEY selKey = SKEY_OR); + void SelectAtoms(int selHnd, int iModel, cpstr Chains, int ResNo1, cpstr Ins1, + int ResNo2, cpstr Ins2, cpstr RNames, cpstr ANames, + cpstr Elements, cpstr altLocs, SELECTION_KEY selKey = SKEY_OR) { + Select(selHnd, STYPE_ATOM, iModel, Chains, ResNo1, Ins1, ResNo2, Ins2, + RNames, ANames, Elements, altLocs, selKey); + } + void SelectSphere(int selHnd, SELECTION_TYPE sType, realtype x, realtype y, + realtype z, realtype r, SELECTION_KEY sKey = SKEY_OR); + // select-from-selection: combine selHnd2's contents into selHnd1 per sKey + void Select(int selHnd1, SELECTION_TYPE sType, int selHnd2, SELECTION_KEY sKey); + // atoms within [d1,d2] of any atom in the given set (defined in contacts.cc) + void SelectNeighbours(int selHnd, SELECTION_TYPE sType, PPAtom atoms, int nAtoms, + realtype d1, realtype d2, SELECTION_KEY sKey = SKEY_OR); + void SetFlag(int /*flags*/) {} // no-op: read/write behaviour is fixed + void SetFlag(cpstr /*flags*/) {} + int PutPDBString(cpstr /*card*/) { return Error_NoError; } // no-op + // No persistent bond table. Verified safe: Coot's only caller (make_bonds in + // coot-utils/bonded-atoms.cc) ignores the mmdb bond table and recomputes bonds + // itself from geometry, so a no-op here matches observed Coot behaviour. + int MakeBonds(bool /*calc*/) { return 0; } + + // flat atom access (across the whole hierarchy) + std::vector all_atoms; + int GetNumberOfAtoms() { return (int)all_atoms.size(); } + int GetNumberOfAtoms(bool /*countTers*/) { return (int)all_atoms.size(); } + int GetNumberOfAtoms(cpstr CID); // count atoms matching CID (defined below) + // MMDB GetAtomI is 1-based: returns Atom[index-1]. + PAtom GetAtomI(int i) { return (i >= 1 && i <= (int)all_atoms.size()) ? all_atoms[i - 1] : nullptr; } + void GetAtomTable(PPAtom &t, int &n) { + t = all_atoms.data(); + n = (int)all_atoms.size(); + } + void GetModelTable(PPModel &t, int &n) { + t = models.data(); + n = (int)models.size(); + } + void GetAtomStatistics(int selHnd, RAtomStat AS); // defined below + int MakeSelIndex(int selHnd) { + return (selHnd >= 1 && selHnd <= (int)selections.size()) + ? (int)selections[selHnd - 1].atoms.size() + : 0; + } + void SelectAtom(int selHnd, PAtom atom, SELECTION_KEY sKey, bool makeIndex = true); + // CID-string selection, e.g. "/1/A/10-20/CA" + void Select(int selHnd, SELECTION_TYPE sType, cpstr CID, SELECTION_KEY sKey); + + // ---- contacts (gemmi NeighborSearch; TMatrix path uses a uniform grid) ---- + // TMatrix is MMDB's optional symmetry transform applied to the 2nd set: when + // given, contacts.cc transforms that set and searches against it (symmetry + // mates); when null, gemmi NeighborSearch over the untransformed model is used. + void SeekContacts(PPAtom A1, int n1, PPAtom A2, int n2, realtype d1, + realtype d2, int seqDist, PContact &contact, int &ncontacts, + int maxlen = 0, pmat44 TMatrix = nullptr, long group = 0); + void SeekContacts(PPAtom A, int n, realtype d1, realtype d2, int seqDist, + PContact &contact, int &ncontacts, int maxlen = 0, + pmat44 TMatrix = nullptr, long group = 0); + // single-atom vs selection (forwards to the array overload with a 1-elem array) + void SeekContacts(PAtom a, PPAtom A2, int n2, realtype d1, realtype d2, int seqDist, + PContact &contact, int &ncontacts, int maxlen = 0, + pmat44 TMatrix = nullptr, long group = 0) { + PAtom a1[1] = {a}; + SeekContacts(a1, 1, A2, n2, d1, d2, seqDist, contact, ncontacts, maxlen, TMatrix, group); + } + + // Compact deferred residue deletions across the whole hierarchy: MMDB defers + // DeleteResidue (tombstone the slot, keep the count) until FinishStructEdit, so + // here we drop the null tombstone slots + their gemmi placeholder residues and + // rebuild the flat atom lists. (Atoms already stay in sync eagerly.) + void _rebuild_all_atoms() { + all_atoms.clear(); + for (Model *mw : models) { + mw->mgr = this; + mw->all_atoms.clear(); + for (Chain *cw : mw->chains) { + cw->mgr = this; + for (Residue *rw : cw->residues) + if (rw) { + rw->mgr = this; + for (Atom *aw : rw->atoms) { + // Rebind ownership pointers: residues added via AddResidue/ + // InsResidue (e.g. add_terminal_residue) carry atoms whose mgr + // still points at the deep-copy temporary (or is null). Atom + // UDData routes through Atom::mgr, so without this the new atoms + // fail Put/GetUDData with WrongHandle — which drops their bonds + // (the atom-index UDD never lands) and any UD colouring. + aw->mgr = this; + aw->res = rw; + all_atoms.push_back(aw); + mw->all_atoms.push_back(aw); + } + } + } + } + } + int FinishStructEdit() { + for (Model *mw : models) + for (Chain *cw : mw->chains) cw->_compact_residues(); + _rebuild_all_atoms(); + return 0; + } + + // ---- UDData registry ---- + struct UDReg { + UDR_TYPE type; + int kind; + std::string name; + int slot; + }; // kind:0=int,1=real,2=str + std::vector ud_regs; + int ud_counts[5][3] = {{0}}; // [UDR_TYPE][kind] -> next slot + + int RegisterUDInteger(UDR_TYPE t, cpstr name) { return _regUD(t, 0, name); } + int RegisterUDReal(UDR_TYPE t, cpstr name) { return _regUD(t, 1, name); } + int RegisterUDString(UDR_TYPE t, cpstr name) { return _regUD(t, 2, name); } + int GetUDDHandle(UDR_TYPE t, cpstr name) { + for (int i = 0; i < (int)ud_regs.size(); ++i) + if (ud_regs[i].type == t && ud_regs[i].name == name) return i + 1; + return 0; // MMDB: 0 == "not registered" — Coot relies on `if (handle == 0) Register…` + } + + private: + // MMDB UDData handles are 1-based (0 is reserved for "not registered", see + // GetUDDHandle). Return a 1-based handle; _ud_desc maps back with handle-1. + int _regUD(UDR_TYPE t, int kind, cpstr name) { + ud_regs.push_back({t, kind, name ? name : "", ud_counts[t][kind]++}); + return (int)ud_regs.size(); + } + + public: + // ---- I/O (defined in mmdb-shim/src/io.cc; keeps heavy gemmi write/read + // headers out of the ~229 Coot TUs that include mmdb_manager.h) ---- + ERROR_CODE ReadPDBASCII(cpstr fname); + ERROR_CODE ReadCoorFile(cpstr fname); // auto-detects PDB / mmCIF + ERROR_CODE WritePDBASCII(cpstr fname); + ERROR_CODE WriteCIFASCII(cpstr fname); + }; + +} // namespace mmdb diff --git a/mmdb-shim/include/mmdb2/_shim_types.hh b/mmdb-shim/include/mmdb2/_shim_types.hh new file mode 100644 index 0000000000..4000f95628 --- /dev/null +++ b/mmdb-shim/include/mmdb2/_shim_types.hh @@ -0,0 +1,513 @@ +// mmdb-shim — layer 1 of 4: scalar types, enums, and small record classes. +// +// This is the base layer of the gemmi-backed MMDB API shim (architecture B; see +// MMDB_SHIM_Recon_and_Plan.md). It provides MMDB's typedefs/enums, the per-object +// UDData+selection base (UDStore), forward declarations of the hierarchy classes, +// and the leaf "record" classes that carry no hierarchy (LINK / CISPEP / Cryst / +// Helix / Sheet / SymOps / Title …). Included first by the layers below. +#pragma once + +#include +#include // trim_str — normalise MMDB-padded names to gemmi's trimmed form +#include +#include // space-group / symmetry operators + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace mmdb { + + // ---- basic MMDB scalar/typedefs (real MMDB: mmdb_mattype.h / mmdb_defs.h) ---- + typedef double realtype; + typedef char *pstr; + typedef const char *cpstr; + typedef unsigned short word; + typedef char AtomName[20]; + typedef char ResName[20]; + typedef char InsCode[10]; + typedef char ChainID[10]; + typedef char Element[10]; + typedef char AltLoc[20]; + typedef char SegID[10]; + typedef char LinkRID[20]; // Refmac link ID + typedef unsigned char byte; // mmdb_mattype.h + typedef int *ivector; // mmdb_mattype.h 1-based vectors/matrices + typedef realtype *rvector; + typedef ivector *imatrix; + typedef rvector *rmatrix; + typedef char maxMMDBName[40]; + + // WhatIsSet mask flags (mmdb_atom.h ASET_FLAG) + enum ASET_FLAG { + ASET_Coordinates = 0x00000001, + ASET_Occupancy = 0x00000002, + ASET_tempFactor = 0x00000004, + ASET_CoordSigma = 0x00000010, + ASET_OccSigma = 0x00000020, + ASET_tFacSigma = 0x00000040, + ASET_Charge = 0x00000080, + ASET_Anis_tFac = 0x00000100, + ASET_Anis_tFSigma = 0x00001000, + ASET_All = 0x000FFFFF + }; + + // vector/matrix types (mmdb_defs.h) — plain fixed-size arrays of realtype + typedef realtype vect3[3]; + typedef realtype vect4[4]; + typedef vect3 mat33[3]; // realtype[3][3] + typedef vect4 mat44[4]; // realtype[4][4] + typedef mat44 *pmat44; + typedef mat44 &rmat44; + + enum ERROR_CODE { + Error_NoError = 0, + Error_CantOpenFile = 12, // matches real MMDB's value + Error_GeneralError1 = 1 + }; + + // ---- UDData (user-defined data) — real MMDB values (mmdb_uddata.h) ---- + enum UDR_TYPE { UDR_ATOM = 0, + UDR_RESIDUE = 1, + UDR_CHAIN = 2, + UDR_MODEL = 3, + UDR_HIERARCHY = 4 }; + enum UDDATA_CODE { UDDATA_Ok = 0, + UDDATA_WrongHandle = -1, + UDDATA_WrongUDRType = -2, + UDDATA_NoData = -3 }; + + // ---- Selection (real MMDB values: mmdb_selmngr.h) ---- + enum SELECTION_TYPE { STYPE_INVALID = -1, + STYPE_UNDEFINED = 0, + STYPE_ATOM = 1, + STYPE_RESIDUE = 2, + STYPE_CHAIN = 3, + STYPE_MODEL = 4 }; + enum SELECTION_KEY { SKEY_NEW = 0, + SKEY_OR = 1, + SKEY_AND = 2, + SKEY_XOR = 3, + SKEY_CLR = 4, + SKEY_XAND = 100 }; + inline const long int MinInt4 = -2147483647; + inline const long int MaxInt4 = 2147483647; + inline const int ANY_RES = -2147483647; // real MMDB: extern const == MinInt4 + inline const double Pi = 3.14159265358979323846; + + // PDB/CIF read flags (mmdb_io_file.h). Values are arbitrary distinct bits — the + // shim's SetFlag is a no-op, so only distinctness matters for Coot's bit ops. + enum MMDB_READ_FLAG { + MMDBF_AutoSerials = 0x00000001, + MMDBF_IgnoreDuplSeqNum = 0x00000002, + MMDBF_IgnoreBlankLines = 0x00000004, + MMDBF_IgnoreRemarks = 0x00000008, + MMDBF_IgnoreHash = 0x00000010, + MMDBF_IgnoreNonCoorPDBErrors = 0x00000020, + MMDBF_PrintCIFWarnings = 0x00000040, + MMDBF_All = 0x0000FFFF + }; + enum MMDB_FCM { MMDBFCM_None = 0, + MMDBFCM_All = 1, + MMDBFCM_Coord = 2, + MMDBFCM_Cryst = 4, + MMDBFCM_SC = 8 }; + typedef int COPY_MASK; // Coot uses `COPY_MASK cm = MMDBFCM_All` + bit arithmetic + + // Per-object UDData slots + selection membership bits. Each registered UDData + // handle maps to a (type,kind,slot); the object stores contiguous vectors + // indexed by slot. `_inSel[selHnd-1]` = is this object in selection selHnd + // (maintained by Manager::Select/SelectSphere/DeleteSelection). + struct UDStore { + std::vector _udi; + std::vector _udr; + std::vector _uds; + std::vector _inSel; + bool isInSelection(int selHnd) const { + return selHnd >= 1 && selHnd <= (int)_inSel.size() && _inSel[selHnd - 1]; + } + void _setInSel(int selHnd, bool v) { + if ((int)_inSel.size() < selHnd) _inSel.resize(selHnd, false); + _inSel[selHnd - 1] = v; + } + }; + + class Atom; + class Residue; + class Chain; + class Model; + class Manager; + typedef Atom *PAtom; + typedef Atom **PPAtom; + typedef Residue *PResidue; + typedef Residue **PPResidue; + typedef Chain *PChain; + typedef Chain **PPChain; + typedef Model *PModel; + typedef Model **PPModel; + typedef Manager *PManager; + typedef Manager **PPManager; + + struct Contact { + int id1, id2; + long group; + realtype dist; + }; + typedef Contact *PContact; + + // base for records held in MMDB containers (Title compound/author, LINK, …) + class ContainerClass { + public: + virtual ~ContainerClass() {} + }; + typedef ContainerClass *PContainerClass; + + // LINK record. Public data members mirror real MMDB (Coot reads them directly). + // Populated from gemmi Structure::connections on load (Manager::_load_metadata); + // Coot-created links are appended via Model::AddLink. + class Link : public ContainerClass { + public: + AtomName atName1{}, atName2{}; + AltLoc aloc1{}, aloc2{}; + ResName resName1{}, resName2{}; + ChainID chainID1{}, chainID2{}; + InsCode insCode1{}, insCode2{}; + int seqNum1 = 0, seqNum2 = 0; + int s1 = 1, i1 = 0, j1 = 0, k1 = 0; // symmetry id of 1st atom + int s2 = 1, i2 = 0, j2 = 0, k2 = 0; // symmetry id of 2nd atom + realtype dist = 0; + void Copy(PContainerClass o) { + if (auto *l = dynamic_cast(o)) *this = *l; + } + }; + typedef Link *PLink; + typedef Link **PPLink; + + // Refmac LINK record (mmdb_model.h LinkR). Public members mirror real MMDB; + // populated from gemmi Connections carrying a link_id (Manager::_load_metadata). + class LinkR { + public: + LinkRID linkRID{}; + AtomName atName1{}, atName2{}; + AltLoc aloc1{}, aloc2{}; + ResName resName1{}, resName2{}; + ChainID chainID1{}, chainID2{}; + int seqNum1 = 0, seqNum2 = 0; + InsCode insCode1{}, insCode2{}; + realtype dist = 0; + }; + typedef LinkR *PLinkR; + typedef LinkR **PPLinkR; + + // CIS-peptide record (mmdb_model.h CisPep). Public members mirror real MMDB; + // populated from gemmi Structure::cispeps on load (Manager::_load_metadata). + class CisPep { + public: + int serNum = 0; + ResName pep1{}; + ChainID chainID1{}; + int seqNum1 = 0; + InsCode icode1{}; + ResName pep2{}; + ChainID chainID2{}; + int seqNum2 = 0; + InsCode icode2{}; + int modNum = 0; + realtype measure = 0; + }; + typedef CisPep *PCisPep; + + // Container of LINK records (mmdb_model.h LinkContainer). Minimal: Coot only + // declares `empty_links_container()` returning one by value; never dereferenced. + class LinkContainer { + public: + std::vector data; + int Length() { return (int)data.size(); } + PContainerClass GetContainerClass(int i) { return (i >= 0 && i < (int)data.size()) ? data[i] : nullptr; } + }; + typedef LinkContainer *PLinkContainer; + + // PDB title records (mmdb_title.h). Coot subclasses Manager & Title to reach the + // COMPND/AUTHOR line containers. The AUTHOR container is filled from gemmi + // meta.authors on load and the TITLE string comes from Structure::get_info + // ("_struct.title"); COMPND/JRNL have no structured gemmi home, so those + // containers stay empty. + class Compound : public ContainerClass { + public: + char Line[256] = {0}; + }; + typedef Compound *PCompound; + class Author : public ContainerClass { + public: + char Line[256] = {0}; + }; + typedef Author *PAuthor; + class Journal : public ContainerClass { + public: + char Line[256] = {0}; + }; + typedef Journal *PJournal; + class TitleContainer { + public: + std::vector data; + int Length() { return (int)data.size(); } + PContainerClass GetContainerClass(int i) { + return (i >= 0 && i < (int)data.size()) ? data[i] : nullptr; + } + }; + class Title { + public: + TitleContainer compound, author, journal; // public so Coot's access_title can reach them + TitleContainer *GetCompound() { return &compound; } // real Title exposes these + TitleContainer *GetAuthor() { return &author; } // publicly; access_title + TitleContainer *GetJournal() { return &journal; } // inherits GetJournal() + }; + + // gzip mode flag (mmdb_io_file.h). Minimal mmdb::io — the shim does I/O via gemmi, + // so only this compression-mode enum is provided (Coot passes it to write calls). + namespace io { + enum GZ_MODE { GZM_NONE = 0, + GZM_CHECK = 1, + GZM_ENFORCE = 2 }; + } + + // initialise a 4x4 matrix to identity (mmdb_mattype.h Mat4Init) + inline void Mat4Init(mat44 &A) { + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 4; ++j) A[i][j] = (i == j) ? 1.0 : 0.0; + } + + // Orthogonal symmetry transformation for operator Nop (0-based) + integer cell + // shifts, from a gemmi cell + space group. The op acts in fractional space; we + // conjugate it with the cell frac<->orth transforms so TMatrix maps orthogonal + // coordinates directly (MMDB semantics). Returns 0 on success, 1 if there is no + // usable space group / the operator is out of range. Shared by Manager and Cryst. + inline int gemmi_sym_tmatrix(const gemmi::UnitCell &cell, const std::string &sg_name, + mat44 &TMatrix, int Nop, int a, int b, int c) { + Mat4Init(TMatrix); + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(sg_name); + if (!sg || !cell.is_crystal()) return 1; + gemmi::GroupOps gops = sg->operations(); + if (Nop < 0 || Nop >= (int)gops.order()) return 1; + int i = 0; + gemmi::Op op; + for (gemmi::Op o : gops) { + if (i++ == Nop) { + op = o; + break; + } + } + gemmi::Transform sym{gemmi::rot_as_mat33(op), + gemmi::tran_as_vec3(op) + gemmi::Vec3(a, b, c)}; + gemmi::Transform t = cell.orth.combine(sym).combine(cell.frac); + for (int r = 0; r < 3; ++r) { + for (int cc = 0; cc < 3; ++cc) TMatrix[r][cc] = t.mat.a[r][cc]; + TMatrix[r][3] = t.vec.at(r); + } + return 0; + } + + // Crystal/symmetry record (mmdb_cryst.h). Holds a gemmi cell + space-group name + // and computes symmetry through the shared helper — same result as Manager for a + // populated Cryst (Manager is the usual live symmetry path). + class Cryst { + public: + gemmi::UnitCell cell; + std::string spaceGroup; + virtual ~Cryst() {} + int GetTMatrix(mat44 &T, int Nop, int a, int b, int c) { + return gemmi_sym_tmatrix(cell, spaceGroup, T, Nop, a, b, c); + } + int GetNumberOfSymOps() { + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(spaceGroup); + return sg ? (int)sg->operations().order() : 0; + } + pstr GetSymOp(int Nop) { + const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name(spaceGroup); + if (!sg) return nullptr; + int i = 0; + for (gemmi::Op op : sg->operations()) + if (i++ == Nop) { + _symop_buf = op.triplet(); + return (pstr)_symop_buf.c_str(); + } + return nullptr; + } + + private: + std::string _symop_buf; + }; + typedef Cryst *PCryst; + + // mmdb::math graph-matching subsystem — full classes defined in _graph_impl.hh + // (included at end of this file, after Atom/Residue are complete). Only the + // Alignment class (unused by the cootapi build) stays a forward decl. + namespace math { + class Alignment; + } + + struct AtomBond { + PAtom atom = nullptr; + int order = 0; + }; + typedef AtomBond *PAtomBond; + typedef AtomBond **PPAtomBond; + + struct AtomStat { // selection coordinate statistics (mmdb_atom.h) + int nAtoms = 0; + realtype xmin = 0, ymin = 0, zmin = 0, xmax = 0, ymax = 0, zmax = 0; + realtype xm = 0, ym = 0, zm = 0; // coordinate means (centroid) + realtype GetMaxSize() { + realtype dx = xmax - xmin, dy = ymax - ymin, dz = zmax - zmin; + return dx > dy ? (dx > dz ? dx : dz) : (dy > dz ? dy : dz); + } + }; + typedef AtomStat &RAtomStat; + + // secondary-structure element codes (mmdb_tables.h) + enum SSE_CODE { SSE_None = 0, + SSE_Strand = 1, + SSE_Bulge = 2, + SSE_3Turn = 3, + SSE_4Turn = 4, + SSE_5Turn = 5, + SSE_Helix = 6 }; + + // PDBCleanup flags (mmdb_root.h) — bit flags OR'd into PDBCleanup(word) + // misc return-code / sort-key enums (mmdb_cryst.h / mmdb_selmngr.h / mmdb_tables.h) + enum { SYMOP_Ok = 0, + SYMOP_NoLibFile = -1, + SYMOP_UnknownSpaceGroup = -2 }; + enum { SSERC_Ok = 0, + SSERC_noResidues = 1 }; + enum { SORT_CHAIN_ChainID_Asc = 0, + SORT_CHAIN_ChainID_Desc = 1 }; + enum { CNSORT_OFF = 0, + CNSORT_1INC = 1, + CNSORT_1DEC = 2, + CNSORT_2INC = 3, + CNSORT_2DEC = 4 }; + + enum PDB_CLEAN_FLAG { + PDBCLEAN_ATNAME = 0x00000001, + PDBCLEAN_TER = 0x00000002, + PDBCLEAN_CHAIN = 0x00000004, + PDBCLEAN_CHAIN_STRONG = 0x00000008, + PDBCLEAN_ALTCODE = 0x00000010, + PDBCLEAN_ALTCODE_STRONG = 0x00000020, + PDBCLEAN_SERIAL = 0x00000040, + PDBCLEAN_SEQNUM = 0x00000080, + PDBCLEAN_INDEX = 0x00000800, + PDBCLEAN_ELEMENT = 0x00001000, + PDBCLEAN_ELEMENT_STRONG = 0x00002000 + }; + + // SS records — public-member structs. Model::GetNumberOf{Helices,Sheets} are + // populated from gemmi Structure::{helices,sheets} on load (_load_metadata) and + // also fillable by Coot's own SS computation via the access_model subclass. + class Helix { + public: + ChainID initChainID{}, endChainID{}; + int initSeqNum = 0, endSeqNum = 0, serNum = 0, helixClass = 0, length = 0; + ResName initResName{}, endResName{}; + InsCode initICode{}, endICode{}; + char helixID[20]{}, comment[80]{}; + }; + class Strand { + public: + ChainID initChainID{}, endChainID{}; + int initSeqNum = 0, endSeqNum = 0, strandNo = 0, sense = 0; + ResName initResName{}, endResName{}; + InsCode initICode{}, endICode{}; + char sheetID[20]{}; + }; + class Sheet { + public: + int nStrands = 0; + Strand **strand = nullptr; + char sheetID[20]{}; + }; + class Sheets { + public: + int nSheets = 0; + Sheet **sheet = nullptr; + }; // filled from gemmi in _load_metadata + typedef Helix *PHelix; + typedef Strand *PStrand; + typedef Sheet *PSheet; + typedef Sheets *PSheets; + // container of helices (Model.helices); Coot's access_model subclass fills it. + class Helices { + public: + std::vector data; + void AddData(PHelix h) { + if (h) data.push_back(h); + } + int nHelices = 0; + }; + + // container of symmetry operators (mmdb_symop.h SymOps). Coot fills it from a + // space group; ops are xyz-triplet strings. + class SymOps { + std::vector ops; + std::deque buf; + + public: + int AddSymOp(cpstr xyz) { + ops.push_back(xyz ? xyz : ""); + return 0; + } + int GetNofSymOps() { return (int)ops.size(); } + pstr GetSymOp(int n) { + if (n < 0 || n >= (int)ops.size()) return nullptr; + buf.push_back(ops[n]); + return (pstr)buf.back().c_str(); + } + void FreeMemory() { ops.clear(); } + }; + + [[noreturn]] inline void unimpl(const char *w) { + throw std::logic_error(std::string("mmdb-shim: unimplemented: ") + w); + } + + // ---- free functions (mmdb_tables.h / mmdb_mattype.h) ---- + inline void InitMatType() {} // real MMDB inits static matrix-type tables; no-op here + inline cpstr GetErrorDescription(ERROR_CODE ec) { + switch (ec) { + case Error_NoError: + return "no error"; + case Error_CantOpenFile: + return "cannot open file"; + default: + return "MMDB error"; + } + } + inline realtype getVdWaalsRadius(cpstr element) { + return gemmi::Element(element ? element : "X").vdw_r(); + } + + // Borrowed empty C-string, returned by the delegating accessors when an object + // is detached (no parent) — real MMDB yields safe defaults, not a crash. + inline pstr mmdb_empty_pstr() { + static char e[1] = {0}; + return e; + } + + // UDData helpers (defined after Manager); each class forwards with its UDR type. + int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int v); + int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype v); + int ud_put(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, cpstr v); + int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, int &v); + int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, realtype &v); + int ud_get(Manager *mgr, UDR_TYPE myType, UDStore &s, int handle, pstr &v); + +} // namespace mmdb From fbb466f5538caf82547210de47e5e6dcb8d5c885 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Thu, 23 Jul 2026 09:37:17 +0100 Subject: [PATCH 17/23] CI only on master --- .github/workflows/build-coot-ubuntu.yml | 2 ++ .github/workflows/build-coot-with-coot-zerokara.yml | 2 ++ .github/workflows/build-libcootapi-ubuntu.yml | 2 ++ 3 files changed, 6 insertions(+) diff --git a/.github/workflows/build-coot-ubuntu.yml b/.github/workflows/build-coot-ubuntu.yml index 8d333ef72a..ea8c1c77e6 100644 --- a/.github/workflows/build-coot-ubuntu.yml +++ b/.github/workflows/build-coot-ubuntu.yml @@ -2,6 +2,8 @@ name: Coot CI Ubuntu on: push: + branches: + - main workflow_dispatch: jobs: diff --git a/.github/workflows/build-coot-with-coot-zerokara.yml b/.github/workflows/build-coot-with-coot-zerokara.yml index 7313fa7080..add2fe9a01 100644 --- a/.github/workflows/build-coot-with-coot-zerokara.yml +++ b/.github/workflows/build-coot-with-coot-zerokara.yml @@ -8,6 +8,8 @@ name: Coot CI (coot_zerokara build script) on: push: + branches: + - main workflow_dispatch: jobs: diff --git a/.github/workflows/build-libcootapi-ubuntu.yml b/.github/workflows/build-libcootapi-ubuntu.yml index 16159799a6..409d95f853 100644 --- a/.github/workflows/build-libcootapi-ubuntu.yml +++ b/.github/workflows/build-libcootapi-ubuntu.yml @@ -2,6 +2,8 @@ name: libcootapi CI Ubuntu on: push: + branches: + - main jobs: From 4470831412e742d21d1163807406ac74ab315318 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Thu, 23 Jul 2026 09:37:47 +0100 Subject: [PATCH 18/23] Add filter to test-molecules-container --- api/test-molecules-container.cc | 428 +++++++++++++++++--------------- 1 file changed, 227 insertions(+), 201 deletions(-) diff --git a/api/test-molecules-container.cc b/api/test-molecules-container.cc index 21c75afd9a..ad10ffd005 100644 --- a/api/test-molecules-container.cc +++ b/api/test-molecules-container.cc @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #define GLM_ENABLE_EXPERIMENTAL @@ -8301,18 +8303,42 @@ print_results_summary() { } +template +int run_test_maybe(const std::string& filter, Function test_func, const char* test_name, Args&&... args) { + std::string name_str(test_name); + + // If a filter is provided and the test name doesn't contain it, skip the test + if (!filter.empty() && name_str.find(filter) == std::string::npos) { + return 0; // Skipped test contributes 0 to the fail/error count + } + + // Run the actual test function + std::cout << "Running " << test_name << std::endl; + return run_test(test_func, test_name, std::forward(args)...); + std::cout << "Completed " << test_name << std::endl; +} int main(int argc, char **argv) { int status = 0; write_test_name("---"); bool last_test_only = false; - if (argc > 1) { - std::string arg(argv[1]); - if (arg == "last-test-only") + std::string filter = ""; + + // Parse command line arguments + for (int i = 1; i < argc; ++i) { + std::string arg(argv[i]); + + if (arg == "last-test-only") { last_test_only = true; + } + else if (arg == "--filter" && i + 1 < argc) { + filter = argv[++i]; // Get the next argument as the filter term + } + else if (arg.rfind("--filter=", 0) == 0) { // Handles --filter=my_test syntax + filter = arg.substr(9); + } } - int all_tests_status = 1; // fail! { @@ -8337,173 +8363,173 @@ int main(int argc, char **argv) { if (! last_test_only) { - status += run_test(test_new_position_for_atoms_in_residues, "new positions for atoms in residues", mc); - status += run_test(test_transformation_for_atom_selection, "transformation for atoms", mc); - status += run_test(test_copy_fragment_using_residue_range, "copy-fragment using residue range", mc); - status += run_test(test_density_correlation_validation, "density correlation validation", mc); - status += run_test(test_pepflips_using_difference_map, "Pepflips from Difference Map", mc); - status += run_test(test_difference_map_contours, "difference map density mesh", mc); - status += run_test(test_rota_dodecs_mesh, "rotamer dodecahedra mesh", mc); - status += run_test(test_rsr_using_residue_range, "rsr using residue range", mc); - status += run_test(test_rsr_using_multi_atom_cid, "multi-atom-cid RSR", mc); - status += run_test(test_copy_fragment_using_cid, "copy-fragment using cid", mc); - status += run_test(test_no_dictionary_residues, "no-dictionary residues", mc); - status += run_test(test_cis_trans, "cis_trans conversion", mc); - status += run_test(test_rsr_using_atom_cid, "rsr using atom cid", mc); - status += run_test(test_auto_fit_rotamer_1, "auto-fit rotamer", mc); - status += run_test(test_auto_fit_rotamer_2, "auto-fit rotamer t2", mc); - status += run_test(test_delete_molecule, "delete_moelcule", mc); - status += run_test(test_rama_balls_mesh, "rama balls mesh", mc); - status += run_test(test_density_mesh, "density mesh", mc); - status += run_test(test_updating_maps, "updating maps", mc); - status += run_test(test_delete_residue, "delete residue", mc); - status += run_test(test_delete_chain, "delete chain", mc); - status += run_test(test_fill_partial, "Fill partially-filled residues", mc); - status += run_test(test_delete_atom, "delete atom", mc); - status += run_test(test_pepflips, "pepflips", mc); - status += run_test(test_mutate, "mutate", mc); - status += run_test(test_rsr, "rsr", mc); - status += run_test(test_jed_flip, "JED Flip", mc); - status += run_test(test_add_water, "add waters", mc); - status += run_test(test_bonds_mesh, "bonds mesh", mc); - status += run_test(test_eigen_flip, "Eigen Flip", mc); - status += run_test(test_read_a_map, "read a map", mc); - status += run_test(test_add_compound, "add compound", mc); - status += run_test(test_weird_delete, "delete II", mc); - status += run_test(test_add_alt_conf, "add alt conf", mc); - status += run_test(test_delete_literal, "delete literal", mc); - status += run_test(test_side_chain_180, "side-chain 180", mc); - status += run_test(test_peptide_omega, "peptide omega", mc); + status += run_test_maybe(filter, test_new_position_for_atoms_in_residues, "new positions for atoms in residues", mc); + status += run_test_maybe(filter, test_transformation_for_atom_selection, "transformation for atoms", mc); + status += run_test_maybe(filter, test_copy_fragment_using_residue_range, "copy-fragment using residue range", mc); + status += run_test_maybe(filter, test_density_correlation_validation, "density correlation validation", mc); + status += run_test_maybe(filter, test_pepflips_using_difference_map, "Pepflips from Difference Map", mc); + status += run_test_maybe(filter, test_difference_map_contours, "difference map density mesh", mc); + status += run_test_maybe(filter, test_rota_dodecs_mesh, "rotamer dodecahedra mesh", mc); + status += run_test_maybe(filter, test_rsr_using_residue_range, "rsr using residue range", mc); + status += run_test_maybe(filter, test_rsr_using_multi_atom_cid, "multi-atom-cid RSR", mc); + status += run_test_maybe(filter, test_copy_fragment_using_cid, "copy-fragment using cid", mc); + status += run_test_maybe(filter, test_no_dictionary_residues, "no-dictionary residues", mc); + status += run_test_maybe(filter, test_cis_trans, "cis_trans conversion", mc); + status += run_test_maybe(filter, test_rsr_using_atom_cid, "rsr using atom cid", mc); + status += run_test_maybe(filter, test_auto_fit_rotamer_1, "auto-fit rotamer", mc); + status += run_test_maybe(filter, test_auto_fit_rotamer_2, "auto-fit rotamer t2", mc); + status += run_test_maybe(filter, test_delete_molecule, "delete_moelcule", mc); + status += run_test_maybe(filter, test_rama_balls_mesh, "rama balls mesh", mc); + status += run_test_maybe(filter, test_density_mesh, "density mesh", mc); + status += run_test_maybe(filter, test_updating_maps, "updating maps", mc); + status += run_test_maybe(filter, test_delete_residue, "delete residue", mc); + status += run_test_maybe(filter, test_delete_chain, "delete chain", mc); + status += run_test_maybe(filter, test_fill_partial, "Fill partially-filled residues", mc); + status += run_test_maybe(filter, test_delete_atom, "delete atom", mc); + status += run_test_maybe(filter, test_pepflips, "pepflips", mc); + status += run_test_maybe(filter, test_mutate, "mutate", mc); + status += run_test_maybe(filter, test_rsr, "rsr", mc); + status += run_test_maybe(filter, test_jed_flip, "JED Flip", mc); + status += run_test_maybe(filter, test_add_water, "add waters", mc); + status += run_test_maybe(filter, test_bonds_mesh, "bonds mesh", mc); + status += run_test_maybe(filter, test_eigen_flip, "Eigen Flip", mc); + status += run_test_maybe(filter, test_read_a_map, "read a map", mc); + status += run_test_maybe(filter, test_add_compound, "add compound", mc); + status += run_test_maybe(filter, test_weird_delete, "delete II", mc); + status += run_test_maybe(filter, test_add_alt_conf, "add alt conf", mc); + status += run_test_maybe(filter, test_delete_literal, "delete literal", mc); + status += run_test_maybe(filter, test_side_chain_180, "side-chain 180", mc); + status += run_test_maybe(filter, test_peptide_omega, "peptide omega", mc); // Molecular replacement tests (moved here to run before potentially-crashing tests) - status += run_test(test_patterson_from_map_using_mtz, "patterson from mtz", mc); - status += run_test(test_patterson_from_map_using_map, "patterson from map", mc); - status += run_test(test_self_rotation_function, "self rotation function", mc); - status += run_test(test_cross_rotation_function, "cross rotation function", mc); - status += run_test(test_crowther_rotation_function, "crowther rotation fn", mc); - status += run_test(test_crowther_rotation_with_model, "crowther with model", mc); - status += run_test(test_phased_translation_function, "phased translation fn", mc); - status += run_test(test_molecular_placement_pipeline, "MR pipeline", mc); - status += run_test(test_molecular_placement_pipeline_r_chain, "MR R-chain", mc); - - status += run_test(test_undo_and_redo, "undo and redo", mc); - status += run_test(test_undo_and_redo_2, "undo/redo 2", mc); - status += run_test(test_merge_molecules, "merge molecules", mc); - status += run_test(test_dictionary_bonds, "dictionary bonds", mc); - status += run_test(test_replace_fragment, "replace fragment", mc); - status += run_test(test_gaussian_surface, "Gaussian surface", mc); - status += run_test(test_missing_atoms_info, "missing atom info", mc); - status += run_test(test_move_molecule_here, "move_molecule_here", mc); - status += run_test(test_rotamer_validation, "rotamer validation", mc); - status += run_test(test_ligand_contact_dots, "ligand contact dots", mc); - status += run_test(test_difference_map_peaks, "Difference Map Peaks", mc); - status += run_test(test_rama_validation, "rama validation 2", mc); // for the plot, not the graph - status += run_test(test_ramachandran_analysis, "ramachandran analysis", mc); // for the graph, not the plot - status += run_test(test_non_standard_residues, "non-standard residues", mc); - status += run_test(test_import_cif_dictionary, "import cif dictionary", mc); - status += run_test(test_add_terminal_residue, "add terminal residue", mc); - status += run_test(test_sequence_generator, "Make a sequence string", mc); - status += run_test(test_instanced_rota_markup, "Instanced rotamer mesh", mc); - status += run_test(test_new_position_for_atoms,"New positions for atoms", mc); - status += run_test(test_molecular_representation, "Molecular representation mesh", mc); + status += run_test_maybe(filter, test_patterson_from_map_using_mtz, "patterson from mtz", mc); + status += run_test_maybe(filter, test_patterson_from_map_using_map, "patterson from map", mc); + status += run_test_maybe(filter, test_self_rotation_function, "self rotation function", mc); + status += run_test_maybe(filter, test_cross_rotation_function, "cross rotation function", mc); + status += run_test_maybe(filter, test_crowther_rotation_function, "crowther rotation fn", mc); + status += run_test_maybe(filter, test_crowther_rotation_with_model, "crowther with model", mc); + status += run_test_maybe(filter, test_phased_translation_function, "phased translation fn", mc); + status += run_test_maybe(filter, test_molecular_placement_pipeline, "MR pipeline", mc); + status += run_test_maybe(filter, test_molecular_placement_pipeline_r_chain, "MR R-chain", mc); + + status += run_test_maybe(filter, test_undo_and_redo, "undo and redo", mc); + status += run_test_maybe(filter, test_undo_and_redo_2, "undo/redo 2", mc); + status += run_test_maybe(filter, test_merge_molecules, "merge molecules", mc); + status += run_test_maybe(filter, test_dictionary_bonds, "dictionary bonds", mc); + status += run_test_maybe(filter, test_replace_fragment, "replace fragment", mc); + status += run_test_maybe(filter, test_gaussian_surface, "Gaussian surface", mc); + status += run_test_maybe(filter, test_missing_atoms_info, "missing atom info", mc); + status += run_test_maybe(filter, test_move_molecule_here, "move_molecule_here", mc); + status += run_test_maybe(filter, test_rotamer_validation, "rotamer validation", mc); + status += run_test_maybe(filter, test_ligand_contact_dots, "ligand contact dots", mc); + status += run_test_maybe(filter, test_difference_map_peaks, "Difference Map Peaks", mc); + status += run_test_maybe(filter, test_rama_validation, "rama validation 2", mc); // for the plot, not the graph + status += run_test_maybe(filter, test_ramachandran_analysis, "ramachandran analysis", mc); // for the graph, not the plot + status += run_test_maybe(filter, test_non_standard_residues, "non-standard residues", mc); + status += run_test_maybe(filter, test_import_cif_dictionary, "import cif dictionary", mc); + status += run_test_maybe(filter, test_add_terminal_residue, "add terminal residue", mc); + status += run_test_maybe(filter, test_sequence_generator, "Make a sequence string", mc); + status += run_test_maybe(filter, test_instanced_rota_markup, "Instanced rotamer mesh", mc); + status += run_test_maybe(filter, test_new_position_for_atoms,"New positions for atoms", mc); + status += run_test_maybe(filter, test_molecular_representation, "Molecular representation mesh", mc); // remove these for now - I know why they don't work and they are slow. - // status += run_test(test_rigid_body_fit, "Rigid-body fit", mc); - // status += run_test(test_ligand_fitting_here, "Ligand fitting here", mc); - // status += run_test(test_jiggle_fit, "Jiggle-fit", mc); - // status += run_test(test_jiggle_fit_with_blur, "Jiggle-fit-with-blur", mc); - // status += run_test(test_ligand_fitting_in_map, "ligand fitting in map", mc); - status += run_test(test_multiligands_lig_bonding, "Some multiligands bonding", mc); - status += run_test(test_gltf_export_via_api, "glTF via api", mc); - status += run_test(test_long_name_ligand_cif_merge, "Long-name ligand cif merge", mc); - status += run_test(test_user_defined_bond_colours_v3, "user-defined colours v3", mc); - status += run_test(test_gltf_export, "glTF export", mc); - status += run_test(test_5char_ligand_merge, "5-char ligand merge", mc); - status += run_test(test_thread_pool, "thread pool", mc); - // status += run_test(test_thread_launching, "thread launching", mc); // this is not a helpful test - status += run_test(test_cif_gphl_chem_comp_info, "extracting gphl info", mc); - // status += run_test(test_test_the_threading, "threading speed test", mc); // not helpful - // status += run_test(test_contouring_timing, "contouring timing", mc); // not helpful + // status += run_test_maybe(filter, test_rigid_body_fit, "Rigid-body fit", mc); + // status += run_test_maybe(filter, test_ligand_fitting_here, "Ligand fitting here", mc); + // status += run_test_maybe(filter, test_jiggle_fit, "Jiggle-fit", mc); + // status += run_test_maybe(filter, test_jiggle_fit_with_blur, "Jiggle-fit-with-blur", mc); + // status += run_test_maybe(filter, test_ligand_fitting_in_map, "ligand fitting in map", mc); + status += run_test_maybe(filter, test_multiligands_lig_bonding, "Some multiligands bonding", mc); + status += run_test_maybe(filter, test_gltf_export_via_api, "glTF via api", mc); + status += run_test_maybe(filter, test_long_name_ligand_cif_merge, "Long-name ligand cif merge", mc); + status += run_test_maybe(filter, test_user_defined_bond_colours_v3, "user-defined colours v3", mc); + status += run_test_maybe(filter, test_gltf_export, "glTF export", mc); + status += run_test_maybe(filter, test_5char_ligand_merge, "5-char ligand merge", mc); + status += run_test_maybe(filter, test_thread_pool, "thread pool", mc); + // status += run_test_maybe(filter, test_thread_launching, "thread launching", mc); // this is not a helpful test + status += run_test_maybe(filter, test_cif_gphl_chem_comp_info, "extracting gphl info", mc); + // status += run_test_maybe(filter, test_test_the_threading, "threading speed test", mc); // not helpful + // status += run_test_maybe(filter, test_contouring_timing, "contouring timing", mc); // not helpful //reinstate this test when mmdb chain selection works - // status += run_test(test_mmcif_atom_selection, "mmCIF atom selection", mc); + // status += run_test_maybe(filter, test_mmcif_atom_selection, "mmCIF atom selection", mc); //reinstate this test when gemmi is used for writing cif files - // status += run_test(test_mmcif_as_string, "mmCIF as string", mc); - status += run_test(test_pdb_as_string, "PDB as string", mc); - status += run_test(test_cif_writer, "mmCIF dictionary writer", mc); - status += run_test(test_residues_near_residues, "residues near residues", mc); - status += run_test(test_electro_molecular_representation, "electro molecular representation mesh", mc); - status += run_test(test_replace_fragment, "replace fragment", mc); - status += run_test(test_ncs_chains, "NCS chains", mc); - status += run_test(test_omega_5tig_cif, "Omega for 5tig cif", mc); - // status += run_test(test_jiggle_fit_params, "actually testing for goodness pr params", mc); // not useful - status += run_test(test_dark_mode_colours, "light vs dark mode colours", mc); - status += run_test(test_read_extra_restraints, "read extra restraints", mc); - status += run_test(test_map_histogram, "map histogram", mc); - status += run_test(test_auto_read_mtz, "auto-read-mtz", mc); - status += run_test(test_read_a_missing_map, "read a missing map file ", mc); - status += run_test(test_colour_map_by_other_map, "colour-map-by-other-map", mc); - status += run_test(test_something_filo, "Self something filo", mc); - status += run_test(test_self_restraints, "Self restraints mesh", mc); - status += run_test(test_other_user_defined_colours_other, "New colour test", mc); - status += run_test(test_is_em_map, "EM map flag is correctly set?", mc); - status += run_test(test_user_defined_bond_colours_v2, "user-defined bond colours v2", mc); + // status += run_test_maybe(filter, test_mmcif_as_string, "mmCIF as string", mc); + status += run_test_maybe(filter, test_pdb_as_string, "PDB as string", mc); + status += run_test_maybe(filter, test_cif_writer, "mmCIF dictionary writer", mc); + status += run_test_maybe(filter, test_residues_near_residues, "residues near residues", mc); + status += run_test_maybe(filter, test_electro_molecular_representation, "electro molecular representation mesh", mc); + status += run_test_maybe(filter, test_replace_fragment, "replace fragment", mc); + status += run_test_maybe(filter, test_ncs_chains, "NCS chains", mc); + status += run_test_maybe(filter, test_omega_5tig_cif, "Omega for 5tig cif", mc); + // status += run_test_maybe(filter, test_jiggle_fit_params, "actually testing for goodness pr params", mc); // not useful + status += run_test_maybe(filter, test_dark_mode_colours, "light vs dark mode colours", mc); + status += run_test_maybe(filter, test_read_extra_restraints, "read extra restraints", mc); + status += run_test_maybe(filter, test_map_histogram, "map histogram", mc); + status += run_test_maybe(filter, test_auto_read_mtz, "auto-read-mtz", mc); + status += run_test_maybe(filter, test_read_a_missing_map, "read a missing map file ", mc); + status += run_test_maybe(filter, test_colour_map_by_other_map, "colour-map-by-other-map", mc); + status += run_test_maybe(filter, test_something_filo, "Self something filo", mc); + status += run_test_maybe(filter, test_self_restraints, "Self restraints mesh", mc); + status += run_test_maybe(filter, test_other_user_defined_colours_other, "New colour test", mc); + status += run_test_maybe(filter, test_is_em_map, "EM map flag is correctly set?", mc); + status += run_test_maybe(filter, test_user_defined_bond_colours_v2, "user-defined bond colours v2", mc); // reinstate when add alt conf has been added - // status += run_test(test_alt_conf_and_rotamer, "Alt Conf then rotamer", mc); - status += run_test(test_editing_session_tutorial_1, "an Tutorial 1 editing session", mc); - status += run_test(test_broken_function, "Something was broken", mc); - status += run_test(test_delete_side_chain, "delete side chain", mc); - status += run_test(test_colour_rules, "colour rules", mc); - status += run_test(test_mmrrcc, "MMRRCC", mc); - status += run_test(test_instanced_bonds_mesh, "insta bonds mesh", mc); - status += run_test(test_instanced_bonds_mesh_v2, "test instanced bond selection v2", mc); - status += run_test(test_utils, "utils", mc); - status += run_test(test_svg, "svg string", mc); - status += run_test(test_superpose, "SSM superpose ", mc); - status += run_test(test_multi_colour_rules, "multi colour rules ", mc); - status += run_test(test_non_drawn_atoms, "non-drawn atoms", mc); - status += run_test(test_symmetry, "symmetry", mc); - status += run_test(test_add_hydrogen_atoms, "add hydrogen atoms", mc); - status += run_test(test_set_rotamer, "set rotamer ", mc); - status += run_test(test_alt_conf_and_rotamer_v2, "alt-conf and rotamer v2 ", mc); - status += run_test(test_moorhen_h_bonds, "moorhen H-bonds ", mc); - status += run_test(test_number_of_hydrogen_atoms, "number of hydrogen atoms ", mc); - status += run_test(test_cell, "cell", mc); - status += run_test(test_map_centre, "map centre", mc); - status += run_test(test_dragged_atom_refinement, "dragged atom refinement", mc); - status += run_test(test_bespoke_carbon_colour, "bespoke carbon colours ", mc); - status += run_test(test_replace_model_from_file, "replace model from file", mc); - status += run_test(test_user_defined_bond_colours, "user-defined bond colours", mc); - status += run_test(test_replace_map, "replace map from mtz", mc); - status += run_test(test_residue_name_group, "residue name group", mc); - status += run_test(test_mask_atom_selection, "mask atom selection", mc); - status += run_test(test_write_map_is_sane, "write map is sane", mc); - status += run_test(test_replace_large_fragment, "refine and replace large fragment", mc); - status += run_test(test_molecule_diameter, "molecule diameter", mc); - status += run_test(test_B_factor_multiply, "B-factor multiply", mc); - status += run_test(test_change_chain_id, "change chain id", mc); - status += run_test(test_17257, "read emd_17257.map.gz", mc); + // status += run_test_maybe(filter, test_alt_conf_and_rotamer, "Alt Conf then rotamer", mc); + status += run_test_maybe(filter, test_editing_session_tutorial_1, "an Tutorial 1 editing session", mc); + status += run_test_maybe(filter, test_broken_function, "Something was broken", mc); + status += run_test_maybe(filter, test_delete_side_chain, "delete side chain", mc); + status += run_test_maybe(filter, test_colour_rules, "colour rules", mc); + status += run_test_maybe(filter, test_mmrrcc, "MMRRCC", mc); + status += run_test_maybe(filter, test_instanced_bonds_mesh, "insta bonds mesh", mc); + status += run_test_maybe(filter, test_instanced_bonds_mesh_v2, "test instanced bond selection v2", mc); + status += run_test_maybe(filter, test_utils, "utils", mc); + status += run_test_maybe(filter, test_svg, "svg string", mc); + status += run_test_maybe(filter, test_superpose, "SSM superpose ", mc); + status += run_test_maybe(filter, test_multi_colour_rules, "multi colour rules ", mc); + status += run_test_maybe(filter, test_non_drawn_atoms, "non-drawn atoms", mc); + status += run_test_maybe(filter, test_symmetry, "symmetry", mc); + status += run_test_maybe(filter, test_add_hydrogen_atoms, "add hydrogen atoms", mc); + status += run_test_maybe(filter, test_set_rotamer, "set rotamer ", mc); + status += run_test_maybe(filter, test_alt_conf_and_rotamer_v2, "alt-conf and rotamer v2 ", mc); + status += run_test_maybe(filter, test_moorhen_h_bonds, "moorhen H-bonds ", mc); + status += run_test_maybe(filter, test_number_of_hydrogen_atoms, "number of hydrogen atoms ", mc); + status += run_test_maybe(filter, test_cell, "cell", mc); + status += run_test_maybe(filter, test_map_centre, "map centre", mc); + status += run_test_maybe(filter, test_dragged_atom_refinement, "dragged atom refinement", mc); + status += run_test_maybe(filter, test_bespoke_carbon_colour, "bespoke carbon colours ", mc); + status += run_test_maybe(filter, test_replace_model_from_file, "replace model from file", mc); + status += run_test_maybe(filter, test_user_defined_bond_colours, "user-defined bond colours", mc); + status += run_test_maybe(filter, test_replace_map, "replace map from mtz", mc); + status += run_test_maybe(filter, test_residue_name_group, "residue name group", mc); + status += run_test_maybe(filter, test_mask_atom_selection, "mask atom selection", mc); + status += run_test_maybe(filter, test_write_map_is_sane, "write map is sane", mc); + status += run_test_maybe(filter, test_replace_large_fragment, "refine and replace large fragment", mc); + status += run_test_maybe(filter, test_molecule_diameter, "molecule diameter", mc); + status += run_test_maybe(filter, test_B_factor_multiply, "B-factor multiply", mc); + status += run_test_maybe(filter, test_change_chain_id, "change chain id", mc); + status += run_test_maybe(filter, test_17257, "read emd_17257.map.gz", mc); // 2026-02-14-PE too many gemmi errors. Let's shut it down for now mc.set_use_gemmi(false); - status += run_test(test_get_diff_map_peaks, "get diff map peaks", mc); - status += run_test(test_shiftfield_b_factor_refinement, "Shiftfield B", mc); - status += run_test(test_non_drawn_CA_bonds, "non-drawn bonds in CA+LIGANDS", mc); - status += run_test(test_change_chain_id_1, "change chain-id filo-1", mc); - status += run_test(test_split_model, "Split model", mc); - status += run_test(test_make_ensemble, "Make Ensemble", mc); - status += run_test(test_end_delete_closed_molecules, "end delete close molecules", mc); - status += run_test(test_moorhen_h_bonds, "moorhen H-bonds ", mc); - status += run_test(test_texture_as_floats, "Texture as Floats ", mc); - status += run_test(test_n_map_sections, "N map sections ", mc); + status += run_test_maybe(filter, test_get_diff_map_peaks, "get diff map peaks", mc); + // status += run_test_maybe(filter, test_shiftfield_b_factor_refinement, "Shiftfield B", mc); + status += run_test_maybe(filter, test_non_drawn_CA_bonds, "non-drawn bonds in CA+LIGANDS", mc); + status += run_test_maybe(filter, test_change_chain_id_1, "change chain-id filo-1", mc); + status += run_test_maybe(filter, test_split_model, "Split model", mc); + status += run_test_maybe(filter, test_make_ensemble, "Make Ensemble", mc); + status += run_test_maybe(filter, test_end_delete_closed_molecules, "end delete close molecules", mc); + status += run_test_maybe(filter, test_moorhen_h_bonds, "moorhen H-bonds ", mc); + status += run_test_maybe(filter, test_texture_as_floats, "Texture as Floats ", mc); + status += run_test_maybe(filter, test_n_map_sections, "N map sections ", mc); #ifdef MAKE_ENHANCED_LIGAND_TOOLS - status += run_test(test_pdbe_dictionary_depiction, "pdbe dictionary depiction", mc); - // status += run_test(test_rdkit_mol, "RDKit mol", mc); + status += run_test_maybe(filter, test_pdbe_dictionary_depiction, "pdbe dictionary depiction", mc); + // status += run_test_maybe(filter, test_rdkit_mol, "RDKit mol", mc); #endif #ifdef USE_GEMMI - status += run_test(test_disappearing_ligand, "Disappearing ligand", mc); + status += run_test_maybe(filter, test_disappearing_ligand, "Disappearing ligand", mc); #endif // Note to self: // change the autofit_rotamer test so that it tests the change of positions of the atoms of the neighboring residues. @@ -8512,54 +8538,54 @@ int main(int argc, char **argv) { { #ifdef MAKE_ENHANCED_LIGAND_TOOLS #endif - // status += run_test(test_lsq_superpose, "LSQ superpose", mc); - // status += run_test(test_change_rotamer, "Change Rotamer (Filo)", mc); - // status += run_test(test_alpha_in_colour_holder, "Alpha value in colour holder", mc); - // status += run_test(test_gaussian_surface, "Gaussian surface", mc); - // status += run_test(test_Q_Score, "Q Score", mc); - // status += run_test(test_assign_sequence, "Assign Sequence", mc); - // status += run_test(test_undo_and_redo_2, "Undo and redo 2", mc); - // status += run_test(test_gltf_export_via_api, "glTF via api", mc); - // status += run_test(test_import_ligands_with_same_name_and_animated_refinement, "Test import ligands with same name and animated refinement", mc); - // status += run_test(test_dictionary_conformers, "Dictionary Conformers", mc); - // status += run_test(test_ligand_distortion, "Ligand Distortion", mc); - // status += run_test(test_import_LIG_dictionary, "Import LIG.cif", mc); - // status += run_test(test_tricky_ligand_problem, "Tricky Ligand import/refine", mc); - // status += run_test(test_dictionary_acedrg_atom_types, "Acedrg atom types", mc); - // status += run_test(test_dictionary_acedrg_atom_types_for_ligand, "Acedrg atom types for ligand", mc); - // status += run_test(test_long_name_ligand_cif_merge, "test long name ligand cif merge", mc); - // status += run_test(test_merge_ligand_and_gemmi_parse_mmcif, "test_merge_ligand_and_gemmi_parse_mmcif", mc); - // status += run_test(test_delete_two_add_one_using_gemmi, "test_delete_two_add_one_using_gemmi", mc); - // status += run_test(test_dictionary_atom_name_match, "dictionary atom names match", mc); - // status += run_test(test_average_position_functions, "average position functions", mc); - - // status += run_test(test_get_torsion, "get_torsion", mc); - // status += run_test(test_set_occupancy, "set occupancy", mc); - // status += run_test(test_missing_residues, "missing residues", mc); - // status += run_test(test_mutation_info, "mutation info", mc); - // status += run_test(test_scale_map, "scale_map", mc); - // status += run_test(test_add_RNA_residue, "add RNA residue", mc); - // status += run_test(test_HOLE, "HOLE", mc); - // status += run_test(test_is_nucleic_acid, "is nucleic acid?", mc); - // status += run_test(test_delete_all_carbohydrate, "delete all carbohydrate", mc); - // status += run_test(test_instanced_goodsell_style_mesh, "instanced goodsell style mesh", mc); - // status += run_test(test_map_vertices_histogram, "map vertices histogram", mc); - // status += run_test(test_non_XYZ_EM_map_status, "non-XYZ map status", mc); + // status += run_test_maybe(filter, test_lsq_superpose, "LSQ superpose", mc); + // status += run_test_maybe(filter, test_change_rotamer, "Change Rotamer (Filo)", mc); + // status += run_test_maybe(filter, test_alpha_in_colour_holder, "Alpha value in colour holder", mc); + // status += run_test_maybe(filter, test_gaussian_surface, "Gaussian surface", mc); + // status += run_test_maybe(filter, test_Q_Score, "Q Score", mc); + // status += run_test_maybe(filter, test_assign_sequence, "Assign Sequence", mc); + // status += run_test_maybe(filter, test_undo_and_redo_2, "Undo and redo 2", mc); + // status += run_test_maybe(filter, test_gltf_export_via_api, "glTF via api", mc); + // status += run_test_maybe(filter, test_import_ligands_with_same_name_and_animated_refinement, "Test import ligands with same name and animated refinement", mc); + // status += run_test_maybe(filter, test_dictionary_conformers, "Dictionary Conformers", mc); + // status += run_test_maybe(filter, test_ligand_distortion, "Ligand Distortion", mc); + // status += run_test_maybe(filter, test_import_LIG_dictionary, "Import LIG.cif", mc); + // status += run_test_maybe(filter, test_tricky_ligand_problem, "Tricky Ligand import/refine", mc); + // status += run_test_maybe(filter, test_dictionary_acedrg_atom_types, "Acedrg atom types", mc); + // status += run_test_maybe(filter, test_dictionary_acedrg_atom_types_for_ligand, "Acedrg atom types for ligand", mc); + // status += run_test_maybe(filter, test_long_name_ligand_cif_merge, "test long name ligand cif merge", mc); + // status += run_test_maybe(filter, test_merge_ligand_and_gemmi_parse_mmcif, "test_merge_ligand_and_gemmi_parse_mmcif", mc); + // status += run_test_maybe(filter, test_delete_two_add_one_using_gemmi, "test_delete_two_add_one_using_gemmi", mc); + // status += run_test_maybe(filter, test_dictionary_atom_name_match, "dictionary atom names match", mc); + // status += run_test_maybe(filter, test_average_position_functions, "average position functions", mc); + + // status += run_test_maybe(filter, test_get_torsion, "get_torsion", mc); + // status += run_test_maybe(filter, test_set_occupancy, "set occupancy", mc); + // status += run_test_maybe(filter, test_missing_residues, "missing residues", mc); + // status += run_test_maybe(filter, test_mutation_info, "mutation info", mc); + // status += run_test_maybe(filter, test_scale_map, "scale_map", mc); + // status += run_test_maybe(filter, test_add_RNA_residue, "add RNA residue", mc); + // status += run_test_maybe(filter, test_HOLE, "HOLE", mc); + // status += run_test_maybe(filter, test_is_nucleic_acid, "is nucleic acid?", mc); + // status += run_test_maybe(filter, test_delete_all_carbohydrate, "delete all carbohydrate", mc); + // status += run_test_maybe(filter, test_instanced_goodsell_style_mesh, "instanced goodsell style mesh", mc); + // status += run_test_maybe(filter, test_map_vertices_histogram, "map vertices histogram", mc); + // status += run_test_maybe(filter, test_non_XYZ_EM_map_status, "non-XYZ map status", mc); // put these up - // status += run_test(test_radius_of_gyration, "radius of gyration", mc); - // status += run_test(test_temperature_factor_of_atom, "temperature factor of atom", mc); - // status += run_test(test_water_spherical_variance, "water spherical variance", mc); - // status += run_test(test_dedust, "dedust", mc); .... maybe not this one - // status += run_test(test_atom_overlaps, "atom overlaps", mc); - // status += run_test(test_pucker_info, "pucker info", mc); - // status += run_test(test_set_residue_to_rotamer_number, "set residue", mc); - // status += run_test(test_inner_bond_kekulization, "inner-bond kekulization", mc); - // status += run_test(test_gaussian_surface_to_map_molecule, "gaussian-surface to map", mc); - // status += run_test(test_density_mesh, "density mesh", mc); - // status += run_test(test_molecular_placement_pipeline_r_chain, "MR R-chain", mc); - // status += run_test(test_molecular_placement_pipeline, "MR pipeline", mc); - status += run_test(test_rdkit_mol_pickle, "RDKit Mol Pickle", mc); + // status += run_test_maybe(filter, test_radius_of_gyration, "radius of gyration", mc); + // status += run_test_maybe(filter, test_temperature_factor_of_atom, "temperature factor of atom", mc); + // status += run_test_maybe(filter, test_water_spherical_variance, "water spherical variance", mc); + // status += run_test_maybe(filter, test_dedust, "dedust", mc); .... maybe not this one + // status += run_test_maybe(filter, test_atom_overlaps, "atom overlaps", mc); + // status += run_test_maybe(filter, test_pucker_info, "pucker info", mc); + // status += run_test_maybe(filter, test_set_residue_to_rotamer_number, "set residue", mc); + // status += run_test_maybe(filter, test_inner_bond_kekulization, "inner-bond kekulization", mc); + // status += run_test_maybe(filter, test_gaussian_surface_to_map_molecule, "gaussian-surface to map", mc); + // status += run_test_maybe(filter, test_density_mesh, "density mesh", mc); + // status += run_test_maybe(filter, test_molecular_placement_pipeline_r_chain, "MR R-chain", mc); + // status += run_test_maybe(filter, test_molecular_placement_pipeline, "MR pipeline", mc); + status += run_test_maybe(filter, test_rdkit_mol_pickle, "RDKit Mol Pickle", mc); if (status == n_tests) all_tests_status = 0; print_results_summary(); From 46b25b9d1021c1aecc81af1af5691f93113adb8d Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Thu, 23 Jul 2026 09:38:14 +0100 Subject: [PATCH 19/23] Add audit test to mmdb-shim --- mmdb-shim/build.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mmdb-shim/build.sh b/mmdb-shim/build.sh index 4fbeea8170..cf7bf0217b 100755 --- a/mmdb-shim/build.sh +++ b/mmdb-shim/build.sh @@ -37,6 +37,12 @@ $CXX $STD -DCOOT_USE_MMDB_SHIM -I"$HERE/include" -I"$GEMMI" \ -L"$(brew --prefix gemmi)/lib" -lgemmi_cpp -lz -o "$HERE/test/test_io" \ && "$HERE/test/test_io" "$PDB" | tail -1 +echo "=== audit test (symmetry / LINK / PutAtom / Sort / terminus / contacts via gemmi) ===" +$CXX $STD -DCOOT_USE_MMDB_SHIM -I"$HERE/include" -I"$GEMMI" \ + "$HERE/src/io.cc" "$HERE/src/contacts.cc" "$HERE/test/test_audit.cc" \ + -L"$(brew --prefix gemmi)/lib" -lgemmi_cpp -lz -o "$HERE/test/test_audit" \ + && "$HERE/test/test_audit" "$HERE/../1hr2_final.pdb" | tail -1 + echo "=== leaf integration test (real Coot mmdb idioms vs gemmi ground truth) ===" $CXX $STD -DCOOT_USE_MMDB_SHIM -I"$HERE/include" -I"$GEMMI" \ "$HERE/src/io.cc" "$HERE/test/test_leaf.cc" \ From 3f29fb6039017c58053107219b7c6d0e8f153e31 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Thu, 23 Jul 2026 15:06:16 +0100 Subject: [PATCH 20/23] Change new files to use shims --- api/coot-molecule-json.cc | 2 +- coot-utils/grid-balls.cc | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/api/coot-molecule-json.cc b/api/coot-molecule-json.cc index 2da99b68b0..1f32c10cb9 100644 --- a/api/coot-molecule-json.cc +++ b/api/coot-molecule-json.cc @@ -22,7 +22,7 @@ std::string coot::molecule_t::get_molecule_selection_as_json(const std::string & j["occupancy"] = at->occupancy(); j["name"] = sn; j["element"] = se; - j["altLoc"] = std::string(at->altLoc); + j["altLoc"] = std::string(at->altLoc()); return j; }; diff --git a/coot-utils/grid-balls.cc b/coot-utils/grid-balls.cc index c6b4d0185a..36b21f9df2 100644 --- a/coot-utils/grid-balls.cc +++ b/coot-utils/grid-balls.cc @@ -36,12 +36,12 @@ coot::grid_balls_t::get_extents(mmdb::Manager *mol) const { for (int iat=0; iatGetAtom(iat); if (! at->isTer()) { - if (at->x < mol_x_min) mol_x_min = at->x; - if (at->y < mol_y_min) mol_y_min = at->y; - if (at->z < mol_z_min) mol_z_min = at->z; - if (at->x > mol_x_max) mol_x_max = at->x; - if (at->y > mol_y_max) mol_y_max = at->y; - if (at->z > mol_z_max) mol_z_max = at->z; + if (at->x() < mol_x_min) mol_x_min = at->x(); + if (at->y() < mol_y_min) mol_y_min = at->y(); + if (at->z() < mol_z_min) mol_z_min = at->z(); + if (at->x() > mol_x_max) mol_x_max = at->x(); + if (at->y() > mol_y_max) mol_y_max = at->y(); + if (at->z() > mol_z_max) mol_z_max = at->z(); } } } @@ -253,10 +253,10 @@ namespace { mmdb::Atom *at, const std::string &residue_name) { double radius = -1.1; if (geom_p) - radius = geom_p->get_vdw_radius(std::string(at->name), residue_name, + radius = geom_p->get_vdw_radius(std::string(at->GetAtomName()), residue_name, imol, false); // heavy-atom VdW, as in KVFinder if (radius <= 0.0) - radius = element_to_vdw_radius(at->element); + radius = element_to_vdw_radius(at->GetElementName()); return static_cast(radius); } } @@ -286,7 +286,7 @@ coot::grid_balls_t::brick_the_model(mmdb::Manager *mol) { float radius = atom_vdw_radius(geom_p, imol, at, residue_name); // rasterise the VdW sphere into the grid - point_3d_t atom_pos(at->x, at->y, at->z); + point_3d_t atom_pos(at->x(), at->y(), at->z()); triple_index_t centre = mol_space_to_grid_point(atom_pos); int ir = static_cast(std::ceil(radius * n_grids_per_angstrom)); float radius_sqrd = radius * radius; @@ -353,7 +353,7 @@ coot::grid_balls_t::make_blocked_grid(float probe_radius) const { float radius = atom_vdw_radius(geom_p, imol, at, residue_name) + probe_radius; - point_3d_t atom_pos(at->x, at->y, at->z); + point_3d_t atom_pos(at->x(), at->y(), at->z()); triple_index_t centre = mol_space_to_grid_point(atom_pos); int ir = static_cast(std::ceil(radius * n_grids_per_angstrom)); float radius_sqrd = radius * radius; @@ -675,7 +675,7 @@ coot::grid_balls_t::compute_lining_residues_for(std::vector &cavs, flo mmdb::Atom *at = residue_p->GetAtom(iat); if (at->isTer()) continue; - point_3d_t ap(at->x, at->y, at->z); + point_3d_t ap(at->x(), at->y(), at->z()); triple_index_t centre = mol_space_to_grid_point(ap); std::set hit; // labels this atom is in contact with From f5ad3aa2f22411e88686c6d523174a0a657eeec5 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Thu, 23 Jul 2026 17:05:39 +0100 Subject: [PATCH 21/23] untrack coot assistant files --- python/coot_commands/agent.py | 324 -------------- python/coot_commands/agent_serve.py | 184 -------- python/coot_commands/context_tools.py | 72 --- python/coot_commands/new.py | 245 ---------- python/coot_commands/socket_client.py | 157 ------- python/coot_commands/speech.py | 154 ------- python/coot_commands/tools.py | 243 ---------- python/coot_commands/try.py | 120 ----- python/test_coot_tools.py | 615 -------------------------- 9 files changed, 2114 deletions(-) delete mode 100644 python/coot_commands/agent.py delete mode 100644 python/coot_commands/agent_serve.py delete mode 100644 python/coot_commands/context_tools.py delete mode 100644 python/coot_commands/new.py delete mode 100644 python/coot_commands/socket_client.py delete mode 100644 python/coot_commands/speech.py delete mode 100644 python/coot_commands/tools.py delete mode 100644 python/coot_commands/try.py delete mode 100644 python/test_coot_tools.py diff --git a/python/coot_commands/agent.py b/python/coot_commands/agent.py deleted file mode 100644 index 709ce68a88..0000000000 --- a/python/coot_commands/agent.py +++ /dev/null @@ -1,324 +0,0 @@ -# coot_commands/agent.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""Drive Coot from natural language with a small local model. - -This is the loop that ties a language model to the command registry: it -sends the user's request plus the command *tools* (see -:mod:`coot_commands.tools`) to a local, OpenAI-compatible chat endpoint, -runs whatever tool calls the model emits, feeds the results back, and -repeats until the model answers in plain text. - -The default endpoint is Ollama's OpenAI-compatible API -(``http://localhost:11434/v1/chat/completions``); any server speaking that -protocol works. A 7-8B instruct model with solid tool-calling - Qwen2.5-7B -or Qwen3-8B at 4-bit fits comfortably in 16 GB - is the target. Override -the model and URL with the ``COOT_AGENT_MODEL`` and ``COOT_AGENT_URL`` -environment variables, or the keyword arguments. - -Only the Python standard library is used, so there is no new build -dependency. The chat transport is injectable (the *chat* argument), which -keeps the loop itself testable without a running model server - and lets a -future in-process, GTK-thread-aware transport slot in without touching the -loop. - -Usage inside Coot's Python tab:: - - import coot_commands.agent as agent - print(agent.run_agent("go to residue A 45 and colour it by chain")) - -or standalone (drives Ollama; handlers no-op without Coot, so this also -exercises the loop end to end):: - - python3 -m coot_commands.agent "add a water near A 45" - -Note: :func:`run_agent` is synchronous and blocks on the model call. Called -from Coot's GUI thread it will freeze the display until it returns; wiring it -into the Command tab without blocking (a worker thread that marshals each tool -call back onto the main loop) is deliberately left as a follow-up. -""" - -from __future__ import annotations - -import json -import os -import urllib.error -import urllib.request -from typing import Any, Callable, Dict, List, Optional - -from coot_commands.tools import command_tools, custom_tools, execute_tool - -DEFAULT_URL = "http://localhost:11434/v1/chat/completions" -DEFAULT_MODEL = "gemma4" -# How many commands to expose per request when retrieval is on. A small model -# chooses far better from ~12 tools than from all ~90; see coot_commands.retrieval. -DEFAULT_TOP_K = 12 - -# A message-producing transport: given the running message list and the tool -# definitions, return the assistant's reply message (the OpenAI -# ``choices[0].message`` dict, with an optional ``tool_calls`` list). -ChatFn = Callable[[List[Dict[str, Any]], List[Dict[str, Any]]], Dict[str, Any]] - -SYSTEM_PROMPT = ( - "You are the assistant inside Coot, a program for building and refining " - "macromolecular models (proteins, nucleic acids, ligands) into experimental " - "density from X-ray crystallography or cryo-EM. You act by calling the " - "provided tools; each tool is a Coot command. Work in small steps: call one " - "tool at a time, use each result to decide the next, and finish with a short " - "plain-text summary of what you did.\n" - "\n" - "Molecules: every model and map has an integer molecule number, shared " - "across models and maps (e.g. model 0, map 1). When the user does not name a " - "molecule, omit that argument so the command acts on the active molecule. " - "Residues are referenced by chain and residue number, written 'A/45' or " - "'A 45'. When the user says 'here', 'this residue', 'the current residue' or " - "similar, call get_active_residue to find out which residue and model they " - "mean before acting.\n" - "\n" - "Structural-biology terms - map the user's shorthand to the right command. " - "Real-space refinement (RSR, 'refine') locally optimises atoms into the " - "density. A rotamer is a side-chain conformation; fitting or fixing a rotamer " - "picks the best-fitting one. A Ramachandran outlier is a residue with an " - "unusual backbone phi/psi combination. A peptide flip ('pepflip') rotates a " - "peptide bond by ~180 degrees to correct the backbone; a backrub is a small " - "local backbone adjustment. A clash is atoms too close together; C-beta " - "deviations and chiral-volume errors are geometry problems. ADPs (B-factors) " - "describe atomic displacement; occupancy is the fraction of an atom present; " - "an alt conf is an alternate conformation; OXT is the C-terminal oxygen. " - "Waters are ordered solvent; a ligand or monomer is a bound small molecule. " - "The refinement map is the map refinement uses; a 2Fo-Fc map shows density, " - "while a difference (Fo-Fc) map shows model-vs-data disagreement - green " - "(positive) peaks suggest missing atoms, red (negative) peaks suggest atoms " - "that should not be there. Validation flags these problems so you can fix " - "them.\n" - "\n" - "The conversation may span several requests: remember what you did earlier " - "(for example, a residue you just refined) and use it as context. Only call " - "tools that are provided, with the arguments they define - never invent a " - "tool or argument. If a request is ambiguous or very large in scope, do the " - "most sensible part and state what you assumed, or ask one brief clarifying " - "question." -) - - -def _normalise_chat_url(url: str) -> str: - """Accept a full endpoint or just a base, and return the chat endpoint. - - POSTing to the Ollama base URL (``http://localhost:11434``) returns 405 - Method Not Allowed, so we tolerate a base or a ``.../v1`` root and append - the ``/v1/chat/completions`` path, and strip a trailing slash (which - otherwise redirects). - """ - url = url.rstrip("/") - if url.endswith("/chat/completions"): - return url - if url.endswith("/v1"): - return url + "/chat/completions" - return url + "/v1/chat/completions" - - -def _ollama_chat(model: str, url: str, timeout: float, - messages: List[Dict[str, Any]], - tools: List[Dict[str, Any]]) -> Dict[str, Any]: - """Default transport: one round-trip to an OpenAI-compatible endpoint.""" - url = _normalise_chat_url(url) - payload = { - "model": model, - "messages": messages, - "tools": tools, - "tool_choice": "auto", - "stream": False, - # Low temperature: we want deterministic tool selection, not prose. - "temperature": 0.0, - } - data = json.dumps(payload).encode("utf-8") - req = urllib.request.Request( - url, data=data, headers={"Content-Type": "application/json"}) - try: - with urllib.request.urlopen(req, timeout=timeout) as resp: - body = json.loads(resp.read().decode("utf-8")) - except urllib.error.HTTPError as e: - # The server's body carries the real reason (e.g. "model 'x' not - # found"), which urllib otherwise hides behind a bare status code. - detail = e.read().decode("utf-8", "replace").strip() - raise RuntimeError( - f"chat request to {url} with model {model!r} failed " - f"(HTTP {e.code}): {detail}") from None - return body["choices"][0]["message"] - - -# Executes a tool by name with a dict of arguments, returning a result string. -# The default runs commands in-process; the GUI/agent_serve path injects one -# that runs them over the socket into a live Coot (see coot_commands.socket_client). -ExecuteFn = Callable[[str, Dict[str, Any]], str] - -# Receives structured progress events so a consumer (the GUI transcript, a test) -# can observe the run without parsing printed text. Event shapes: -# {"type": "tools", "names": [...]} -# {"type": "step", "tool": name, "args": {...}, "result": "..."} -# {"type": "final", "text": "..."} -# {"type": "stopped","steps": n} -EventFn = Callable[[Dict[str, Any]], None] - - -def _run_tool_calls(tool_calls: List[Dict[str, Any]], - execute: ExecuteFn, - emit: EventFn) -> List[Dict[str, Any]]: - """Execute each tool call, returning the ``role: tool`` reply messages.""" - replies = [] - for call in tool_calls: - function = call.get("function", {}) - name = function.get("name", "") - raw_args = function.get("arguments") or "{}" - try: - args = json.loads(raw_args) if isinstance(raw_args, str) else raw_args - except json.JSONDecodeError: - args = {} - result = execute(name, args) - emit({"type": "step", "tool": name, "args": args, "result": result}) - replies.append({ - "role": "tool", - "tool_call_id": call.get("id", ""), - "content": result, - }) - return replies - - -def _retrieved_tools(user_text: str, top_k: int, - emit: EventFn) -> List[Dict[str, Any]]: - """Tools for the commands most relevant to *user_text*, top_k of them. - - Falls back to the full command set if retrieval fails (e.g. the embedding - model is not pulled or the server is down) so a request never breaks just - because the optional embeddings are unavailable. - """ - from coot_commands import retrieval - try: - names = retrieval.select_tools(user_text, top_k) - emit({"type": "tools", "names": names}) - return command_tools(names) - except Exception as e: # noqa: BLE001 - retrieval is best-effort - emit({"type": "tools", "names": [], "error": str(e)}) - return command_tools() - - -def _make_emit(on_event: Optional[EventFn], verbose: bool) -> EventFn: - """Build the event sink: fans out to *on_event* and/or a human-readable print.""" - def emit(event: Dict[str, Any]) -> None: - if on_event is not None: - on_event(event) - if verbose: - print(_format_event(event)) - return emit - - -def _format_event(event: Dict[str, Any]) -> str: - """Render an event as the one-line form the CLI/verbose mode prints.""" - kind = event.get("type") - if kind == "tools": - names = event.get("names") or [] - if event.get("error"): - return f" (retrieval unavailable: {event['error']}; using all tools)" - return f" (retrieved {len(names)} tools: {', '.join(names)})" - if kind == "step": - args = ", ".join(f"{k}={v!r}" for k, v in (event.get("args") or {}).items()) - return f" -> {event.get('tool')}({args}): {event.get('result')}" - if kind == "final": - return event.get("text", "") - if kind == "stopped": - return f"Stopped after {event.get('steps')} tool-calling rounds without a final answer." - return json.dumps(event) - - -def run_agent(user_text: str, *, - model: Optional[str] = None, - url: Optional[str] = None, - tools: Optional[List[Dict[str, Any]]] = None, - chat: Optional[ChatFn] = None, - execute: Optional[ExecuteFn] = None, - on_event: Optional[EventFn] = None, - messages: Optional[List[Dict[str, Any]]] = None, - top_k: Optional[int] = DEFAULT_TOP_K, - max_steps: int = 8, - timeout: float = 120.0, - verbose: bool = True) -> str: - """Fulfil *user_text* by letting the model call Coot commands. - - Returns the model's final plain-text reply. *chat* overrides the transport - (used by the tests); by default a fresh Ollama transport is built from - *model*/*url* (falling back to ``COOT_AGENT_MODEL``/``COOT_AGENT_URL`` then - the module defaults). *execute* overrides how a tool call is run (default: - in-process :func:`coot_commands.tools.execute_tool`; the GUI injects a - socket-backed executor into a live Coot). *on_event* receives structured - progress events (see :data:`EventFn`), for a GUI transcript or tests. - *messages* is the running conversation: pass the same list across calls to - give the agent memory of earlier requests (it is seeded with the system - prompt if empty and appended to in place); omit it for a one-shot call. - *tools* overrides the exposed command set; when it is ``None`` and *top_k* - is set, embedding retrieval narrows the ~90 commands to the *top_k* most - relevant (pass ``top_k=None`` to expose them all). *max_steps* caps the - tool-calling rounds so a confused model cannot loop forever. - """ - model = model or os.environ.get("COOT_AGENT_MODEL", DEFAULT_MODEL) - url = url or os.environ.get("COOT_AGENT_URL", DEFAULT_URL) - execute = execute or execute_tool - emit = _make_emit(on_event, verbose) - if tools is None: - commands = _retrieved_tools(user_text, top_k, emit) if top_k else command_tools() - # Custom context tools (e.g. get_active_residue) are always available, - # so "here"/"this residue" can be resolved whatever the request says. - tools = custom_tools() + commands - if chat is None: - def chat(messages, tools): - return _ollama_chat(model, url, timeout, messages, tools) - - # Seed a fresh conversation, or continue a caller-supplied one (giving the - # agent memory across requests); either way append this request's turn. - if messages is None: - messages = [{"role": "system", "content": SYSTEM_PROMPT}] - elif not messages: - messages.append({"role": "system", "content": SYSTEM_PROMPT}) - messages.append({"role": "user", "content": user_text}) - - for _step in range(max_steps): - message = chat(messages, tools) - messages.append(message) - tool_calls = message.get("tool_calls") - if not tool_calls: - text = (message.get("content") or "").strip() - emit({"type": "final", "text": text}) - return text - messages.extend(_run_tool_calls(tool_calls, execute, emit)) - - emit({"type": "stopped", "steps": max_steps}) - return ("Stopped after {} tool-calling rounds without a final answer." - .format(max_steps)) - - -def main(argv: Optional[List[str]] = None) -> int: - import sys - args = sys.argv[1:] if argv is None else argv - if not args: - sys.stderr.write('usage: python3 -m coot_commands.agent ""\n') - return 2 - # verbose=True already prints the step and final lines as they happen. - run_agent(" ".join(args), verbose=True) - return 0 - - -if __name__ == "__main__": - import sys - sys.exit(main()) diff --git a/python/coot_commands/agent_serve.py b/python/coot_commands/agent_serve.py deleted file mode 100644 index 2aa8b2e595..0000000000 --- a/python/coot_commands/agent_serve.py +++ /dev/null @@ -1,184 +0,0 @@ -# coot_commands/agent_serve.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""Run the agent as a subprocess that Coot's Assistant tab drives. - -This is the process Coot spawns for the Assistant tab. It reads one request -per line from ``stdin`` and writes newline-delimited JSON *events* to -``stdout``, so the GUI can stream progress without ever blocking on the slow -model calls (those happen here, in this separate process). Tool calls are -executed back in the live Coot over its socket -(:mod:`coot_commands.socket_client`), which runs them on Coot's main thread. - -Protocol --------- -Requests (one JSON object per line on stdin):: - - {"text": "load the tutorial data and refine A 89"} - -(a bare line of text is also accepted and treated as the ``text``). - -Events (one JSON object per line on stdout):: - - {"type": "ready"} - {"type": "tools", "names": [...]} - {"type": "step", "tool": "...", "args": {...}, "result": "..."} - {"type": "final", "text": "..."} - {"type": "error", "message": "..."} - {"type": "done"} # one per request, always last - -The port to reach Coot comes from ``COOT_RPC_PORT`` (Coot sets it when it -spawns us); the model and endpoints come from the same ``COOT_AGENT_*`` / -``COOT_EMBED_*`` environment as the standalone CLI. -""" - -from __future__ import annotations - -import json -import os -import sys -import urllib.error -import urllib.request -from typing import Any, Dict, Optional, TextIO -from urllib.parse import urlparse - -from coot_commands.agent import run_agent -from coot_commands.socket_client import CootSocketClient, make_socket_executor - - -def _emit(out: TextIO, event: Dict[str, Any]) -> None: - """Write one JSON event as a line and flush (the GUI reads line by line).""" - out.write(json.dumps(event) + "\n") - out.flush() - - -def _parse_request(line: str): - """Classify a stdin *line*: ``("reset", None)``, ``("text", str)`` or None. - - ``{"reset": true}`` starts a new conversation; ``{"text": "..."}`` (or a - bare, unquoted line) is a request; anything else is skipped. - """ - line = line.strip() - if not line: - return None - try: - parsed = json.loads(line) - except json.JSONDecodeError: - return ("text", line) # tolerate a bare, unquoted request line - if isinstance(parsed, dict): - if parsed.get("reset"): - return ("reset", None) - text = parsed.get("text") - if isinstance(text, str) and text.strip(): - return ("text", text) - return None - if isinstance(parsed, str): - return ("text", parsed) if parsed.strip() else None - return None - - -def _probe_ollama(timeout: float = 2.0): - """Check the model server is reachable; return ``(ok, detail)``. - - A GET to the server root is enough - Ollama answers it, and any HTTP - response (even an error status) proves the server is up. - """ - from coot_commands.agent import DEFAULT_URL, _normalise_chat_url - url = _normalise_chat_url(os.environ.get("COOT_AGENT_URL", DEFAULT_URL)) - parts = urlparse(url) - base = f"{parts.scheme}://{parts.netloc}" - try: - with urllib.request.urlopen(base, timeout=timeout) as resp: - resp.read(64) - return True, "" - except urllib.error.HTTPError as e: - return True, f"HTTP {e.code}" # the server responded, so it is reachable - except Exception as e: # noqa: BLE001 - any failure means unreachable - return False, str(e) - - -def _startup_status(client: CootSocketClient) -> Dict[str, Any]: - """Probe the RPC socket and the model server for a GUI readiness indicator.""" - from coot_commands.agent import DEFAULT_MODEL - model = os.environ.get("COOT_AGENT_MODEL", DEFAULT_MODEL) - rpc_ok, rpc_detail = True, "" - try: - client.connect() # also warms the connection reused for tool calls - except Exception as e: # noqa: BLE001 - rpc_ok, rpc_detail = False, str(e) - ollama_ok, ollama_detail = _probe_ollama() - return {"type": "status", "model": model, - "rpc": rpc_ok, "rpc_detail": rpc_detail, - "ollama": ollama_ok, "ollama_detail": ollama_detail} - - -def _context_stats(conversation: list) -> Dict[str, Any]: - """Approximate how much context the running conversation is using. - - We have no tokenizer here, so tokens are estimated at ~4 characters each - over the serialised messages - enough for a GUI "how full is the context" - indicator, labelled as approximate. - """ - return {"messages": len(conversation), - "approx_tokens": max(0, len(json.dumps(conversation)) // 4)} - - -def serve(stdin: TextIO, stdout: TextIO, *, - client: Optional[CootSocketClient] = None, - startup_status: bool = True) -> None: - """Read requests from *stdin*, stream events to *stdout*, until EOF. - - A single *conversation* is threaded across requests for the life of the - process, so the agent remembers earlier turns (a ``{"reset": true}`` line - starts a new one). *client* is injectable for testing; by default a real - socket client to Coot is created (connecting lazily on the first tool call). - On start it emits a ``status`` event (RPC + model reachability) for the GUI - readiness indicator, unless *startup_status* is false. - """ - client = client or CootSocketClient() - execute = make_socket_executor(client) - conversation: list = [] - _emit(stdout, {"type": "ready"}) - if startup_status: - _emit(stdout, _startup_status(client)) - - for line in stdin: - request = _parse_request(line) - if request is None: - continue - kind, text = request - if kind == "reset": - conversation = [] - _emit(stdout, {"type": "reset"}) - continue - try: - run_agent(text, messages=conversation, execute=execute, - on_event=lambda e: _emit(stdout, e), verbose=False) - except Exception as e: # noqa: BLE001 - report any failure to the GUI - _emit(stdout, {"type": "error", "message": str(e)}) - _emit(stdout, {"type": "context", **_context_stats(conversation)}) - _emit(stdout, {"type": "done"}) - - client.close() - - -def main() -> int: - serve(sys.stdin, sys.stdout) - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/python/coot_commands/context_tools.py b/python/coot_commands/context_tools.py deleted file mode 100644 index 7aa571ac67..0000000000 --- a/python/coot_commands/context_tools.py +++ /dev/null @@ -1,72 +0,0 @@ -# coot_commands/context_tools.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""Custom context tools for the assistant: live queries, not actions. - -These are :func:`~coot_commands.tools.custom_tool` handlers - always offered to -the model, unlike the retrieval-filtered commands - that let it read Coot's -current state so it can resolve what the user *means* before acting. The -motivating case: the user says "refine here" or "what's this residue?"; the -model calls :func:`get_active_residue` to learn the residue at the centre of -the screen, then acts on it. - -Importing this module registers the tools (it is imported by the package -``__init__``). Add a query here and it becomes available to the assistant with -no other wiring. They run wherever ``execute_tool`` runs - in-process, or -inside a live Coot over the socket - so the values are always current. -""" - -from __future__ import annotations - -from coot_commands.tools import custom_tool - -try: - import coot -except ImportError: - coot = None - - -@custom_tool( - "get_active_residue", - "Return the residue currently at the centre of the screen (the \"active\" " - "residue) as its chain, residue number and model number. Call this when the " - "user refers to \"here\", \"this residue\", \"the current residue\" or " - "similar, to find out which residue and model they mean before acting.") -def get_active_residue() -> str: - """Report the residue at the centre of the screen.""" - if coot is None: - return "the Coot API is not available" - active = coot.active_residue_py() - if not active: - return "No active residue - centre on a model first" - imol, chain, resno = active[0], active[1], active[2] - ins_code = active[3] if len(active) > 3 else "" - spec = f"{chain}/{resno}" + (f" (insertion code '{ins_code}')" if ins_code else "") - return f"Active residue: {spec} of model {imol}" - - -@custom_tool( - "get_active_map", - "Return the map molecule number currently set for refinement (the map that " - "refinement commands use). Call this to find out which map is active.") -def get_active_map() -> str: - """Report the molecule number of the map set for refinement.""" - if coot is None: - return "the Coot API is not available" - imol = coot.imol_refinement_map() - if imol is None or imol < 0: - return "No map is set for refinement - open a map first" - return f"Refinement map: molecule {imol}" diff --git a/python/coot_commands/new.py b/python/coot_commands/new.py deleted file mode 100644 index 48211594d2..0000000000 --- a/python/coot_commands/new.py +++ /dev/null @@ -1,245 +0,0 @@ -# coot_commands/new.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""Scaffold a new command from a pattern and examples. - -Writing the boilerplate by hand is the tedious part: the licence header, the -``import`` lines, and a handler signature whose parameters exactly match the -pattern's named groups (with the optional ones defaulting to ``None``). This -helper does that for you. - -It derives the signature *from the examples*: it matches each example against -the pattern, and a named group that is ``None`` in any example is treated as -optional (``= None``), the rest as required. So give at least one example that -omits each optional argument and the signature comes out right. - -Run it interactively:: - - python3 -m coot_commands.new - -It prints a ready-to-paste ``@command`` block. If you name a command *file* -that does not exist yet, it offers to create it (header + imports + the stub) -and reminds you to add it to ``python/Makefile.am``. It never edits an -existing file - appending blindly would put a specific pattern *after* the -general ones and get it shadowed (see ordering in ``doc/writing-commands.md``), -so for an existing file it prints the block for you to place by hand. -""" - -from __future__ import annotations - -import os -import re -import sys -from typing import List - -from coot_commands.registry import normalise - -_GROUP_RE = re.compile(r"\(\?P<([A-Za-z_]\w*)>") - -_HEADER = '''\ -# coot_commands/commands/{module}.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""{summary}""" - -from __future__ import annotations - -from typing import Optional - -from coot_commands.registry import command -from coot_commands.types import resolve_model, resolve_map, as_int, as_float, CommandError - -try: - import coot -except ImportError: - coot = None - - -CATEGORY = "{category}" -''' - - -def group_names(pattern: str) -> List[str]: - """The named groups in *pattern*, in order of appearance.""" - seen: List[str] = [] - for name in _GROUP_RE.findall(pattern): - if name not in seen: - seen.append(name) - return seen - - -def signature(pattern: str, examples: List[str]) -> str: - """Build the handler parameter list for *pattern* from its *examples*. - - A named group is optional (``name=None``) if it fails to participate in - at least one example match; otherwise it is required. Groups that never - appear in any successful match are assumed optional, to be safe. - """ - names = group_names(pattern) - if not names: - return "" - regex = re.compile(pattern, re.IGNORECASE) - optional = {name: False for name in names} - matched_any = False - for example in examples: - m = regex.match(normalise(example)) - if not m: - continue - matched_any = True - groups = m.groupdict() - for name in names: - if groups.get(name) is None: - optional[name] = True - if not matched_any: - optional = {name: True for name in names} - required = [n for n in names if not optional[n]] - opt = [n for n in names if optional[n]] - parts = [f"{n}: str" for n in required] - parts += [f"{n}: Optional[str] = None" for n in opt] - return ", ".join(parts) - - -def stub(name: str, pattern: str, examples: List[str], - help_text: str, notes: str) -> str: - """Render the ``@command`` decorator + handler stub as source text.""" - ex_lines = ", ".join(repr(e) for e in examples) or repr(pattern) - deco = [f'@command(r"{pattern}",', - f' examples=[{ex_lines}],', - f' category=CATEGORY,'] - if notes: - deco.append(f' notes={notes!r},') - # Drop trailing comma on the last kwarg, close the call. - deco[-1] = deco[-1].rstrip(",") + ")" - - sig = signature(pattern, examples) - doc = help_text or "TODO: one-line description." - body = [" \"\"\"" + doc + "\"\"\"", - " # TODO: resolve arguments and call the coot.* API, then return a", - " # short status string. Coerce captured strings via types.py helpers.", - " raise CommandError(\"not implemented yet\")"] - return "\n".join(deco + [f"def {name}({sig}) -> str:"] + body) + "\n" - - -def _prompt(label: str, default: str = "") -> str: - suffix = f" [{default}]" if default else "" - try: - value = input(f"{label}{suffix}: ").strip() - except EOFError: - value = "" - return value or default - - -def _prompt_examples() -> List[str]: - print("Examples (one per line, blank to finish; the first is canonical):") - examples: List[str] = [] - while True: - try: - line = input(" example> ").strip() - except EOFError: - break - if not line: - break - examples.append(line) - return examples - - -def interactive() -> int: - print("Scaffold a new Coot command. Ctrl-C to abort.\n") - name = _prompt("Handler function name (e.g. refine_chain)") - if not name.isidentifier(): - sys.stderr.write(f"error: {name!r} is not a valid function name\n") - return 1 - category = _prompt("Category", "General") - pattern = _prompt("Pattern (regex; named groups become arguments)") - if not pattern: - sys.stderr.write("error: a pattern is required\n") - return 1 - try: - re.compile(pattern) - except re.error as exc: - sys.stderr.write(f"error: pattern is not a valid regex: {exc}\n") - return 1 - examples = _prompt_examples() - help_text = _prompt("One-line help") - notes = _prompt("Notes (optional, longer prose for the docs)") - - # Validate the examples up front - the same check the test suite enforces. - regex = re.compile(pattern, re.IGNORECASE) - bad = [e for e in examples if not regex.match(normalise(e))] - if bad: - sys.stderr.write("\nwarning: these examples do NOT match the pattern " - "(fix the pattern or the example):\n") - for e in bad: - sys.stderr.write(f" {e!r}\n") - - block = stub(name, pattern, examples, help_text, notes) - - module = _prompt("\nTarget command module (file stem under commands/, " - "e.g. refine)") - print() - if not module: - print("# Paste this into a file in coot_commands/commands/:\n") - print(block) - return 0 - - here = os.path.dirname(os.path.abspath(__file__)) - path = os.path.join(here, "commands", f"{module}.py") - if os.path.exists(path): - print(f"# {module}.py already exists - not editing it (ordering matters:") - print("# specific patterns must come before general ones). Paste this in,") - print("# placing it above any more-general pattern:\n") - print(block) - return 0 - - summary = f"Commands for {category.lower()}." - contents = _HEADER.format(module=module, summary=summary, - category=category) + "\n\n" + block - with open(path, "w") as fh: - fh.write(contents) - print(f"wrote {path}") - print("\nNext:") - print(f" 1. add 'coot_commands/commands/{module}.py' to " - "python/Makefile.am (nobase_dist_pkgpython_PYTHON)") - print(" 2. implement the handler body (it raises NotImplemented for now)") - print(f" 3. dry-run it: python3 -m coot_commands.try " - f"{examples[0]!r}" if examples else - " 3. dry-run it with: python3 -m coot_commands.try ''") - return 0 - - -def main() -> int: - try: - return interactive() - except KeyboardInterrupt: - sys.stderr.write("\naborted\n") - return 130 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/python/coot_commands/socket_client.py b/python/coot_commands/socket_client.py deleted file mode 100644 index accec3235b..0000000000 --- a/python/coot_commands/socket_client.py +++ /dev/null @@ -1,157 +0,0 @@ -# coot_commands/socket_client.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""Talk to a running Coot from another process, over its JSON-RPC socket. - -The agent runs as a separate process (so its slow model calls never block -Coot's GUI), but its tool calls must reach the live Coot. Coot already -serves a length-prefixed JSON-RPC socket on localhost (see ``src/json-rpc.cc``, -started via ``make_socket_listener_maybe``); this client speaks that wire -format and runs a ``python.exec`` there. Because the server processes the -request on Coot's GTK idle function, the executed code runs on the main -thread - exactly where the Coot API is safe to call. - -The frame format is a 4-byte big-endian length prefix followed by the JSON -payload, in both directions. :meth:`CootSocketClient.exec_python` sends one -request and reads one response (a single client, used sequentially). - -:func:`make_socket_executor` adapts the client into the ``execute`` callback -that :func:`coot_commands.agent.run_agent` expects: it runs a command by -calling :func:`coot_commands.tools.execute_tool` *inside* Coot, so the same -registry and argument handling apply whether a command runs in-process or -over the socket. -""" - -from __future__ import annotations - -import json -import os -import socket -import struct -import time -from typing import Any, Dict, Optional - -DEFAULT_HOST = "127.0.0.1" -# Coot's default remote-control port (graphics_info_t::remote_control_port_number; -# vte.cc falls back to 9090 when it is unset). -DEFAULT_PORT = 9090 - - -class CootSocketError(RuntimeError): - """A transport-level failure talking to Coot (connection or protocol).""" - - -class CootSocketClient: - """A client for Coot's length-prefixed JSON-RPC socket.""" - - def __init__(self, host: str = DEFAULT_HOST, port: Optional[int] = None, - timeout: float = 30.0) -> None: - self.host = host - self.port = port if port is not None else int( - os.environ.get("COOT_RPC_PORT", DEFAULT_PORT)) - self.timeout = timeout - self._sock: Optional[socket.socket] = None - self._next_id = 1 - - def connect(self, retries: int = 15, delay: float = 0.2) -> None: - """Connect to Coot, retrying briefly so a startup race can't fail us. - - Coot brings the listener up and spawns this process at nearly the same - moment, so the first connect can land a hair too early. We retry for - ~*retries* x *delay* seconds before giving up with the last error. - """ - if self._sock is not None: - return - last_error: Optional[OSError] = None - for attempt in range(max(1, retries)): - try: - self._sock = socket.create_connection( - (self.host, self.port), timeout=self.timeout) - return - except OSError as e: - last_error = e - if attempt < retries - 1: - time.sleep(delay) - raise CootSocketError( - f"cannot connect to Coot at {self.host}:{self.port} after " - f"{retries} attempts: {last_error}") from None - - def close(self) -> None: - if self._sock is not None: - try: - self._sock.close() - finally: - self._sock = None - - def _send_frame(self, payload: bytes) -> None: - assert self._sock is not None - self._sock.sendall(struct.pack(">I", len(payload)) + payload) - - def _recv_exactly(self, n: int) -> bytes: - assert self._sock is not None - chunks = [] - remaining = n - while remaining > 0: - chunk = self._sock.recv(remaining) - if not chunk: - raise CootSocketError("Coot closed the connection") - chunks.append(chunk) - remaining -= len(chunk) - return b"".join(chunks) - - def _recv_frame(self) -> bytes: - (length,) = struct.unpack(">I", self._recv_exactly(4)) - return self._recv_exactly(length) - - def exec_python(self, code: str) -> str: - """Evaluate *code* (a single expression) in Coot; return its value string. - - Raises :class:`CootSocketError` on a transport failure or if the server - reports an error. - """ - self.connect() - request_id = self._next_id - self._next_id += 1 - request = { - "jsonrpc": "2.0", - "id": request_id, - "method": "python.exec", - "params": {"code": code}, - } - self._send_frame(json.dumps(request).encode("utf-8")) - response = json.loads(self._recv_frame().decode("utf-8")) - if "error" in response: - message = response["error"].get("message", "unknown error") - raise CootSocketError(f"Coot error: {message}") - result = response.get("result") or {} - return result.get("value", "") - - -def make_socket_executor(client: CootSocketClient): - """Return an ``execute(name, args)`` that runs a command inside Coot. - - The command runs via :func:`coot_commands.tools.execute_tool` on the Coot - side, as a single ``__import__`` expression so no separate import statement - is needed, mirroring how the Command tab evaluates its Python. - """ - def execute(name: str, args: Dict[str, Any]) -> str: - args_json = json.dumps(args) - code = ( - "__import__('coot_commands.tools', fromlist=['execute_tool'])" - ".execute_tool({name!r}, __import__('json').loads({args!r}))" - ).format(name=name, args=args_json) - return client.exec_python(code) - return execute diff --git a/python/coot_commands/speech.py b/python/coot_commands/speech.py deleted file mode 100644 index ef32727404..0000000000 --- a/python/coot_commands/speech.py +++ /dev/null @@ -1,154 +0,0 @@ -# coot_commands/speech.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""Turn dictated speech into the canonical text the command patterns expect. - -macOS Dictation (and other speech-to-text) types its transcription straight -into the focused field, so a spoken command arrives as ordinary text - but -worded the way people speak rather than the way the command regexes are -written. :func:`from_speech` rewrites those spoken forms into the canonical -tokens, and :func:`~coot_commands.registry.dispatch` runs it on every input, -so "superpose model zero onto model one" reaches the same handler as -"superpose model 0 onto model 1". - -It only ever rewrites number words, "point"/"minus" and spoken separators; a -command that is already typed with digits passes through unchanged, so this is -safe to run on all input, not just dictated input. No command keyword is a -number word, and the number words themselves are spelled distinctly from their -homophones ("two" not "to", "four" not "for"), so the rewrite does not clash -with the vocabulary. -""" - -from __future__ import annotations - -import re -from typing import List, Tuple - -_UNITS = { - "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, - "six": 6, "seven": 7, "eight": 8, "nine": 9, -} -_TEENS = { - "ten": 10, "eleven": 11, "twelve": 12, "thirteen": 13, "fourteen": 14, - "fifteen": 15, "sixteen": 16, "seventeen": 17, "eighteen": 18, - "nineteen": 19, -} -_TENS = { - "twenty": 20, "thirty": 30, "forty": 40, "fifty": 50, "sixty": 60, - "seventy": 70, "eighty": 80, "ninety": 90, -} -_NUMBER_WORDS = {**_UNITS, **_TEENS, **_TENS} - - -def _is_number_word(word: str) -> bool: - w = word.lower() - return w in _NUMBER_WORDS or w in ("hundred", "thousand") - - -def _parse_number(tokens: List[str], start: int) -> Tuple[int, int]: - """Parse a run of spoken number words at *start*. - - Returns ``(value, count)`` where *count* is how many tokens were consumed - (0 if *start* is not a number word). Follows ordinary English number - grammar - "forty five" -> 45, "one hundred twenty" -> 120 - but stops - rather than merging two bare units ("four five" -> 4, then 5), so a number - read out digit by digit is not silently turned into its sum. - """ - total = 0 # sum of scale-completed groups (… thousand) - current = 0 # the group being built - unit_open = False # a units/teens value has been placed in this group - count = 0 - saw = False - n = len(tokens) - - while start + count < n: - w = tokens[start + count].lower() - if w in _UNITS: - # A unit fits after a tens word ("forty" "five") or a hundred - # boundary, but never straight after another unit/teen - so a - # number read out digit by digit ("four" "five") is not merged. - if unit_open: - break - current += _NUMBER_WORDS[w] - unit_open = True - elif w in _TEENS: - # A teen (10-19) only starts a group or follows a hundred. - if unit_open or (current % 100) != 0: - break - current += _NUMBER_WORDS[w] - unit_open = True - elif w in _TENS: - if unit_open or (current % 100) != 0: - break - current += _NUMBER_WORDS[w] - elif w == "hundred" and saw: - current = (current or 1) * 100 - unit_open = False - elif w == "thousand" and saw: - total += (current or 1) * 1000 - current = 0 - unit_open = False - elif w == "and" and saw and start + count + 1 < n \ - and _is_number_word(tokens[start + count + 1]): - pass # spoken connector, e.g. "one hundred and five" - else: - break - saw = True - count += 1 - - if not saw: - return (0, 0) - return (total + current, count) - - -_POINT = re.compile(r"(\d) (?:point|dot) (\d)", re.IGNORECASE) -_NEGATIVE = re.compile(r"\b(?:minus|negative|dash) (\d)", re.IGNORECASE) -_SPACED_SLASH = re.compile(r" ?/ ?") - - -def from_speech(text: str) -> str: - """Rewrite dictated *text* into canonical command text. - - Idempotent on already-canonical (digit) input. - """ - if not text: - return text or "" - - collapsed = re.sub(r"\s+", " ", text.strip()) - if not collapsed: - return "" - - tokens = collapsed.split(" ") - out: List[str] = [] - i = 0 - while i < len(tokens): - value, consumed = _parse_number(tokens, i) - if consumed: - out.append(str(value)) - i += consumed - else: - out.append(tokens[i]) - i += 1 - result = " ".join(out) - - # "one point five" -> "1 point 5" -> "1.5" - result = _POINT.sub(r"\1.\2", result) - # "minus 5" / "negative 5" -> "-5" (for negative residue numbers) - result = _NEGATIVE.sub(r"-\1", result) - # spoken or spaced chain/residue separator -> a bare slash ("A / 45" -> "A/45") - result = result.replace(" slash ", "/").replace(" stroke ", "/") - result = _SPACED_SLASH.sub("/", result) - return result diff --git a/python/coot_commands/tools.py b/python/coot_commands/tools.py deleted file mode 100644 index 97a57f6e3a..0000000000 --- a/python/coot_commands/tools.py +++ /dev/null @@ -1,243 +0,0 @@ -# coot_commands/tools.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""Expose the command registry to a tool-calling language model. - -This is the bridge that lets a small local model (Gemma, Qwen, ...) drive -Coot: it turns each :func:`~coot_commands.registry.command` into an -OpenAI-style *tool* (a JSON schema of name, description and parameters) -and runs a tool call the model emits back through the registered handler. - -Nothing here talks to a model or a network - see :mod:`coot_commands.agent` -for the loop that does. Keeping the bridge separate means it is pure -Python and unit-testable without Coot or a model server: the command -modules ``try: import coot / except ImportError: coot = None``, so the -schemas build and (side-effect-free) handlers run standalone. - -Why not hand the model Coot's ~400 raw API functions? A 7-8B model -degrades badly past a few dozen tools. The curated ``@command`` set - each -with a one-line description and example phrasings - is a far better tool -surface, and :func:`command_tools` accepts a *names* subset so a future -retrieval step can narrow it further per request. - -The handler signature is the source of truth for a command's parameters: -by convention it mirrors the regex's named groups (e.g. -``go_to_residue(chain, resno, model=None)``), so :func:`inspect.signature` -yields both the parameter list and which are required (no default) versus -optional (default ``None``, resolved to the active molecule). -""" - -from __future__ import annotations - -import inspect -from typing import Any, Dict, Iterable, List, Optional - -from coot_commands.registry import Command, all_commands -from coot_commands.types import ArgType, CommandError - -# JSON-schema parameter descriptions per argument kind. The value the model -# supplies is always coerced to a string before the handler sees it (handlers -# expect the same strings the regex would capture), so every parameter is typed -# "string"; the ArgType only enriches the human-readable description. -_ARG_DESCRIPTIONS = { - ArgType.MODEL: "Model (molecule) number, e.g. \"0\".", - ArgType.MAP: "Map (molecule) number, e.g. \"1\".", - ArgType.COLOUR: "A colour name, e.g. \"red\" or \"sky blue\".", -} - -# What to add for an optional argument of a given kind: the fallback the shared -# resolvers apply when the model omits it (see coot_commands.types). -_ARG_OMIT_HINTS = { - ArgType.MODEL: " Omit to act on the active model.", - ArgType.MAP: " Omit to use the map set for refinement.", -} - - -def _handler_params(cmd: Command) -> List[inspect.Parameter]: - """The command's real arguments: named handler params, minus ``**kwargs``. - - Some handlers accept ``**_`` (they take no arguments but must swallow the - named groups ``dispatch`` would pass); those contribute no tool parameters. - """ - sig = inspect.signature(cmd.handler) - return [p for p in sig.parameters.values() - if p.kind in (inspect.Parameter.POSITIONAL_OR_KEYWORD, - inspect.Parameter.KEYWORD_ONLY)] - - -def _param_schema(cmd: Command, param: inspect.Parameter) -> Dict[str, Any]: - """JSON schema for one parameter, described using its :class:`ArgType`.""" - arg_type = cmd.arg_types.get(param.name) - required = param.default is inspect.Parameter.empty - description = _ARG_DESCRIPTIONS.get(arg_type, "") - if not required: - description += _ARG_OMIT_HINTS.get(arg_type, "") - schema: Dict[str, Any] = {"type": "string"} - if description: - schema["description"] = description.strip() - return schema - - -def _description(cmd: Command) -> str: - """The tool description: the command's help plus its example phrasings. - - Example phrasings matter a lot for a small model - they show the natural - language that maps to this command, so the model can pick the right tool - from an ambiguous request. - """ - text = (cmd.help_text or cmd.description or cmd.name).strip() - if cmd.examples: - text += "\n\nExample phrasings: " + "; ".join( - f'"{ex}"' for ex in cmd.examples[:4]) - return text - - -def command_to_tool(cmd: Command) -> Dict[str, Any]: - """Render one :class:`Command` as an OpenAI-style tool definition.""" - properties: Dict[str, Any] = {} - required: List[str] = [] - for param in _handler_params(cmd): - properties[param.name] = _param_schema(cmd, param) - if param.default is inspect.Parameter.empty: - required.append(param.name) - parameters: Dict[str, Any] = {"type": "object", "properties": properties} - if required: - parameters["required"] = required - return { - "type": "function", - "function": { - "name": cmd.name, - "description": _description(cmd), - "parameters": parameters, - }, - } - - -def _commands_by_name() -> Dict[str, Command]: - """Map tool name -> command, keeping the first on a name clash. - - Tool names must be unique; two commands sharing a handler ``__name__`` - (different modules, same function name) would otherwise collide, so we keep - the first-registered and skip the rest. - """ - by_name: Dict[str, Command] = {} - for cmd in all_commands(): - by_name.setdefault(cmd.name, cmd) - return by_name - - -def command_tools(names: Optional[Iterable[str]] = None) -> List[Dict[str, Any]]: - """Return tool definitions for the registered commands. - - Pass *names* to expose only a subset (e.g. the output of a retrieval step - that picked the commands relevant to a request); by default every command - is exposed. - """ - by_name = _commands_by_name() - selected = list(by_name) if names is None else [n for n in names if n in by_name] - return [command_to_tool(by_name[n]) for n in selected] - - -# Custom (context/query) tools: agent-only tools that are NOT @command regex -# handlers. A command is an ACTION triggered by typed or spoken language; a -# custom tool is typically a QUERY returning live context - e.g. the residue at -# the centre of the screen - so the model can resolve deictic references like -# "here", "this residue" or "the current position" before it acts. Register one -# with @custom_tool (see coot_commands.context_tools). They are always exposed -# to the model (never dropped by retrieval), since such context is relevant -# regardless of how a request is worded. -_CUSTOM_TOOLS: Dict[str, Dict[str, Any]] = {} - - -def custom_tool(name: str, description: str, - parameters: Optional[Dict[str, Any]] = None) -> Callable: - """Register *handler* as an agent tool named *name*. - - *parameters* is a JSON-schema object for the arguments (default: none). The - handler returns a result string (like a command handler); it receives the - model-supplied arguments as keyword arguments. - """ - schema_params = parameters or {"type": "object", "properties": {}} - - def decorator(handler: Callable[..., str]) -> Callable[..., str]: - _CUSTOM_TOOLS[name] = { - "schema": { - "type": "function", - "function": { - "name": name, - "description": description, - "parameters": schema_params, - }, - }, - "handler": handler, - } - return handler - - return decorator - - -def custom_tools() -> List[Dict[str, Any]]: - """Tool definitions for the always-available custom (context) tools.""" - return [entry["schema"] for entry in _CUSTOM_TOOLS.values()] - - -def _custom_kwargs(handler: Callable, arguments: Dict[str, Any]) -> Dict[str, Any]: - """Filter *arguments* to those the custom *handler* actually accepts.""" - sig = inspect.signature(handler) - if any(p.kind == inspect.Parameter.VAR_KEYWORD for p in sig.parameters.values()): - return dict(arguments) - allowed = {name for name, p in sig.parameters.items() - if p.kind in (inspect.Parameter.POSITIONAL_OR_KEYWORD, - inspect.Parameter.KEYWORD_ONLY)} - return {k: v for k, v in arguments.items() if k in allowed} - - -def execute_tool(name: str, arguments: Optional[Dict[str, Any]] = None) -> str: - """Run the tool *name* (custom tool or command) with *arguments*. - - Returns the handler's result string, or a readable error string (never - raises) so the agent loop can feed failures straight back to the model. - - Command arguments are coerced to strings and passed by the handler's - parameter name, mirroring exactly what ``registry.dispatch`` passes from a - regex ``groupdict`` - a missing argument arrives as ``None`` and the shared - resolvers fall back to the active molecule (or raise a clear - :class:`CommandError`). - """ - arguments = arguments or {} - - custom = _CUSTOM_TOOLS.get(name) - if custom is not None: - try: - return custom["handler"](**_custom_kwargs(custom["handler"], arguments)) - except CommandError as e: - return f"Error: {e}" - except Exception as e: # noqa: BLE001 - report any failure to the model - return f"Error running '{name}': {e}" - - cmd = _commands_by_name().get(name) - if cmd is None: - return f"Error: unknown command '{name}'" - kwargs = {} - for param in _handler_params(cmd): - value = arguments.get(param.name) - kwargs[param.name] = None if value is None else str(value) - try: - return cmd.handler(**kwargs) - except CommandError as e: - return f"Error: {e}" - except Exception as e: # noqa: BLE001 - report any handler failure to the model - return f"Error running '{name}': {e}" diff --git a/python/coot_commands/try.py b/python/coot_commands/try.py deleted file mode 100644 index 87e416c54e..0000000000 --- a/python/coot_commands/try.py +++ /dev/null @@ -1,120 +0,0 @@ -# coot_commands/try.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""Dry-run a command line against the registry without running Coot. - -Answers the two questions you actually have while writing a pattern: - -* **Which command wins?** ``dispatch`` runs the *first* registered - pattern that matches, so this shows that command, the arguments it would - be called with, and where it lives. -* **Is anything shadowing it?** It also lists every *other* command whose - pattern matches the same input. Those are unreachable for this input - (the first one wins) - a classic cause of "my new command never fires". - -It never calls the handler, so it is safe to run outside Coot:: - - python3 -m coot_commands.try "refine chain A" - -With no argument it reads lines from stdin, so you can pipe or type several -inputs to probe. -""" - -from __future__ import annotations - -import inspect -import sys -from typing import List, Optional, Tuple - -import coot_commands # noqa: F401 - imports all command modules so they register -from coot_commands.registry import Command, all_commands, normalise - - -def _location(cmd: Command) -> str: - """`file.py:line` for a command's handler, for a clickable pointer.""" - try: - path = inspect.getsourcefile(cmd.handler) or "?" - line = cmd.handler.__code__.co_firstlineno - return f"{path.rsplit('/', 1)[-1]}:{line}" - except (TypeError, OSError): - return "?" - - -def _format_call(cmd: Command, groups: dict) -> str: - """Render the handler call that would be made, e.g. ``f(chain='A')``.""" - args = ", ".join(f"{k}={v!r}" for k, v in groups.items()) - return f"{cmd.name}({args})" - - -def matches(text: str) -> List[Tuple[Command, dict]]: - """Every command whose pattern matches *text*, in registration order. - - The first entry is the one ``dispatch`` would run; the rest are - shadowed for this input. Each is paired with the captured groups - (``match.groupdict()``) it would pass to its handler. - """ - norm = normalise(text) - found = [] - for cmd in all_commands(): - m = cmd.regex.match(norm) - if m: - found.append((cmd, m.groupdict())) - return found - - -def explain(text: str) -> str: - """Human-readable dry-run report for a single input line.""" - norm = normalise(text) - found = matches(text) - lines = [f"input (normalised): {norm!r}", ""] - if not found: - lines.append("no command matched - nothing would run.") - return "\n".join(lines) - - winner, groups = found[0] - lines.append(f"MATCH {winner.name} [{winner.category}] {_location(winner)}") - if groups: - for key, value in groups.items(): - lines.append(f" {key} = {value!r}") - else: - lines.append(" (no arguments captured)") - lines.append(f" would call: {_format_call(winner, groups)}") - - if len(found) > 1: - lines.append("") - lines.append("also matched (shadowed - the first match above wins):") - for cmd, _ in found[1:]: - lines.append(f" {cmd.name} [{cmd.category}] {_location(cmd)}") - return "\n".join(lines) - - -def main(argv: Optional[List[str]] = None) -> int: - argv = list(sys.argv[1:] if argv is None else argv) - if argv: - print(explain(" ".join(argv))) - return 0 - # No argument: treat each stdin line as an input to probe. - for raw in sys.stdin: - line = raw.strip() - if not line: - continue - print(explain(line)) - print() - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/python/test_coot_tools.py b/python/test_coot_tools.py deleted file mode 100644 index 567242abb7..0000000000 --- a/python/test_coot_tools.py +++ /dev/null @@ -1,615 +0,0 @@ -# test_coot_tools.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""Standalone tests for the language-model bridge (no Coot, no model server). - -Run from the python/ directory: - - python3 test_coot_tools.py - -Covers coot_commands.tools (registry -> tool schemas, tool call -> handler) -and coot_commands.agent's loop with an injected fake transport, so nothing -here needs Coot or Ollama. Also discoverable by pytest. -""" - -import io -import json -import socket -import struct -import threading - -import coot_commands # noqa: F401 - triggers command discovery/registration -from coot_commands import agent -from coot_commands.registry import all_commands -from coot_commands.tools import command_to_tool, command_tools, execute_tool - - -def _tool_named(name): - for tool in command_tools(): - if tool["function"]["name"] == name: - return tool - return None - - -def test_every_command_becomes_a_valid_tool(): - tools = command_tools() - assert len(tools) == len({c.name for c in all_commands()}) - for tool in tools: - assert tool["type"] == "function" - fn = tool["function"] - assert isinstance(fn["name"], str) and fn["name"] - assert isinstance(fn["description"], str) and fn["description"] - params = fn["parameters"] - assert params["type"] == "object" - assert isinstance(params["properties"], dict) - - -def test_tool_names_are_unique(): - names = [t["function"]["name"] for t in command_tools()] - assert len(names) == len(set(names)) - - -def test_required_and_optional_params_from_signature(): - # go_to_residue(chain, resno, model=None): chain/resno required, model not. - tool = _tool_named("go_to_residue") - assert tool is not None - params = tool["function"]["parameters"] - assert set(params["properties"]) == {"chain", "resno", "model"} - assert set(params["required"]) == {"chain", "resno"} - - -def test_arg_type_enriches_description_and_omit_hint(): - tool = _tool_named("go_to_residue") - model_desc = tool["function"]["parameters"]["properties"]["model"]["description"] - assert "Model" in model_desc - assert "active" in model_desc # optional -> omit hint appended - - -def test_examples_included_in_description(): - tool = _tool_named("go_to_residue") - assert "Example phrasings" in tool["function"]["description"] - - -def test_kwargs_only_handler_has_no_params(): - # next_residue(**_) takes no real arguments. - tool = _tool_named("next_residue") - assert tool is not None - assert tool["function"]["parameters"]["properties"] == {} - assert "required" not in tool["function"]["parameters"] - - -def test_execute_tool_dispatches_to_handler(): - # centre_at_xyz runs without Coot (the coot-is-None branch returns a string). - out = execute_tool("centre_at_xyz", {"x": "12.0", "y": "4.5", "z": "-3.2"}) - assert out == "Centred at (12, 4.5, -3.2)" - - -def test_execute_tool_coerces_numeric_arguments_to_strings(): - # A model may emit JSON numbers, not strings; handlers expect strings. - out = execute_tool("centre_at_xyz", {"x": 1, "y": 2, "z": 3}) - assert out == "Centred at (1, 2, 3)" - - -def test_execute_unknown_tool_reports_error(): - out = execute_tool("no_such_command", {}) - assert out.startswith("Error: unknown command") - - -def test_execute_tool_reports_command_error(): - # A bad coordinate raises CommandError inside the handler; execute_tool - # turns it into a readable string rather than propagating. - out = execute_tool("centre_at_xyz", {"x": "not-a-number", "y": "0", "z": "0"}) - assert out.startswith("Error:") - - -def test_command_tools_subset_by_name(): - tools = command_tools(names=["go_to_residue", "no_such_command"]) - names = [t["function"]["name"] for t in tools] - assert names == ["go_to_residue"] # unknown names are dropped - - -def test_command_to_tool_matches_registry_entry(): - cmd = next(c for c in all_commands() if c.name == "centre_at_xyz") - tool = command_to_tool(cmd) - assert tool["function"]["name"] == "centre_at_xyz" - assert set(tool["function"]["parameters"]["properties"]) == {"x", "y", "z"} - - -# --- agent loop (fake transport) -------------------------------------------- - -def _fake_chat_script(*replies): - """Return a chat transport that yields *replies* in order, recording calls.""" - state = {"i": 0, "seen": []} - - def chat(messages, tools): - state["seen"].append((list(messages), tools)) - reply = replies[state["i"]] - state["i"] += 1 - return reply - - chat.state = state - return chat - - -def test_agent_runs_a_tool_call_then_returns_final_text(): - chat = _fake_chat_script( - {"role": "assistant", "content": None, "tool_calls": [ - {"id": "c1", "function": { - "name": "centre_at_xyz", - "arguments": json.dumps({"x": "1", "y": "2", "z": "3"})}}]}, - {"role": "assistant", "content": "Done - centred the view."}, - ) - out = agent.run_agent("centre at 1 2 3", chat=chat, top_k=None, verbose=False) - assert out == "Done - centred the view." - # The tool result must be fed back before the final turn. - final_messages = chat.state["seen"][-1][0] - tool_msgs = [m for m in final_messages if m.get("role") == "tool"] - assert tool_msgs and tool_msgs[0]["content"] == "Centred at (1, 2, 3)" - assert tool_msgs[0]["tool_call_id"] == "c1" - - -def test_agent_handles_reply_with_no_tool_calls(): - chat = _fake_chat_script({"role": "assistant", "content": "Hello!"}) - assert agent.run_agent("hi", chat=chat, top_k=None, verbose=False) == "Hello!" - - -def test_agent_stops_after_max_steps(): - loop_reply = {"role": "assistant", "content": None, "tool_calls": [ - {"id": "c", "function": {"name": "centre_at_xyz", - "arguments": "{\"x\":\"0\",\"y\":\"0\",\"z\":\"0\"}"}}]} - chat = _fake_chat_script(*([loop_reply] * 10)) - out = agent.run_agent("spin", chat=chat, max_steps=3, top_k=None, verbose=False) - assert "Stopped after 3" in out - assert chat.state["i"] == 3 - - -# --- retrieval (fake embeddings) -------------------------------------------- - -def _bag_of_words_embed(vocab): - """A fake embedder: each text -> a count vector over *vocab*. - - Deterministic and network-free, so retrieval ranking can be asserted: - documents sharing more query words score higher under cosine. - """ - def embed(texts): - vectors = [] - for text in texts: - words = text.lower().split() - vectors.append([float(words.count(term)) for term in vocab]) - return vectors - return embed - - -def test_retriever_ranks_by_similarity(): - from coot_commands.retrieval import ToolRetriever - vocab = ["water", "add", "refine", "residue", "centre", "colour"] - documents = { - "add_water": "add a water molecule", - "refine_residue": "refine a residue", - "set_colour": "set the colour", - } - retriever = ToolRetriever(documents, _bag_of_words_embed(vocab)) - assert retriever.select("add a water please", k=1) == ["add_water"] - assert retriever.select("refine this residue", k=1) == ["refine_residue"] - - -def test_retriever_k_limits_results_and_orders_them(): - from coot_commands.retrieval import ToolRetriever - vocab = ["water", "refine", "colour"] - documents = {"add_water": "water", "refine_residue": "refine", - "set_colour": "colour"} - retriever = ToolRetriever(documents, _bag_of_words_embed(vocab)) - top = retriever.select("water refine colour", k=2) - assert len(top) == 2 - - -def test_command_documents_cover_every_command(): - from coot_commands.retrieval import command_documents - docs = command_documents() - assert len(docs) == len({c.name for c in all_commands()}) - assert all(text.strip() for text in docs.values()) - - -def test_agent_uses_retrieved_subset_when_top_k_set(): - from coot_commands import retrieval - captured = {} - - def chat(messages, tools): - captured["tools"] = tools - return {"role": "assistant", "content": "ok"} - - fake = retrieval.ToolRetriever( - {"add_water": "add water", "refine_residue": "refine"}, - _bag_of_words_embed(["water", "refine", "add"])) - orig = retrieval._default_retriever - retrieval._default_retriever = fake - try: - agent.run_agent("add a water", chat=chat, top_k=1, verbose=False) - finally: - retrieval._default_retriever = orig - names = [t["function"]["name"] for t in captured["tools"]] - assert "add_water" in names # the retrieved command - assert "get_active_residue" in names # custom tools are pinned - - -def test_agent_falls_back_to_all_tools_when_retrieval_fails(): - from coot_commands import retrieval - - def boom(texts): - raise RuntimeError("no embedding server") - - captured = {} - - def chat(messages, tools): - captured["tools"] = tools - return {"role": "assistant", "content": "ok"} - - fake = retrieval.ToolRetriever({"add_water": "add water"}, boom) - orig = retrieval._default_retriever - retrieval._default_retriever = fake - try: - agent.run_agent("do something", chat=chat, top_k=5, verbose=False) - finally: - retrieval._default_retriever = orig - # Fallback exposes the full command set (plus the pinned custom tools). - from coot_commands.tools import custom_tools - assert len(captured["tools"]) == ( - len({c.name for c in all_commands()}) + len(custom_tools())) - - -def test_chat_url_normalisation(): - from coot_commands.agent import _normalise_chat_url as n - full = "http://127.0.0.1:11435/v1/chat/completions" - assert n("http://127.0.0.1:11435") == full # bare base (the 405 case) - assert n("http://127.0.0.1:11435/") == full # trailing slash - assert n("http://127.0.0.1:11435/v1") == full # v1 root - assert n(full) == full # already full: unchanged - assert n(full + "/") == full # full with trailing slash - - -def test_embed_url_normalisation(): - from coot_commands.retrieval import _normalise_embed_url as n - full = "http://127.0.0.1:11435/api/embed" - assert n("http://127.0.0.1:11435") == full - assert n("http://127.0.0.1:11435/") == full - assert n("http://127.0.0.1:11435/api") == full - assert n(full) == full - assert n(full + "/") == full - - -# --- pluggable executor + events ------------------------------------------- - -def test_run_agent_uses_injected_executor_and_emits_events(): - calls = [] - - def execute(name, args): - calls.append((name, args)) - return "did " + name - - events = [] - chat = _fake_chat_script( - {"role": "assistant", "content": None, "tool_calls": [ - {"id": "c1", "function": { - "name": "add_water", "arguments": "{}"}}]}, - {"role": "assistant", "content": "Added a water."}, - ) - out = agent.run_agent("add water", chat=chat, execute=execute, - on_event=events.append, top_k=None, verbose=False) - assert out == "Added a water." - assert calls == [("add_water", {})] # our executor ran - kinds = [e["type"] for e in events] - assert "step" in kinds and kinds[-1] == "final" - step = next(e for e in events if e["type"] == "step") - assert step["tool"] == "add_water" and step["result"] == "did add_water" - - -# --- socket client (loopback fake server) ----------------------------------- - -def _recv_exactly(conn, n): - buf = b"" - while len(buf) < n: - chunk = conn.recv(n - len(buf)) - if not chunk: - break - buf += chunk - return buf - - -def _fake_coot_server(responder): - """A one-shot loopback server framing like json-rpc.cc; returns its port.""" - srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - srv.bind(("127.0.0.1", 0)) - srv.listen(1) - port = srv.getsockname()[1] - - def run(): - conn, _ = srv.accept() - (length,) = struct.unpack(">I", _recv_exactly(conn, 4)) - request = json.loads(_recv_exactly(conn, length).decode("utf-8")) - payload = json.dumps(responder(request)).encode("utf-8") - conn.sendall(struct.pack(">I", len(payload)) + payload) - conn.close() - srv.close() - - threading.Thread(target=run, daemon=True).start() - return port - - -def test_socket_client_exec_python_returns_value(): - from coot_commands.socket_client import CootSocketClient - seen = {} - - def responder(req): - seen["req"] = req - return {"jsonrpc": "2.0", "id": str(req["id"]), - "result": {"value": "Centred on A/45"}} - - port = _fake_coot_server(responder) - client = CootSocketClient(port=port) - assert client.exec_python("1 + 1") == "Centred on A/45" - assert seen["req"]["method"] == "python.exec" - assert seen["req"]["params"]["code"] == "1 + 1" - client.close() - - -def test_socket_client_raises_on_server_error(): - from coot_commands.socket_client import CootSocketClient, CootSocketError - port = _fake_coot_server( - lambda req: {"jsonrpc": "2.0", "id": str(req["id"]), - "error": {"code": -32001, "message": "boom"}}) - client = CootSocketClient(port=port) - try: - client.exec_python("bad") - assert False, "expected CootSocketError" - except CootSocketError as e: - assert "boom" in str(e) - client.close() - - -def test_socket_executor_builds_execute_tool_call(): - from coot_commands.socket_client import CootSocketClient, make_socket_executor - seen = {} - - def responder(req): - seen["code"] = req["params"]["code"] - return {"jsonrpc": "2.0", "id": str(req["id"]), - "result": {"value": "Centred on A/45 of model 0"}} - - port = _fake_coot_server(responder) - execute = make_socket_executor(CootSocketClient(port=port)) - result = execute("go_to_residue", {"chain": "A", "resno": "45"}) - assert result == "Centred on A/45 of model 0" - # The generated code invokes execute_tool with the name and JSON args. - assert "execute_tool" in seen["code"] - assert "go_to_residue" in seen["code"] - assert '"chain": "A"' in seen["code"] or "'chain': 'A'" in seen["code"] - - -# --- agent_serve event loop ------------------------------------------------- - -def test_agent_serve_streams_events_per_request(monkeypatch=None): - from coot_commands import agent_serve - - # Stub run_agent so the serve loop is tested without a model: it drives one - # tool call through the injected executor and emits step/final events. - def fake_run_agent(text, *, messages, execute, on_event, verbose): - on_event({"type": "step", "tool": "load_tutorial", "args": {}, - "result": execute("load_tutorial", {})}) - on_event({"type": "final", "text": "done: " + text}) - - orig = agent_serve.run_agent - agent_serve.run_agent = fake_run_agent - - class FakeClient: - def exec_python(self, code): - return "Loaded the tutorial model and data" - - def close(self): - pass - - try: - stdin = io.StringIO('{"text": "load tutorial"}\n') - stdout = io.StringIO() - agent_serve.serve(stdin, stdout, client=FakeClient(), startup_status=False) - finally: - agent_serve.run_agent = orig - - events = [json.loads(line) for line in stdout.getvalue().splitlines()] - kinds = [e["type"] for e in events] - assert kinds[0] == "ready" - assert "step" in kinds - assert any(e["type"] == "final" and e["text"] == "done: load tutorial" - for e in events) - assert any(e["type"] == "context" and "approx_tokens" in e for e in events) - assert kinds[-1] == "done" - - -# --- custom (context) tools ------------------------------------------------- - -def test_custom_tools_are_registered_and_schematised(): - from coot_commands.tools import custom_tools - names = [t["function"]["name"] for t in custom_tools()] - assert "get_active_residue" in names - for tool in custom_tools(): - assert tool["type"] == "function" - assert tool["function"]["description"] - - -def test_execute_tool_dispatches_to_custom_tool(): - from coot_commands import tools - - @tools.custom_tool("unit_probe", "test probe", - parameters={"type": "object", - "properties": {"x": {"type": "string"}}}) - def _probe(x=None): - return f"probe:{x}" - - try: - assert tools.execute_tool("unit_probe", {"x": "7"}) == "probe:7" - # Unknown/extra args are filtered out, not passed through as a TypeError. - assert tools.execute_tool("unit_probe", {"x": "7", "bogus": "9"}) == "probe:7" - finally: - tools._CUSTOM_TOOLS.pop("unit_probe", None) - - -def test_get_active_residue_without_coot(): - # Standalone (no coot) it reports the API is unavailable rather than raising. - from coot_commands.tools import execute_tool - out = execute_tool("get_active_residue", {}) - assert "Coot API is not available" in out - - -def test_agent_pins_custom_tools_even_with_no_commands(): - captured = {} - - def chat(messages, tools): - captured["tools"] = tools - return {"role": "assistant", "content": "ok"} - - from coot_commands.tools import custom_tools - agent.run_agent("do nothing", chat=chat, tools=None, top_k=None, verbose=False) - names = [t["function"]["name"] for t in captured["tools"]] - for custom in custom_tools(): - assert custom["function"]["name"] in names - - -def test_run_agent_threads_conversation_across_calls(): - conversation = [] - chat1 = _fake_chat_script({"role": "assistant", "content": "refined A 42"}) - agent.run_agent("refine the worst residue", chat=chat1, - messages=conversation, top_k=None, verbose=False) - # The running conversation retains system + this turn. - assert [m["role"] for m in conversation] == ["system", "user", "assistant"] - - chat2 = _fake_chat_script({"role": "assistant", "content": "ok"}) - agent.run_agent("focus on the residue you just refined", chat=chat2, - messages=conversation, top_k=None, verbose=False) - # The second call sees the first turn's history (that's the memory). - seen = chat2.state["seen"][0][0] - contents = [m.get("content") for m in seen] - assert "refine the worst residue" in contents - assert "refined A 42" in contents - assert "focus on the residue you just refined" in contents - - -def test_agent_serve_threads_conversation_and_reset(): - from coot_commands import agent_serve - snapshots = [] - - def fake_run_agent(text, *, messages, execute, on_event, verbose): - snapshots.append(list(messages)) # history coming into this turn - messages.append({"role": "user", "content": text}) - messages.append({"role": "assistant", "content": "ok:" + text}) - on_event({"type": "final", "text": "ok:" + text}) - - class FakeClient: - def exec_python(self, code): - return "x" - - def close(self): - pass - - orig = agent_serve.run_agent - agent_serve.run_agent = fake_run_agent - try: - stdin = io.StringIO('{"text": "first"}\n{"text": "second"}\n' - '{"reset": true}\n{"text": "third"}\n') - stdout = io.StringIO() - agent_serve.serve(stdin, stdout, client=FakeClient(), startup_status=False) - finally: - agent_serve.run_agent = orig - - assert snapshots[0] == [] # first: no history - assert any(m.get("content") == "first" for m in snapshots[1]) # second sees first - assert snapshots[2] == [] # after reset: cleared - events = [json.loads(line) for line in stdout.getvalue().splitlines()] - assert any(e["type"] == "reset" for e in events) - - -def test_agent_serve_emits_startup_status(): - from coot_commands import agent_serve - - class FakeClient: - def connect(self): - pass # RPC reachable - - def exec_python(self, code): - return "x" - - def close(self): - pass - - orig_probe = agent_serve._probe_ollama - agent_serve._probe_ollama = lambda timeout=2.0: (True, "") - try: - stdout = io.StringIO() - agent_serve.serve(io.StringIO(""), stdout, client=FakeClient(), - startup_status=True) - finally: - agent_serve._probe_ollama = orig_probe - - events = [json.loads(line) for line in stdout.getvalue().splitlines()] - status = [e for e in events if e["type"] == "status"] - assert status, "expected a status event" - assert status[0]["rpc"] is True - assert status[0]["ollama"] is True - assert "model" in status[0] - - -def test_agent_serve_startup_status_reports_rpc_failure(): - from coot_commands import agent_serve - - class DeadClient: - def connect(self): - raise RuntimeError("connection refused") - - def close(self): - pass - - orig_probe = agent_serve._probe_ollama - agent_serve._probe_ollama = lambda timeout=2.0: (False, "no server") - try: - stdout = io.StringIO() - agent_serve.serve(io.StringIO(""), stdout, client=DeadClient(), - startup_status=True) - finally: - agent_serve._probe_ollama = orig_probe - - status = [json.loads(l) for l in stdout.getvalue().splitlines() - if json.loads(l)["type"] == "status"][0] - assert status["rpc"] is False and "refused" in status["rpc_detail"] - assert status["ollama"] is False - - -def _run(): - tests = [v for k, v in sorted(globals().items()) - if k.startswith("test_") and callable(v)] - failures = 0 - for test in tests: - try: - test() - print(f"PASS {test.__name__}") - except AssertionError as e: - failures += 1 - print(f"FAIL {test.__name__}: {e}") - print(f"\n{len(tests) - failures}/{len(tests)} passed") - return failures == 0 - - -if __name__ == "__main__": - import sys - sys.exit(0 if _run() else 1) From dd7ace4bba6a36f3981e39b2bae223ede89f93f2 Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Thu, 23 Jul 2026 17:11:23 +0100 Subject: [PATCH 22/23] Removed Coot Assistant infrastructure from this branch --- python/coot_commands/__init__.py | 4 - python/coot_commands/mic.py | 124 ---------- python/coot_commands/retrieval.py | 179 -------------- python/coot_commands/tts.py | 100 -------- src/vte.cc | 372 +----------------------------- 5 files changed, 1 insertion(+), 778 deletions(-) delete mode 100644 python/coot_commands/mic.py delete mode 100644 python/coot_commands/retrieval.py delete mode 100644 python/coot_commands/tts.py diff --git a/python/coot_commands/__init__.py b/python/coot_commands/__init__.py index 6edfb24488..6941e42a29 100644 --- a/python/coot_commands/__init__.py +++ b/python/coot_commands/__init__.py @@ -42,7 +42,3 @@ def _discover_command_modules() -> None: _discover_command_modules() - -# Register the custom context tools (get_active_residue, ...) that the assistant -# uses to read live state; see coot_commands.context_tools. -from . import context_tools # noqa: E402,F401 diff --git a/python/coot_commands/mic.py b/python/coot_commands/mic.py deleted file mode 100644 index f14e7e145f..0000000000 --- a/python/coot_commands/mic.py +++ /dev/null @@ -1,124 +0,0 @@ -# coot_commands/mic.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""Record a voice request from the microphone and output it as base64 WAV. - -Protocol (one JSON object per line on stdout): - {"type": "recording"} — microphone opened, recording has started - {"type": "audio", "data": "..."} — base64-encoded 16 kHz mono WAV, ready to send - {"type": "error", "message": "..."} - -Records until a period of silence is detected or the maximum duration is -reached. Requires ``sounddevice`` and ``numpy`` (pip install sounddevice numpy). -""" - -from __future__ import annotations - -import base64 -import io -import json -import sys -import wave - -SAMPLERATE = 16000 -SILENCE_THRESHOLD = 500 # RMS on int16 scale (0–32 768); tune to mic -SILENCE_DURATION = 1.5 # seconds of quiet that ends the recording -MAX_DURATION = 30.0 # hard cap in seconds - - -def _emit(obj: dict) -> None: - print(json.dumps(obj), flush=True) - - -def _record(samplerate: int = SAMPLERATE, - silence_threshold: float = SILENCE_THRESHOLD, - silence_duration: float = SILENCE_DURATION, - max_duration: float = MAX_DURATION): - import numpy as np - import sounddevice as sd - - chunk_s = 0.1 # 100 ms chunks - chunk_frames = int(samplerate * chunk_s) - max_chunks = int(max_duration / chunk_s) - silence_chunks_needed = int(silence_duration / chunk_s) - - chunks = [] - silent_count = 0 - speech_started = False - - with sd.InputStream(samplerate=samplerate, channels=1, dtype="int16") as stream: - for _ in range(max_chunks): - chunk, _ = stream.read(chunk_frames) - chunks.append(chunk.copy()) - rms = float(np.sqrt(np.mean(chunk.astype(np.float32) ** 2))) - if rms >= silence_threshold: - speech_started = True - silent_count = 0 - elif speech_started: - silent_count += 1 - if silent_count >= silence_chunks_needed: - break - - import numpy as np - return np.concatenate(chunks, axis=0) if chunks else np.zeros((0, 1), dtype="int16") - - -def _to_wav_b64(samples, samplerate: int = SAMPLERATE) -> str: - buf = io.BytesIO() - with wave.open(buf, "wb") as wf: - wf.setnchannels(1) - wf.setsampwidth(2) # int16 = 2 bytes per sample - wf.setframerate(samplerate) - wf.writeframes(samples.flatten().tobytes()) - return base64.b64encode(buf.getvalue()).decode("ascii") - - -def main() -> int: - try: - import numpy # noqa: F401 - except ImportError: - _emit({"type": "error", "message": "numpy not installed (pip install numpy)"}) - return 1 - try: - import sounddevice # noqa: F401 - except ImportError: - _emit({"type": "error", "message": "sounddevice not installed (pip install sounddevice)"}) - return 1 - - _emit({"type": "recording"}) - try: - samples = _record() - except Exception as exc: - _emit({"type": "error", "message": f"recording failed: {exc}"}) - return 1 - - import numpy as np - if samples.size == 0 or float(np.sqrt(np.mean(samples.astype(np.float32) ** 2))) < SILENCE_THRESHOLD / 2: - _emit({"type": "error", "message": "no speech detected"}) - return 1 - - try: - data = _to_wav_b64(samples) - except Exception as exc: - _emit({"type": "error", "message": f"WAV encoding failed: {exc}"}) - return 1 - - _emit({"type": "audio", "data": data}) - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/python/coot_commands/retrieval.py b/python/coot_commands/retrieval.py deleted file mode 100644 index f7d5b8f067..0000000000 --- a/python/coot_commands/retrieval.py +++ /dev/null @@ -1,179 +0,0 @@ -# coot_commands/retrieval.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""Pick the commands relevant to a request, so the model sees few tools. - -The bridge (:mod:`coot_commands.tools`) can emit all ~90 commands as tools, -but a small local model chooses far more reliably from a dozen than from -ninety. This module ranks the commands by semantic similarity to the -user's request and returns the top few names, which -:func:`coot_commands.tools.command_tools` then narrows to via its *names* -argument. - -Ranking uses text embeddings from a local, Ollama-style endpoint -(``/api/embed``, default model ``embeddinggemma`` - a ~300 MB pull; -override with ``COOT_EMBED_MODEL``). -Each command is embedded once from a short document built out of its name, -help, examples, category and notes; the query is embedded per request; we -return the commands with the highest cosine similarity. Embeddings are -memoised for the process, so only the first request pays to embed the -command set. - -As with :mod:`coot_commands.agent`, the embedding transport is injectable -(:class:`ToolRetriever` takes an *embed_fn*), so the ranking logic is -testable without a model server, and only the standard library is used. -""" - -from __future__ import annotations - -import json -import math -import os -import urllib.error -import urllib.request -from typing import Callable, Dict, List, Optional, Sequence - -from coot_commands.registry import Command, all_commands - -DEFAULT_EMBED_URL = "http://localhost:11434/api/embed" -DEFAULT_EMBED_MODEL = "embeddinggemma" - -# Embed a batch of texts -> one vector per text. -EmbedFn = Callable[[Sequence[str]], List[List[float]]] - - -def command_document(cmd: Command) -> str: - """The text embedded to represent a command for retrieval. - - Bundles every scrap of natural language the command carries - help, - example phrasings, category and notes - since domain terms a user might - use ("H-bond", "rotamer", "blur") often live in the notes rather than the - one-line help. - """ - parts = [cmd.name.replace("_", " "), cmd.help_text or cmd.description] - if cmd.examples: - parts.append("Examples: " + "; ".join(cmd.examples)) - parts.append("Category: " + cmd.category) - if cmd.notes: - parts.append(cmd.notes) - return ". ".join(p for p in parts if p) - - -def command_documents() -> Dict[str, str]: - """Map command name -> its retrieval document, for every command.""" - docs: Dict[str, str] = {} - for cmd in all_commands(): - docs.setdefault(cmd.name, command_document(cmd)) - return docs - - -def cosine(a: Sequence[float], b: Sequence[float]) -> float: - """Cosine similarity of two vectors; 0.0 if either is degenerate.""" - dot = sum(x * y for x, y in zip(a, b)) - na = math.sqrt(sum(x * x for x in a)) - nb = math.sqrt(sum(y * y for y in b)) - if na == 0.0 or nb == 0.0: - return 0.0 - return dot / (na * nb) - - -def _normalise_embed_url(url: str) -> str: - """Accept a full endpoint or just a base, and return the embed endpoint. - - POSTing to the Ollama base URL returns 405 Method Not Allowed, so we - tolerate a base or a ``.../api`` root and append the ``/api/embed`` path, - and strip a trailing slash (which otherwise redirects). - """ - url = url.rstrip("/") - if url.endswith("/api/embed"): - return url - if url.endswith("/api"): - return url + "/embed" - return url + "/api/embed" - - -def ollama_embed(texts: Sequence[str], *, - model: Optional[str] = None, - url: Optional[str] = None, - timeout: float = 60.0) -> List[List[float]]: - """Embed *texts* via an Ollama ``/api/embed`` endpoint (batched request).""" - model = model or os.environ.get("COOT_EMBED_MODEL", DEFAULT_EMBED_MODEL) - url = _normalise_embed_url(url or os.environ.get("COOT_EMBED_URL", DEFAULT_EMBED_URL)) - payload = {"model": model, "input": list(texts)} - data = json.dumps(payload).encode("utf-8") - req = urllib.request.Request( - url, data=data, headers={"Content-Type": "application/json"}) - try: - with urllib.request.urlopen(req, timeout=timeout) as resp: - body = json.loads(resp.read().decode("utf-8")) - except urllib.error.HTTPError as e: - # Surface the server's reason (e.g. "model 'x' not found") rather than a - # bare status code; this message reaches the agent's fallback log. - detail = e.read().decode("utf-8", "replace").strip() - raise RuntimeError( - f"embed request to {url} with model {model!r} failed " - f"(HTTP {e.code}): {detail}") from None - return body["embeddings"] - - -class ToolRetriever: - """Rank documents against a query using an embedding transport. - - *documents* maps a name to its text; *embed_fn* embeds a batch of texts. - Document embeddings are computed lazily on the first :meth:`select` and - cached for the retriever's lifetime. - """ - - def __init__(self, documents: Dict[str, str], embed_fn: EmbedFn) -> None: - self.documents = documents - self.embed_fn = embed_fn - self._names: Optional[List[str]] = None - self._vectors: Optional[List[List[float]]] = None - - def _ensure_embedded(self) -> None: - if self._names is None: - self._names = list(self.documents) - self._vectors = self.embed_fn([self.documents[n] for n in self._names]) - - def select(self, query: str, k: int) -> List[str]: - """Return the *k* document names most similar to *query*, best first.""" - self._ensure_embedded() - query_vec = self.embed_fn([query])[0] - scored = sorted( - zip(self._names, self._vectors), - key=lambda nv: cosine(query_vec, nv[1]), - reverse=True, - ) - return [name for name, _ in scored[:k]] - - -# Process-wide default retriever over the registry, embedded via Ollama. Built -# lazily so importing this module never touches the network. -_default_retriever: Optional[ToolRetriever] = None - - -def default_retriever() -> ToolRetriever: - """The shared retriever over all registered commands (Ollama embeddings).""" - global _default_retriever - if _default_retriever is None: - _default_retriever = ToolRetriever(command_documents(), ollama_embed) - return _default_retriever - - -def select_tools(query: str, k: int = 12, - retriever: Optional[ToolRetriever] = None) -> List[str]: - """Command names most relevant to *query* (convenience over the default).""" - return (retriever or default_retriever()).select(query, k) diff --git a/python/coot_commands/tts.py b/python/coot_commands/tts.py deleted file mode 100644 index 5e0adcd8ff..0000000000 --- a/python/coot_commands/tts.py +++ /dev/null @@ -1,100 +0,0 @@ -# coot_commands/tts.py -# -# Copyright 2026 Jordan Dialpuri, Medical Research Council Laboratory of Molecular Biology -# -# This file is part of Coot -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published -# by the Free Software Foundation; either version 3 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -"""Speak a line of text aloud with a local Piper (onnxruntime) neural voice. - -Coot's Assistant tab spawns this as a subprocess to read the agent's final -answer out loud, in place of the macOS ``say`` command. The text is passed as -the first command-line argument (falling back to stdin), synthesised entirely -offline with Piper, and played through the default output device. The process -runs until playback finishes, or until Coot force-exits it to interrupt speech. - -Errors are reported as a single JSON line on stdout so the GUI can surface them -(``{"type": "error", "message": "..."}``); success is silent. Requires -``piper-tts`` and ``sounddevice`` (pip install piper-tts sounddevice). The -voice model is chosen by ``COOT_PIPER_VOICE`` (path to a ``.onnx`` file), -defaulting to ``~/.local/share/coot/piper/en_GB-northern_english_male-medium.onnx``. -""" - -from __future__ import annotations - -import json -import os -import sys - -DEFAULT_VOICE = os.path.expanduser( - "~/.local/share/coot/piper/en_GB-northern_english_male-medium.onnx") - - -def _emit(obj: dict) -> None: - print(json.dumps(obj), flush=True) - - -def _voice_path() -> str: - return os.environ.get("COOT_PIPER_VOICE", DEFAULT_VOICE) - - -def speak(text: str) -> int: - """Synthesise *text* with Piper and play it; return a process exit code.""" - text = text.strip() - if not text: - return 0 - - try: - import numpy as np - import sounddevice as sd - from piper import PiperVoice - except ImportError as exc: - _emit({"type": "error", - "message": f"text-to-speech needs piper-tts + sounddevice ({exc})"}) - return 1 - - voice_path = _voice_path() - if not os.path.exists(voice_path): - _emit({"type": "error", - "message": f"Piper voice not found: {voice_path} " - "(set COOT_PIPER_VOICE or download a voice)"}) - return 1 - - try: - voice = PiperVoice.load(voice_path) - parts = [chunk.audio_int16_array for chunk in voice.synthesize(text)] - except Exception as exc: # noqa: BLE001 - report any synthesis failure - _emit({"type": "error", "message": f"speech synthesis failed: {exc}"}) - return 1 - - if not parts: - return 0 - samples = np.concatenate(parts) - try: - sd.play(samples, samplerate=voice.config.sample_rate) - sd.wait() - except Exception as exc: # noqa: BLE001 - playback device may be unavailable - _emit({"type": "error", "message": f"audio playback failed: {exc}"}) - return 1 - return 0 - - -def main() -> int: - if len(sys.argv) > 1: - text = sys.argv[1] - else: - text = sys.stdin.read() - return speak(text) - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/src/vte.cc b/src/vte.cc index 98ea63634a..ee0dbc17bb 100644 --- a/src/vte.cc +++ b/src/vte.cc @@ -662,8 +662,7 @@ create_vte_terminal_with_style() { // When the user switches notebook tab directly (rather than via the Py/AI buttons), // make sure the terminal for that tab has its child process running. Both spawn -// functions are idempotent. The Assistant tab does NOT auto-start anything: start -// the JSON-RPC listener yourself (Coot's remote-control menu), then use the tab. +// functions are idempotent. static void on_vte_notebook_switch_page(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data) { if (page_num == 0) @@ -873,370 +872,6 @@ static GtkWidget *create_command_tab_widget() { return box; } -// --------------------------------------------------------------------------- -// "Assistant" tab - a local-model agent that drives Coot -// --------------------------------------------------------------------------- -// -// Unlike the Command tab (instant, deterministic regex dispatch), the Assistant -// tab hands a natural-language request to a small local language model that -// plans a sequence of Coot commands to fulfil it. Those model calls are slow, -// so the agent runs as a SEPARATE process (python3 -m coot_commands.agent_serve) -// and we drive it over stdin/stdout: -// - a request is written as one JSON line: {"text": "..."} -// - the agent streams back newline-delimited JSON events -// (ready/tools/step/final/error/done) that we render into the transcript. -// The agent executes each planned command back in THIS Coot over the JSON-RPC -// socket (json-rpc.cc), which runs it on this main thread - so the GUI never -// blocks on the model and command execution is never racy. - -static GtkWidget *assistant_output_view = nullptr; -static GtkWidget *assistant_entry_widget = nullptr; -static GtkWidget *assistant_context_label = nullptr; -static GtkWidget *assistant_status_label = nullptr; -static GtkWidget *assistant_spinner = nullptr; -static GSubprocess *assistant_process = nullptr; -static GDataInputStream *assistant_stdout = nullptr; - -// Show/hide the "thinking" spinner while the model works on a request. -static void assistant_set_thinking(bool thinking) { - if (!assistant_spinner) return; - gtk_widget_set_visible(assistant_spinner, thinking); - if (thinking) gtk_spinner_start(GTK_SPINNER(assistant_spinner)); - else gtk_spinner_stop(GTK_SPINNER(assistant_spinner)); -} - -static void assistant_output_append(const std::string &text) { - - if (!assistant_output_view) return; - GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(assistant_output_view)); - GtkTextIter end; - gtk_text_buffer_get_end_iter(buffer, &end); - gtk_text_buffer_insert(buffer, &end, text.c_str(), -1); - - gtk_text_buffer_get_end_iter(buffer, &end); - GtkTextMark *mark = gtk_text_buffer_create_mark(buffer, nullptr, &end, FALSE); - gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(assistant_output_view), mark); - gtk_text_buffer_delete_mark(buffer, mark); -} - -// Render one streamed JSON event line into the transcript. -static void assistant_handle_event(const std::string &line) { - - json ev; - try { - ev = json::parse(line); - } catch (...) { - return; // ignore any non-JSON noise on stdout - } - std::string type = ev.value("type", ""); - - if (type == "step") { - std::string tool = ev.value("tool", ""); - std::string result = ev.value("result", ""); - std::string args_str; - if (ev.contains("args") && ev["args"].is_object()) { - bool first = true; - for (auto it = ev["args"].begin(); it != ev["args"].end(); ++it) { - if (!first) args_str += ", "; - first = false; - const json &v = it.value(); - args_str += it.key() + "=" + (v.is_string() ? v.get() : v.dump()); - } - } - assistant_output_append(" \xE2\x86\x92 " + tool + "(" + args_str + "): " + result + "\n"); - } else if (type == "final") { - assistant_output_append("\n" + ev.value("text", "") + "\n"); - } else if (type == "error") { - assistant_output_append("Error: " + ev.value("message", "") + "\n"); - } else if (type == "context") { - // Update the "how full is the context" indicator. - if (assistant_context_label) { - int n_msgs = ev.value("messages", 0); - int approx_tokens = ev.value("approx_tokens", 0); - char buf[128]; - if (approx_tokens >= 1000) - g_snprintf(buf, sizeof(buf), "Context: %d msgs \xC2\xB7 ~%.1fk tokens", - n_msgs, approx_tokens / 1000.0); - else - g_snprintf(buf, sizeof(buf), "Context: %d msgs \xC2\xB7 ~%d tokens", - n_msgs, approx_tokens); - gtk_label_set_text(GTK_LABEL(assistant_context_label), buf); - } - } else if (type == "reset") { - if (assistant_context_label) - gtk_label_set_text(GTK_LABEL(assistant_context_label), "New conversation"); - } else if (type == "ready") { - if (assistant_status_label) - gtk_label_set_text(GTK_LABEL(assistant_status_label), - "Assistant starting\xE2\x80\xA6"); - } else if (type == "status") { - // Readiness indicator: whether the model server and the RPC are reachable. - bool ollama = ev.value("ollama", false); - bool rpc = ev.value("rpc", false); - if (assistant_status_label) { - std::string model = ev.value("model", "?"); - std::string s = "Model " + model + (ollama ? ": connected" : ": UNREACHABLE") + - " \xC2\xB7 RPC: " + (rpc ? "ready" : "NOT connected"); - gtk_label_set_text(GTK_LABEL(assistant_status_label), s.c_str()); - } - // Surface the underlying reason for a failure so it can be diagnosed. - if (!rpc && ev.contains("rpc_detail")) - assistant_output_append("RPC not connected: " + - ev.value("rpc_detail", "") + "\n"); - if (!ollama && ev.contains("ollama_detail")) - assistant_output_append("Model server unreachable: " + - ev.value("ollama_detail", "") + "\n"); - } else if (type == "done") { - assistant_set_thinking(false); - if (assistant_entry_widget) { - gtk_widget_set_sensitive(assistant_entry_widget, TRUE); - gtk_widget_grab_focus(assistant_entry_widget); - } - } - // "ready" and "tools" events are informational; we don't clutter the - // transcript with them. -} - -static void assistant_read_line_cb(GObject *source, GAsyncResult *res, gpointer user_data); - -static void assistant_queue_read() { - if (assistant_stdout) - g_data_input_stream_read_line_async(assistant_stdout, G_PRIORITY_DEFAULT, - nullptr, assistant_read_line_cb, nullptr); -} - -static void assistant_read_line_cb(GObject *source, GAsyncResult *res, gpointer user_data) { - - GDataInputStream *stream = G_DATA_INPUT_STREAM(source); - gsize length = 0; - GError *error = nullptr; - char *line = g_data_input_stream_read_line_finish(stream, res, &length, &error); - - if (error) { - g_warning("Assistant: stdout read error: %s", error->message); - g_error_free(error); - return; - } - if (!line) { - // EOF: the agent process exited. Reset so the next request respawns it. - if (assistant_process) { - assistant_output_append("\n[assistant process ended]\n"); - g_object_unref(assistant_process); - assistant_process = nullptr; - } - assistant_stdout = nullptr; // freed when this async op drops its ref - assistant_set_thinking(false); - if (assistant_entry_widget) - gtk_widget_set_sensitive(assistant_entry_widget, TRUE); - return; - } - - assistant_handle_event(std::string(line, length)); - g_free(line); - assistant_queue_read(); -} - -// Ask the embedded interpreter where coot_commands lives, so the spawned -// python3 can import it via PYTHONPATH regardless of install layout. -static std::string assistant_pythonpath() { - - std::string code = - "__import__('os').path.dirname(__import__('coot_commands').__path__[0])"; - execute_python_results_container_t rc = execute_python_code_with_result_internal(code); - if (rc.result && PyUnicode_Check(rc.result)) { - const char *s = PyUnicode_AsUTF8(rc.result); - if (s) return std::string(s); - } - return ""; -} - -// The port the agent uses to reach Coot's JSON-RPC socket. We deliberately do -// NOT start the listener from here - start it yourself from Coot's remote-control -// menu, then use the Assistant. (Auto-starting it proved unreliable.) -static int assistant_rpc_port() { - int port = graphics_info_t::remote_control_port_number; - return port == 0 ? 9090 : port; -} - -static void spawn_assistant_process() { - - if (assistant_process) return; - - int port = assistant_rpc_port(); - - GSubprocessLauncher *launcher = g_subprocess_launcher_new( - (GSubprocessFlags)(G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE)); - g_subprocess_launcher_setenv(launcher, "COOT_RPC_PORT", - std::to_string(port).c_str(), TRUE); - std::string ppath = assistant_pythonpath(); - if (!ppath.empty()) { - const char *existing = g_getenv("PYTHONPATH"); - std::string combined = existing ? (ppath + ":" + existing) : ppath; - g_subprocess_launcher_setenv(launcher, "PYTHONPATH", combined.c_str(), TRUE); - } - - GError *error = nullptr; - assistant_process = g_subprocess_launcher_spawn( - launcher, &error, - "python3", "-u", "-m", "coot_commands.agent_serve", nullptr); - g_object_unref(launcher); - - if (!assistant_process) { - assistant_output_append(std::string("Failed to start assistant: ") + - (error ? error->message : "unknown error") + "\n"); - if (error) g_error_free(error); - return; - } - - GInputStream *out_pipe = g_subprocess_get_stdout_pipe(assistant_process); - assistant_stdout = g_data_input_stream_new(out_pipe); - assistant_queue_read(); -} - -// Write one JSON line to the running agent's stdin. Returns false if there is -// no live process to write to (the caller decides whether to spawn one first). -static bool assistant_write_line(const json &obj) { - - if (!assistant_process) return false; - GOutputStream *in_pipe = g_subprocess_get_stdin_pipe(assistant_process); - if (!in_pipe) return false; - - std::string line = obj.dump() + "\n"; - GError *error = nullptr; - g_output_stream_write_all(in_pipe, line.c_str(), line.size(), - nullptr, nullptr, &error); - if (error) { - assistant_output_append(std::string("Write error: ") + error->message + "\n"); - g_error_free(error); - return false; - } - g_output_stream_flush(in_pipe, nullptr, nullptr); - return true; -} - -static void assistant_send_request(const std::string &text) { - - spawn_assistant_process(); - json req; - req["text"] = text; - assistant_write_line(req); -} - -static void on_assistant_entry_activate(GtkEntry *entry, gpointer user_data) { - - const char *text = gtk_editable_get_text(GTK_EDITABLE(entry)); - if (!text) return; - std::string input(text); - if (input.find_first_not_of(" \t") == std::string::npos) return; // blank line - - assistant_output_append("> " + input + "\n"); - // Disable input until the agent signals "done", so requests don't overlap, - // and show the thinking spinner while the model works. - gtk_widget_set_sensitive(GTK_WIDGET(entry), FALSE); - assistant_send_request(input); - assistant_set_thinking(true); - gtk_editable_set_text(GTK_EDITABLE(entry), ""); -} - -static void on_assistant_new_chat_clicked(GtkButton *button, gpointer user_data) { - - // Clear the transcript locally for immediate feedback... - if (assistant_output_view) { - GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(assistant_output_view)); - gtk_text_buffer_set_text(buffer, "", -1); - } - if (assistant_context_label) - gtk_label_set_text(GTK_LABEL(assistant_context_label), "New conversation"); - // ...and tell a running agent to drop its conversation memory. If none is - // running, the next request spawns a fresh one (which starts empty anyway). - json reset; - reset["reset"] = true; - assistant_write_line(reset); - if (assistant_entry_widget) - gtk_widget_grab_focus(assistant_entry_widget); -} - -static void on_assistant_stop_clicked(GtkButton *button, gpointer user_data) { - - if (assistant_process) { - g_subprocess_force_exit(assistant_process); - g_object_unref(assistant_process); - assistant_process = nullptr; - assistant_stdout = nullptr; - assistant_output_append("\n[stopped]\n"); - } - assistant_set_thinking(false); - if (assistant_entry_widget) - gtk_widget_set_sensitive(assistant_entry_widget, TRUE); -} - -static GtkWidget *create_assistant_tab_widget() { - - GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2); - - GtkWidget *scrolled = gtk_scrolled_window_new(); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_widget_set_vexpand(scrolled, TRUE); - - assistant_output_view = gtk_text_view_new(); - gtk_text_view_set_editable(GTK_TEXT_VIEW(assistant_output_view), FALSE); - gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(assistant_output_view), FALSE); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(assistant_output_view), GTK_WRAP_WORD_CHAR); - gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrolled), assistant_output_view); - - GtkWidget *row = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2); - assistant_entry_widget = gtk_entry_new(); - gtk_widget_set_hexpand(assistant_entry_widget, TRUE); - gtk_entry_set_placeholder_text(GTK_ENTRY(assistant_entry_widget), - "Ask the assistant, e.g. \"load the tutorial data and refine A 89\""); - g_signal_connect(assistant_entry_widget, "activate", - G_CALLBACK(on_assistant_entry_activate), nullptr); - - GtkWidget *new_chat_button = gtk_button_new_with_label("New chat"); - g_signal_connect(new_chat_button, "clicked", - G_CALLBACK(on_assistant_new_chat_clicked), nullptr); - - GtkWidget *stop_button = gtk_button_new_with_label("Stop"); - g_signal_connect(stop_button, "clicked", - G_CALLBACK(on_assistant_stop_clicked), nullptr); - - // "Thinking" spinner, hidden until a request is in flight. - assistant_spinner = gtk_spinner_new(); - gtk_widget_set_visible(assistant_spinner, FALSE); - - gtk_box_append(GTK_BOX(row), assistant_entry_widget); - gtk_box_append(GTK_BOX(row), assistant_spinner); - gtk_box_append(GTK_BOX(row), new_chat_button); - gtk_box_append(GTK_BOX(row), stop_button); - - // A readiness line (model + RPC status) and a context-usage line, both dim. - assistant_status_label = gtk_label_new(""); - gtk_widget_set_halign(assistant_status_label, GTK_ALIGN_START); - gtk_widget_add_css_class(assistant_status_label, "dim-label"); - - assistant_context_label = gtk_label_new("New conversation"); - gtk_widget_set_halign(assistant_context_label, GTK_ALIGN_START); - gtk_widget_add_css_class(assistant_context_label, "dim-label"); - - gtk_box_append(GTK_BOX(box), scrolled); - gtk_box_append(GTK_BOX(box), assistant_status_label); - gtk_box_append(GTK_BOX(box), row); - gtk_box_append(GTK_BOX(box), assistant_context_label); - - assistant_output_append( - "Coot Assistant [alpha] (local model).\n" - "Start the JSON-RPC listener yourself from Coot's remote-control menu,\n" - "then type a request, e.g. \"refine A 89 and pepflip A 32\".\n"); - gtk_label_set_text(GTK_LABEL(assistant_status_label), - "Start the RPC listener from the menu, then send a request."); - - // Nothing is auto-started here: the agent process is spawned on the first - // request (assistant_send_request), and it connects to the JSON-RPC listener - // that you start yourself. Auto-starting the listener proved unreliable. - return box; -} - void setup_claude_vte_terminal() { // Set up lazily and only once. Doing this at startup reparented the Python VTE @@ -1297,11 +932,6 @@ void setup_claude_vte_terminal() { GtkWidget *cmd_label = gtk_label_new("Command"); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), command_widget, cmd_label); - // Add the local-model Assistant tab (alpha) - GtkWidget *assistant_widget = create_assistant_tab_widget(); - GtkWidget *assistant_label = gtk_label_new("Assistant (alpha)"); - gtk_notebook_append_page(GTK_NOTEBOOK(notebook), assistant_widget, assistant_label); - // Put the notebook into the paned gtk_paned_set_end_child(GTK_PANED(vte_paned_widget), notebook); gtk_paned_set_resize_end_child(GTK_PANED(vte_paned_widget), FALSE); From f90672acd4bd8923ef5fffe7020b3ab7020d0b6a Mon Sep 17 00:00:00 2001 From: Jordan Dialpuri Date: Thu, 23 Jul 2026 17:18:06 +0100 Subject: [PATCH 23/23] Remove unnecessary files --- mmdb-shim/core/backing.hh | 186 ---------------------------------- mmdb-shim/core/bench_edits | Bin 61992 -> 0 bytes mmdb-shim/core/bench_edits.cc | 59 ----------- mmdb-shim/core/test_core | Bin 579000 -> 0 bytes mmdb-shim/core/test_core.cc | 77 -------------- mmdb-shim/shim-cxx | 9 -- 6 files changed, 331 deletions(-) delete mode 100644 mmdb-shim/core/backing.hh delete mode 100755 mmdb-shim/core/bench_edits delete mode 100644 mmdb-shim/core/bench_edits.cc delete mode 100755 mmdb-shim/core/test_core delete mode 100644 mmdb-shim/core/test_core.cc delete mode 100755 mmdb-shim/shim-cxx diff --git a/mmdb-shim/core/backing.hh b/mmdb-shim/core/backing.hh deleted file mode 100644 index 611ccc565b..0000000000 --- a/mmdb-shim/core/backing.hh +++ /dev/null @@ -1,186 +0,0 @@ -// mmdb-shim core — architecture B foundation. -// See ../../MMDB_SHIM_Recon_and_Plan.md. -// -// A LIVE gemmi::Structure holds the data; a PARALLEL wrapper tree provides the -// MMDB pointer semantics Coot depends on: -// * wrapper addresses are stable (pool-allocated) -> valid `mmdb::Atom*` and -// usable as std::set/map keys (identity by address); -// * GetAtom(i)/GetResidue(i) return the SAME canonical wrapper pointer every -// call (identity cache = the parent's child-pointer vector); -// * g() resolves a wrapper to its live gemmi object via parent* + a cached -// sibling index; -// * structural edits patch ONLY the shifted siblings in one container -// (localized) — not the whole pool, unlike the first spike. -// -// This is the hardened successor to mmdb-recon/spike/. - -#pragma once -#include - -#include -#include -#include - -namespace shim { - -struct Backing; -struct ModelW; -struct ChainW; -struct ResidueW; - -// --------------------------------------------------------------------------- -struct AtomW { - ResidueW *parent = nullptr; - int ai = 0; // index within parent residue's atoms (cached) - bool alive = true; - - gemmi::Atom &g() const; // resolve to live gemmi::Atom (defined below) - - // numeric fields -> reference-returning accessors (rewrite targets) - double &x() { return g().pos.x; } - double &y() { return g().pos.y; } - double &z() { return g().pos.z; } - // occ/b_iso are float in gemmi -> value get + setter (can't bind double&) - double occupancy() const { return g().occ; } - void set_occupancy(double v) { g().occ = (float)v; } - double tempFactor() const { return g().b_iso; } - void set_tempFactor(double v) { g().b_iso = (float)v; } - // char-array fields -> const char* getter + setter (strcpy sites rewrite here) - const char *name() const { return g().name.c_str(); } - void set_name(const char *s) { g().name = s; } -}; - -// --------------------------------------------------------------------------- -struct ResidueW { - ChainW *parent = nullptr; - int ri = 0; // index within parent chain's residues - bool alive = true; - std::vector atoms_w; // canonical child wrappers (identity cache) - - gemmi::Residue &g() const; - - int GetNumberOfAtoms() const { return (int)atoms_w.size(); } - AtomW *GetAtom(int i) { return (i >= 0 && i < (int)atoms_w.size()) ? atoms_w[i] : nullptr; } - - AtomW *AddAtom(Backing &b, gemmi::Atom a); // append: O(1), no sibling shift - void DeleteAtom(int pos); // O(atoms in this residue) -}; - -// --------------------------------------------------------------------------- -struct ChainW { - ModelW *parent = nullptr; - int ci = 0; - bool alive = true; - std::vector residues_w; - - gemmi::Chain &g() const; - - int GetNumberOfResidues() const { return (int)residues_w.size(); } - ResidueW *GetResidue(int i) { return (i >= 0 && i < (int)residues_w.size()) ? residues_w[i] : nullptr; } - - ResidueW *AddResidue(Backing &b, gemmi::Residue r); // append: O(1) - ResidueW *InsResidue(Backing &b, int pos, gemmi::Residue r); // O(residues in chain) -}; - -// --------------------------------------------------------------------------- -struct ModelW { - Backing *b = nullptr; - int mi = 0; - std::vector chains_w; - - gemmi::Model &g() const; - - int GetNumberOfChains() const { return (int)chains_w.size(); } - ChainW *GetChain(int i) { return (i >= 0 && i < (int)chains_w.size()) ? chains_w[i] : nullptr; } -}; - -// --------------------------------------------------------------------------- -struct Backing { - gemmi::Structure st; - // Pools: std::deque keeps element addresses stable across growth. - std::deque atom_pool; - std::deque res_pool; - std::deque chain_pool; - std::deque model_pool; - std::vector models_w; - - AtomW *newAtom() { atom_pool.emplace_back(); return &atom_pool.back(); } - ResidueW *newRes() { res_pool.emplace_back(); return &res_pool.back(); } - ChainW *newChain() { chain_pool.emplace_back(); return &chain_pool.back(); } - ModelW *newModel() { model_pool.emplace_back(); return &model_pool.back(); } - - ModelW *GetModel(int i) { return (i >= 0 && i < (int)models_w.size()) ? models_w[i] : nullptr; } - int GetNumberOfModels() const { return (int)models_w.size(); } - - // Build the parallel wrapper tree from the current gemmi::Structure. - void build_from_gemmi() { - models_w.clear(); - for (int mi = 0; mi < (int)st.models.size(); ++mi) { - ModelW *mw = newModel(); mw->b = this; mw->mi = mi; - auto &gm = st.models[mi]; - for (int ci = 0; ci < (int)gm.chains.size(); ++ci) { - ChainW *cw = newChain(); cw->parent = mw; cw->ci = ci; - auto &gc = gm.chains[ci]; - for (int ri = 0; ri < (int)gc.residues.size(); ++ri) { - ResidueW *rw = newRes(); rw->parent = cw; rw->ri = ri; - auto &gr = gc.residues[ri]; - for (int ai = 0; ai < (int)gr.atoms.size(); ++ai) { - AtomW *aw = newAtom(); aw->parent = rw; aw->ai = ai; - rw->atoms_w.push_back(aw); - } - cw->residues_w.push_back(rw); - } - mw->chains_w.push_back(cw); - } - models_w.push_back(mw); - } - } -}; - -// ---- g() resolvers (walk parent + cached index into the live gemmi tree) ---- -inline gemmi::Model &ModelW::g() const { return b->st.models[mi]; } -inline gemmi::Chain &ChainW::g() const { return parent->g().chains[ci]; } -inline gemmi::Residue &ResidueW::g() const { return parent->g().residues[ri]; } -inline gemmi::Atom &AtomW::g() const { return parent->g().atoms[ai]; } - -// ---- edits (localized patching) ---- -inline AtomW *ResidueW::AddAtom(Backing &b, gemmi::Atom a) { - g().atoms.push_back(std::move(a)); // append -> existing ai valid - AtomW *aw = b.newAtom(); - aw->parent = this; aw->ai = (int)atoms_w.size(); - atoms_w.push_back(aw); - return aw; -} - -inline void ResidueW::DeleteAtom(int pos) { - if (pos < 0 || pos >= (int)atoms_w.size()) return; - g().atoms.erase(g().atoms.begin() + pos); - atoms_w[pos]->alive = false; atoms_w[pos]->ai = -1; // tombstone (reclaim later) - atoms_w.erase(atoms_w.begin() + pos); - for (int k = pos; k < (int)atoms_w.size(); ++k) atoms_w[k]->ai = k; // shift -1 -} - -inline ResidueW *ChainW::AddResidue(Backing &b, gemmi::Residue r) { - g().residues.push_back(std::move(r)); - ResidueW *rw = b.newRes(); - rw->parent = this; rw->ri = (int)residues_w.size(); - for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { - AtomW *aw = b.newAtom(); aw->parent = rw; aw->ai = ai; rw->atoms_w.push_back(aw); - } - residues_w.push_back(rw); - return rw; -} - -inline ResidueW *ChainW::InsResidue(Backing &b, int pos, gemmi::Residue r) { - g().residues.insert(g().residues.begin() + pos, std::move(r)); - ResidueW *rw = b.newRes(); - rw->parent = this; rw->ri = pos; - residues_w.insert(residues_w.begin() + pos, rw); - for (int k = pos + 1; k < (int)residues_w.size(); ++k) residues_w[k]->ri = k; // shift +1 - for (int ai = 0; ai < (int)rw->g().atoms.size(); ++ai) { - AtomW *aw = b.newAtom(); aw->parent = rw; aw->ai = ai; rw->atoms_w.push_back(aw); - } - return rw; // atoms of OTHER residues are untouched (parent ri updated, ai unchanged) -} - -} // namespace shim diff --git a/mmdb-shim/core/bench_edits b/mmdb-shim/core/bench_edits deleted file mode 100755 index 8df9814dd50a3366b6918f7fa6a34970bfaaa48f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 61992 zcmeHw3w#tsws&<;9zBx~9(e*vhM;Z|6iI-PXfT}@B&dKPK2}{PPnaPuOeQ=;WD-yU z5!{h@RkGJa*j+Ob?&Z3mvdc;USEJ~z0bjf8VnFXYA?{U>$23cr?|-^`!elbxq3-wn z?(dt)uTy=ht4>v&I(6#QsZ-s5I`@wY!HjVXKOWa8T%tc?kF)U<#YW@G!DTSaOP`f} ze|FwniXHfqG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M5BSE@lM)E^>;XFt2^A6HQ~_kJFt zBoFOoK#q&dl>mQ^b4P+Z;HrEdZsGnS|H2RlZxlX@!FL}1%(!PIxF`+%;7R$-2YQ|b zE8yk+=aah%{kWpi%3^p#mtfh+mY)7v`|uZz(<}CV^hWHI)>BV>y6fRz|9hl#a^$wr zkDpF1&VENSe3bCpZQ716w4*nDQ@^C~%iuE)>DSB(KY8H&80WpwH~;=fw6$aOJnM^< z&wtpEw{POPagS_m`u$UnJoJ9c$0Nszd`Hyc?I|raY57}sGzPtt@E^zj(2!Qx*jL(7 zk+QbB`TYKGPCfU#uFd~mxI8Sx|F)v7dxpOg^{3e2uXcn-{m(l;`F+;uH-2{grvaVc zKAbatOzVmbjlYWAx%966bzd#Ivz;4}b!+vf>A(BjKWBTx-LFlLy)pQ}a}lE_-}>S^ z=dOLA{nu;0I`Pi-Roh;SbMNzaKDzVKM;`yn?;CU0-S|@CqWcnW z{VHkixu-hCvbF*qS|iBK|fx@zako^ui;tt7fkLCV t9S^?0=<6{@9{4L4nke}fE*+Ns_hlnv_D@@I{P|J0j^7*n)I5Lg{{TahP(%O# diff --git a/mmdb-shim/core/bench_edits.cc b/mmdb-shim/core/bench_edits.cc deleted file mode 100644 index d767016c85..0000000000 --- a/mmdb-shim/core/bench_edits.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Retire spike risk #1 (O(pool) patching -> quadratic edit loops). -// The hardened core patches only shifted siblings in ONE container, so edit cost -// is independent of TOTAL atom count. Prove it: hold atom count constant, vary -// per-container size, and show InsResidue cost scales with residues-in-chain (not -// total atoms), and AddAtom is ~O(1). -#include "backing.hh" -#include -#include - -using namespace shim; -using clk = std::chrono::high_resolution_clock; - -static gemmi::Atom mk(int r, int a) { - gemmi::Atom at; at.pos = gemmi::Position(r * 10.0 + a, r, a); return at; -} - -static double time_ms(const std::function &f) { - auto t0 = clk::now(); f(); - return std::chrono::duration(clk::now() - t0).count(); -} - -int main() { - // Large structure: 1 chain, N residues, 8 atoms each (~N*8 atoms total). - for (int N : {2000, 8000, 32000}) { - Backing B; - B.st.models.emplace_back(); - B.st.models[0].chains.emplace_back(); - auto &gc = B.st.models[0].chains.back(); - for (int r = 0; r < N; ++r) { - gemmi::Residue res; res.seqid = gemmi::SeqId(r + 1, ' '); - for (int a = 0; a < 8; ++a) res.atoms.push_back(mk(r, a)); - gc.residues.push_back(res); - } - B.build_from_gemmi(); - ChainW *chain = B.GetModel(0)->GetChain(0); - AtomW *held = chain->GetResidue(N / 2)->GetAtom(0); - double hx = held->x(); - - // 500 AddAtom (append -> O(1) each) - ResidueW *rmid = chain->GetResidue(N / 2); - double t_add = time_ms([&] { for (int i = 0; i < 500; ++i) rmid->AddAtom(B, mk(1, i)); }); - - // 500 InsResidue at front (worst case: shift all residues in chain) - double t_ins = time_ms([&] { - for (int i = 0; i < 500; ++i) { - gemmi::Residue r; r.seqid = gemmi::SeqId(0, ' '); r.atoms.push_back(mk(9, i)); - chain->InsResidue(B, 0, r); - } - }); - - bool ok = (held->x() == hx); // identity/correctness survived all edits - std::printf("N_res=%-6d total_atoms=%-8d AddAtom(500)=%6.2fms " - "InsResidue@front(500)=%7.2fms correct=%s\n", - N, N * 8, t_add, t_ins, ok ? "yes" : "NO"); - } - std::printf("\nAddAtom flat across N (O(1)); InsResidue@front scales with " - "residues-in-chain, NOT total atoms -> same class as MMDB arrays.\n"); - return 0; -} diff --git a/mmdb-shim/core/test_core b/mmdb-shim/core/test_core deleted file mode 100755 index 456921635e240289e23fd95b9c324233c8c6a86c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 579000 zcmeEv34B$>_5a+w1l|io0b@~Fk{FdBDlWBuOGkD8jUzTn!cGx_ZLUO;Bn zH{t@fKHht3E*0}KrAg21tG{^O>~xY{U;NS%S>L%4Hw*90`ogL{@KFA1YPx9V%%%&j zoq56MuWq_}#(8#q4OhGM%^T(B=e=2HIdP3O(dNSmfBlV8_YY9yKbvgcZ6etzbd zkV@JNy)v-U)s`2Mm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Cu9%k zv^A*a%7se{oO-`*#(O2d+CSi9=Nn(#In-Te^3-lV>iC6x`5q6Nx2@Dyx#H-wbw+K%im{F@b&)H z_wOk&#_?;D<4-Gn=KkjK-7fcH3T(Hm9@ndWv7cAW&ey(R_RZIa-KmwiY25lY-&}C* w>U_Xn^X9%)>pfFU7mwVpoOw6nLsKo?vS+(T?J0cCUarryA_Ia_n*;^@4-dR6(*OVf diff --git a/mmdb-shim/core/test_core.cc b/mmdb-shim/core/test_core.cc deleted file mode 100644 index b0c75bfabb..0000000000 --- a/mmdb-shim/core/test_core.cc +++ /dev/null @@ -1,77 +0,0 @@ -// Test the hardened core: identity cache + localized-patch edits + stability. -#include "backing.hh" -#include - -using namespace shim; - -static int failures = 0; -#define CHECK(cond, msg) \ - do { \ - if (!(cond)) { std::printf(" FAIL: %s\n", msg); ++failures; } \ - else { std::printf(" ok: %s\n", msg); } \ - } while (0) - -// identity-encoded coords: x = res*10 + atom -static gemmi::Atom mk(int r, int a) { - gemmi::Atom at; - at.name = "A" + std::to_string(r) + "_" + std::to_string(a); - at.pos = gemmi::Position(r * 10.0 + a, (double)r, (double)a); - return at; -} - -int main() { - Backing B; - B.st.models.emplace_back(); - auto &gm = B.st.models.back(); - gm.chains.emplace_back(); - gm.chains.back().name = "A"; - for (int r = 0; r < 3; ++r) { - gemmi::Residue res; res.name = "GLY"; res.seqid = gemmi::SeqId(r + 1, ' '); - for (int a = 0; a < 3; ++a) res.atoms.push_back(mk(r, a)); - gm.chains.back().residues.push_back(res); - } - B.build_from_gemmi(); - - ChainW *chain = B.GetModel(0)->GetChain(0); - ResidueW *res1 = chain->GetResidue(1); - AtomW *held = res1->GetAtom(1); // (res1, atom1) -> x==11 - - std::printf("held=%p x=%.1f name=%s\n", (void *)held, held->x(), held->name()); - - // --- identity cache: repeated Get* return the SAME pointer --- - CHECK(chain->GetResidue(1) == res1, "GetResidue(1) twice -> same pointer (identity)"); - CHECK(res1->GetAtom(1) == held, "GetAtom(1) twice -> same pointer (identity)"); - CHECK(held->x() == 11.0, "resolves to correct atom"); - - // --- edit 1: AddAtom x5000 (gemmi atoms vector reallocates) --- - const void *d0 = (void *)res1->g().atoms.data(); - for (int i = 0; i < 5000; ++i) res1->AddAtom(B, mk(1, 100 + i)); - CHECK(d0 != (void *)res1->g().atoms.data(), "gemmi atoms vector reallocated"); - CHECK(held->x() == 11.0, "held correct after AddAtom (append, no shift)"); - CHECK(res1->GetAtom(1) == held, "identity preserved after AddAtom"); - - // --- edit 2: InsResidue at front: only THIS chain's residue ri shifts --- - // Atom wrappers of other residues must NOT be touched. - gemmi::Residue newr; newr.name = "ACE"; newr.seqid = gemmi::SeqId(0, ' '); - newr.atoms.push_back(mk(7, 7)); - chain->InsResidue(B, 0, newr); - CHECK(res1->ri == 2, "res1 index patched 1 -> 2 (localized to chain)"); - CHECK(held->ai == 1, "held atom index UNCHANGED by residue insert (localized)"); - CHECK(held->x() == 11.0, "held still resolves to same logical atom after mid-insert"); - CHECK(chain->GetResidue(2) == res1, "chain now finds res1 at index 2 (same pointer)"); - CHECK(chain->GetResidue(0)->GetAtom(0)->x() == 77.0, "inserted residue resolves correctly"); - - // --- edit 3: DeleteAtom at index 0 of res1: atom indices shift within residue only --- - res1->DeleteAtom(0); - CHECK(held->ai == 0, "held atom index patched 1 -> 0 after delete"); - CHECK(held->x() == 11.0, "held still correct after DeleteAtom"); - CHECK(res1->GetAtom(0) == held, "identity preserved after DeleteAtom"); - - // --- edit 4: write through reference accessor reaches live gemmi --- - held->x() = 999.0; - CHECK(res1->g().atoms[0].pos.x == 999.0, "ref-accessor write reached live gemmi storage"); - - std::printf("\n=== %s (%d failures) ===\n", - failures == 0 ? "CORE PASSED" : "CORE FAILED", failures); - return failures ? 1 : 0; -} diff --git a/mmdb-shim/shim-cxx b/mmdb-shim/shim-cxx deleted file mode 100755 index ef43dfd6ba..0000000000 --- a/mmdb-shim/shim-cxx +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -# Compiler wrapper that forces the mmdb->gemmi shim's headers to win over real -# mmdb2. Autotools puts pkg-config's `-I` in AM_CPPFLAGS, which precedes -# CPPFLAGS on the compile line — so a shim -I in CPPFLAGS can never win. But -# $(CXX) is emitted before everything, so a -I here is searched FIRST. -# Used via: export CXX="/mmdb-shim/shim-cxx" -# Override the underlying compiler with REAL_CXX if needed (default: c++). -d="$(cd "$(dirname "$0")" && pwd)" -exec "${REAL_CXX:-/usr/bin/c++}" -I"$d/include" -DCOOT_USE_MMDB_SHIM "$@"