Skip to content

ARC

lahuta.core.arc

Classes to model and manage the atomic-level structure of a biological system. The atomic-level structure includes atoms, residues, and chains in the system, and their inter-relationships.

This module provides the following classes:

  • Atoms: This class models and manages the properties of atoms in the system. It provides functionalities to retrieve information about individual atoms, as well as to iterate over and access data of multiple atoms.

  • Residues: This class models and manages the properties of residues in the system. Similar to the Atoms class, it provides functionalities to retrieve information about individual residues, as well as to iterate over and access data of multiple residues.

  • Chains: This class models and manages the properties of chains in the system. Again, similar to the Atoms and Residues classes, it provides functionalities to retrieve information about individual chains, as well as to iterate over and access data of multiple chains.

  • ARC: This class integrates the Atoms, Residues, and Chains (ARC) module, by creating and storing instances of Atoms, Residues, and Chains classes. Depending on the type of the input object (either GemmiLoader or TopologyLoader), it uses the appropriate method from Atoms, Residues, and Chains classes to initialize them. It provides methods to retrieve atom, residue, and chain information individually or together, as well as methods to iterate over and access this data.

  • Atom: This class models and manages the properties of an atom in the system. It is created with keyword arguments, which allows it to dynamically store any attributes passed. The attributes include, but are not limited to, atom name, ID, element, type, residue name, residue ID, chain label, and chain ID.

Example
>>> from arc import ARC, GemmiLoader
>>> loader = GemmiLoader("path_to_structure")
>>> arc = ARC(loader, loader.atom_site_data)
>>> atom_0 = arc.get_atom(0)
>>> print(atom_0)
Atom(name=..., id=..., element=..., type=..., resname=..., resid=..., chain_label=..., chain_id=...)

Atoms

Models and manages the properties and coordinates of atoms in a system.

The Atoms class is part of the Atoms, Residues, Chains (ARC) module. It leverages structured numpy arrays to effectively handle, store and manipulate atomic information for speed optimization. The class stores atom-specific data like atom name, id, element type, and type, using the efficient and fast structured arrays provided by numpy.

The class provides two class methods for initialization: from_gemmi and from_mda. These methods enable the creation of Atoms instances from Gemmi blocks or an MDAnalysis AtomGroup, respectively.

The class also includes various properties to retrieve atomic attributes like names, types, ids, elements, and coordinates, and provides methods to iterate over and access the atomic data.

Attributes:

Name Type Description
data NDArray[Any]

A numpy structured array storing atomic properties.

coords NDArray[float32]

A numpy array storing the coordinates of atoms.

Examples:

>>> from arc import Atoms
>>> atoms_from_gemmi = Atoms.from_gemmi(gemmi_block)
>>> print(atoms_from_gemmi.names)
['C', 'O', 'N', ...]

>>> atoms_from_mda = Atoms.from_mda(uv)
>>> print(atoms_from_mda.ids)
[1, 2, 3, ...]
Source code in lahuta/core/arc.py
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
class Atoms:
    """Models and manages the properties and coordinates of atoms in a system.

    The Atoms class is part of the Atoms, Residues, Chains (ARC) module. It leverages structured
    numpy arrays to effectively handle, store and manipulate atomic information for speed optimization.
    The class stores atom-specific data like atom name, id, element type, and type, using the efficient
    and fast structured arrays provided by numpy.

    The class provides two class methods for initialization: `from_gemmi` and `from_mda`.
    These methods enable the creation of Atoms instances from Gemmi blocks or
    an MDAnalysis AtomGroup, respectively.

    The class also includes various properties to retrieve atomic attributes like names, types, ids,
    elements, and coordinates, and provides methods to iterate over and access the atomic data.

    Attributes:
        data (NDArray[Any]): A numpy structured array storing atomic properties.
        coords (NDArray[np.float32]): A numpy array storing the coordinates of atoms.

    Examples:
        ``` py
        >>> from arc import Atoms
        >>> atoms_from_gemmi = Atoms.from_gemmi(gemmi_block)
        >>> print(atoms_from_gemmi.names)
        ['C', 'O', 'N', ...]

        >>> atoms_from_mda = Atoms.from_mda(uv)
        >>> print(atoms_from_mda.ids)
        [1, 2, 3, ...]
        ```
    """

    dtype = np.dtype(
        {
            "names": ["name", "id", "element", "type"],
            "formats": ["<U10", "int", "<U10", "<U10"],
        }
    )

    def __init__(self) -> None:
        self.data: NDArray[Any] = np.empty(0, dtype=self.dtype)
        self.coords = np.zeros((0, 3), dtype=np.float32)

    @classmethod
    def from_gemmi(cls, gemmi_block: dict[str, Any]) -> "Atoms":
        """Create an Atoms instance from a Gemmi block.

        Args:
            gemmi_block (dict[str, Any]): A Gemmi block.

        Returns:
            Atoms: An Atoms instance.
        """
        cls_instance = cls.__new__(cls)

        # Create structured array
        label_atom_id: list[str] = gemmi_block["label_atom_id"]
        data = np.empty(len(label_atom_id), dtype=cls_instance.dtype)
        data["name"] = np.array(label_atom_id)
        data["id"] = np.arange(data["name"].size)
        data["element"] = np.array(gemmi_block.get("type_symbol"))
        data["type"] = np.array(gemmi_block.get("type_symbol"))

        cls_instance.data = data
        cls_instance.coords = np.zeros((0, 3), dtype=np.float32)

        return cls_instance

    @classmethod
    def from_mda(cls, uv: UniverseType) -> "Atoms":
        """Create an Atoms instance from an MDAnalysis Universe.

        Args:
            uv (UniverseType): An MDAnalysis Universe.

        Returns:
            Atoms: An Atoms instance.
        """
        cls_instance = cls.__new__(cls)
        data: NDArray[Any] = np.empty(len(uv.atoms), dtype=cls_instance.dtype)
        data["name"] = uv.atoms.names
        data["id"] = uv.atoms.ix
        data["element"] = uv.atoms.elements
        data["type"] = uv.atoms.types

        cls_instance.data = data
        cls_instance.coords = uv.atoms.positions

        return cls_instance

    @property
    def names(self) -> NDArray[np.str_]:
        """Atom names."""
        return self.data["name"]

    @property
    def types(self) -> NDArray[np.str_]:
        """Atom types."""
        return self.data["type"]

    @property
    def ids(self) -> NDArray[np.int32]:
        """Atom ids."""
        return self.data["id"]

    @property
    def elements(self) -> NDArray[np.str_]:
        """Atom elements."""
        return self.data["element"]

    @property
    def coordinates(self) -> NDArray[np.float32]:
        """3D coordinates of the atoms."""
        return self.coords

    @coordinates.setter
    def coordinates(self, coordinates: NDArray[np.float32]) -> None:
        self.coords = coordinates

    def __len__(self) -> int:
        return self.data.size

    def __getitem__(self, index: int | slice) -> NDArray[Any]:
        return self.data[index]

    def __iter__(self) -> Iterator[NDArray[Any]]:
        """Iterate over atoms."""
        for i in range(len(self)):
            yield self[i]

names property

names

Atom names.

types property

types

Atom types.

ids property

ids

Atom ids.

elements property

elements

Atom elements.

coordinates property writable

coordinates

3D coordinates of the atoms.

from_gemmi classmethod

from_gemmi(gemmi_block)

Create an Atoms instance from a Gemmi block.

Parameters:

Name Type Description Default
gemmi_block dict[str, Any]

A Gemmi block.

required

Returns:

Name Type Description
Atoms Atoms

An Atoms instance.

Source code in lahuta/core/arc.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
@classmethod
def from_gemmi(cls, gemmi_block: dict[str, Any]) -> "Atoms":
    """Create an Atoms instance from a Gemmi block.

    Args:
        gemmi_block (dict[str, Any]): A Gemmi block.

    Returns:
        Atoms: An Atoms instance.
    """
    cls_instance = cls.__new__(cls)

    # Create structured array
    label_atom_id: list[str] = gemmi_block["label_atom_id"]
    data = np.empty(len(label_atom_id), dtype=cls_instance.dtype)
    data["name"] = np.array(label_atom_id)
    data["id"] = np.arange(data["name"].size)
    data["element"] = np.array(gemmi_block.get("type_symbol"))
    data["type"] = np.array(gemmi_block.get("type_symbol"))

    cls_instance.data = data
    cls_instance.coords = np.zeros((0, 3), dtype=np.float32)

    return cls_instance

from_mda classmethod

from_mda(uv)

Create an Atoms instance from an MDAnalysis Universe.

Parameters:

Name Type Description Default
uv UniverseType

An MDAnalysis Universe.

required

Returns:

Name Type Description
Atoms Atoms

An Atoms instance.

Source code in lahuta/core/arc.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
@classmethod
def from_mda(cls, uv: UniverseType) -> "Atoms":
    """Create an Atoms instance from an MDAnalysis Universe.

    Args:
        uv (UniverseType): An MDAnalysis Universe.

    Returns:
        Atoms: An Atoms instance.
    """
    cls_instance = cls.__new__(cls)
    data: NDArray[Any] = np.empty(len(uv.atoms), dtype=cls_instance.dtype)
    data["name"] = uv.atoms.names
    data["id"] = uv.atoms.ix
    data["element"] = uv.atoms.elements
    data["type"] = uv.atoms.types

    cls_instance.data = data
    cls_instance.coords = uv.atoms.positions

    return cls_instance

Residues

The Residues class models and manages the properties of residues in a system.

The Residues class is part of the Atoms, Residues, Chains (ARC) module. It utilizes structured numpy arrays for effective handling, storage, and manipulation of residue-related data. This class specifically stores data related to residue names and residue IDs.

Initialization of the Residues instances can be accomplished via two class methods: from_gemmi and from_mda. These methods enable the creation of Residues instances from Gemmi blocks or an MDAnalysis Universe respectively.

The class includes properties to retrieve residue attributes like residue names and residue IDs, and provides methods to iterate over and access the residue data.

Attributes:

Name Type Description
_data NDArray[Any]

A numpy structured array storing residue properties.

Examples:

>>> from arc import Residues
>>> residues_from_gemmi = Residues.from_gemmi(gemmi_block)
>>> print(residues_from_gemmi.resnames)
['ALA', 'GLY', 'VAL', ...]

>>> residues_from_mda = Residues.from_mda(uv)
>>> print(residues_from_mda.resids)
[1, 2, 3, ...]
Source code in lahuta/core/arc.py
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
class Residues:
    """The Residues class models and manages the properties of residues in a system.

    The Residues class is part of the Atoms, Residues, Chains (ARC) module. It utilizes structured
    numpy arrays for effective handling, storage, and manipulation of residue-related data. This
    class specifically stores data related to residue names and residue IDs.

    Initialization of the Residues instances can be accomplished via two class methods:
    `from_gemmi` and `from_mda`. These methods enable the creation of Residues instances
    from Gemmi blocks or an MDAnalysis Universe respectively.

    The class includes properties to retrieve residue attributes like residue names and residue IDs,
    and provides methods to iterate over and access the residue data.

    Attributes:
        _data (NDArray[Any]): A numpy structured array storing residue properties.

    Examples:
        ``` py
        >>> from arc import Residues
        >>> residues_from_gemmi = Residues.from_gemmi(gemmi_block)
        >>> print(residues_from_gemmi.resnames)
        ['ALA', 'GLY', 'VAL', ...]

        >>> residues_from_mda = Residues.from_mda(uv)
        >>> print(residues_from_mda.resids)
        [1, 2, 3, ...]
        ```
    """

    dtype = np.dtype({"names": ["resname", "resid"], "formats": ["<U10", "int"]})

    def __init__(self) -> None:
        self.data: NDArray[Any] = np.empty(0, dtype=self.dtype)

    @classmethod
    def from_gemmi(cls, gemmi_block: dict[str, Any]) -> "Residues":
        """Create a Residues instance from a Gemmi block.

        Args:
            gemmi_block (dict[str, Any]): A Gemmi block.

        Returns:
            Residues: A Residues instance.
        """
        cls_instance = cls.__new__(cls)

        # Create structured array
        resnames = np.array(gemmi_block["label_comp_id"])
        resids = np.array(gemmi_block["auth_seq_id"], dtype=int)

        data = np.empty(len(resnames), dtype=cls.dtype)
        data["resname"] = resnames
        data["resid"] = resids

        cls_instance.data = data

        return cls_instance

    @classmethod
    def from_mda(cls, mda_universe: UniverseType) -> "Residues":
        """Create a Residues instance from an MDAnalysis Universe.

        Args:
            mda_universe (UniverseType): An MDAnalysis Universe.

        Returns:
            Residues: A Residues instance.
        """
        cls_instance = cls.__new__(cls)
        cls_instance.data = np.empty(len(mda_universe.atoms), dtype=cls_instance.dtype)
        cls_instance.data["resname"] = mda_universe.atoms.resnames
        cls_instance.data["resid"] = mda_universe.atoms.resids

        return cls_instance

    @property
    def resnames(self) -> NDArray[np.str_]:
        """Residue names."""
        return self.data["resname"]

    @property
    def resids(self) -> NDArray[np.int32]:
        """Residue IDs."""
        return self.data["resid"]

    def __len__(self) -> int:
        return len(self.data)

    def __getitem__(self, index: int | slice) -> NDArray[Any]:
        return self.data[index]

    def __iter__(self) -> Iterator[NDArray[Any]]:
        """Iterate over residues."""
        for i in range(len(self)):
            yield self[i]

resnames property

resnames

Residue names.

resids property

resids

Residue IDs.

from_gemmi classmethod

from_gemmi(gemmi_block)

Create a Residues instance from a Gemmi block.

Parameters:

Name Type Description Default
gemmi_block dict[str, Any]

A Gemmi block.

required

Returns:

Name Type Description
Residues Residues

A Residues instance.

Source code in lahuta/core/arc.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
@classmethod
def from_gemmi(cls, gemmi_block: dict[str, Any]) -> "Residues":
    """Create a Residues instance from a Gemmi block.

    Args:
        gemmi_block (dict[str, Any]): A Gemmi block.

    Returns:
        Residues: A Residues instance.
    """
    cls_instance = cls.__new__(cls)

    # Create structured array
    resnames = np.array(gemmi_block["label_comp_id"])
    resids = np.array(gemmi_block["auth_seq_id"], dtype=int)

    data = np.empty(len(resnames), dtype=cls.dtype)
    data["resname"] = resnames
    data["resid"] = resids

    cls_instance.data = data

    return cls_instance

from_mda classmethod

from_mda(mda_universe)

Create a Residues instance from an MDAnalysis Universe.

Parameters:

Name Type Description Default
mda_universe UniverseType

An MDAnalysis Universe.

required

Returns:

Name Type Description
Residues Residues

A Residues instance.

Source code in lahuta/core/arc.py
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
@classmethod
def from_mda(cls, mda_universe: UniverseType) -> "Residues":
    """Create a Residues instance from an MDAnalysis Universe.

    Args:
        mda_universe (UniverseType): An MDAnalysis Universe.

    Returns:
        Residues: A Residues instance.
    """
    cls_instance = cls.__new__(cls)
    cls_instance.data = np.empty(len(mda_universe.atoms), dtype=cls_instance.dtype)
    cls_instance.data["resname"] = mda_universe.atoms.resnames
    cls_instance.data["resid"] = mda_universe.atoms.resids

    return cls_instance

Chains

The Chains class models and manages the properties of chains in a system.

The Chains class is part of the Atoms, Residues, Chains (ARC) module. It utilizes structured numpy arrays for effective handling, storage, and manipulation of chain-related data. This class specifically stores data related to chain labels, chain auth, and chain IDs.

Initialization of the Chains instances can be accomplished via two class methods: from_gemmi and from_mda. These methods enable the creation of Chains instances from Gemmi blocks or an MDAnalysis Universe respectively.

The class includes properties to retrieve chain attributes like labels, auths, and IDs, and provides methods to iterate over and access the chain data.

Attributes:

Name Type Description
_data NDArray[Any]

A numpy structured array storing chain properties.

mapping dict[str, int]

Mapping from chain auth to chain IDs.

Examples:

>>> from arc import Chains
>>> chains_from_gemmi = Chains.from_gemmi(gemmi_block)
>>> print(chains_from_gemmi.labels)
['A', 'B', 'C', ...]

>>> chains_from_mda = Chains.from_mda(uv)
>>> print(chains_from_mda.auths)
['A', 'B', 'C', ...]
Source code in lahuta/core/arc.py
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
class Chains:
    """The Chains class models and manages the properties of chains in a system.

    The Chains class is part of the Atoms, Residues, Chains (ARC) module. It utilizes structured
    numpy arrays for effective handling, storage, and manipulation of chain-related data. This
    class specifically stores data related to chain labels, chain auth, and chain IDs.

    Initialization of the Chains instances can be accomplished via two class methods:
    `from_gemmi` and `from_mda`. These methods enable the creation of Chains instances from
    Gemmi blocks or an MDAnalysis Universe respectively.

    The class includes properties to retrieve chain attributes like labels, auths, and IDs,
    and provides methods to iterate over and access the chain data.

    Attributes:
        _data (NDArray[Any]): A numpy structured array storing chain properties.
        mapping (dict[str, int]): Mapping from chain auth to chain IDs.

    Examples:
        ``` py
        >>> from arc import Chains
        >>> chains_from_gemmi = Chains.from_gemmi(gemmi_block)
        >>> print(chains_from_gemmi.labels)
        ['A', 'B', 'C', ...]

        >>> chains_from_mda = Chains.from_mda(uv)
        >>> print(chains_from_mda.auths)
        ['A', 'B', 'C', ...]
        ```
    """

    dtype = np.dtype({"names": ["label", "auth", "id"], "formats": ["<U10", "<U10", "int"]})

    def __init__(self, name: Optional[str] = None):
        self.name = name
        self.data: NDArray[Any] = np.empty(0, dtype=self.dtype)

        self.mapping: dict[str, int] = {}

    @classmethod
    def from_gemmi(cls, gemmi_block: dict[str, Any]) -> "Chains":
        """Create a Chains instance from a Gemmi block.

        Args:
            gemmi_block (dict[str, Any]): A Gemmi block.

        Returns:
            Chains: A Chains instance.
        """
        cls_instance = cls.__new__(cls)

        # Create structured array
        labels: NDArray[np.str_] = np.array(gemmi_block["label_asym_id"])
        auths: NDArray[np.str_] = np.array(gemmi_block["auth_asym_id"])
        _, ids = np.unique(auths, return_inverse=True)
        ids += 1

        data = np.empty(len(labels), dtype=cls.dtype)
        data["label"] = labels
        data["auth"] = auths
        data["id"] = ids

        cls_instance.data = data
        cls_instance.mapping = dict(zip(auths, ids, strict=True))

        return cls_instance

    @classmethod
    def from_mda(cls, mda_universe: UniverseType) -> "Chains":
        """Create a Chains instance from an MDAnalysis Universe.

        Args:
            mda_universe (UniverseType): An MDAnalysis Universe.

        Returns:
            Chains: A Chains instance.
        """
        cls_instance = cls.__new__(cls)
        cls_instance.data = np.empty(len(mda_universe.atoms), dtype=cls_instance.dtype)
        cls_instance.data["label"] = mda_universe.atoms.chainIDs
        cls_instance.data["auth"] = mda_universe.atoms.chainIDs
        _, cls_instance.data["id"] = np.unique(cls_instance.data["auth"], return_inverse=True)
        cls_instance.data["id"] += 1

        cls_instance.mapping = dict(zip(cls_instance.data["auth"], cls_instance.data["id"], strict=True))

        return cls_instance

    @property
    def labels(self) -> NDArray[np.str_]:
        """Chain labels."""
        return self.data["label"]

    @property
    def auths(self) -> NDArray[np.str_]:
        """Chain auths."""
        return self.data["auth"]

    @property
    def ids(self) -> NDArray[np.int32]:
        """Chain IDs."""
        return self.data["id"]

    def __len__(self) -> int:
        return len(self.data)

    def __getitem__(self, index: int | slice) -> NDArray[Any]:
        return self.data[index]

    def __iter__(self) -> Iterator[NDArray[Any]]:
        """Iterate over chains."""
        for i in range(len(self)):
            yield self[i]

labels property

labels

Chain labels.

auths property

auths

Chain auths.

ids property

ids

Chain IDs.

from_gemmi classmethod

from_gemmi(gemmi_block)

Create a Chains instance from a Gemmi block.

Parameters:

Name Type Description Default
gemmi_block dict[str, Any]

A Gemmi block.

required

Returns:

Name Type Description
Chains Chains

A Chains instance.

Source code in lahuta/core/arc.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
@classmethod
def from_gemmi(cls, gemmi_block: dict[str, Any]) -> "Chains":
    """Create a Chains instance from a Gemmi block.

    Args:
        gemmi_block (dict[str, Any]): A Gemmi block.

    Returns:
        Chains: A Chains instance.
    """
    cls_instance = cls.__new__(cls)

    # Create structured array
    labels: NDArray[np.str_] = np.array(gemmi_block["label_asym_id"])
    auths: NDArray[np.str_] = np.array(gemmi_block["auth_asym_id"])
    _, ids = np.unique(auths, return_inverse=True)
    ids += 1

    data = np.empty(len(labels), dtype=cls.dtype)
    data["label"] = labels
    data["auth"] = auths
    data["id"] = ids

    cls_instance.data = data
    cls_instance.mapping = dict(zip(auths, ids, strict=True))

    return cls_instance

from_mda classmethod

from_mda(mda_universe)

Create a Chains instance from an MDAnalysis Universe.

Parameters:

Name Type Description Default
mda_universe UniverseType

An MDAnalysis Universe.

required

Returns:

Name Type Description
Chains Chains

A Chains instance.

Source code in lahuta/core/arc.py
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
@classmethod
def from_mda(cls, mda_universe: UniverseType) -> "Chains":
    """Create a Chains instance from an MDAnalysis Universe.

    Args:
        mda_universe (UniverseType): An MDAnalysis Universe.

    Returns:
        Chains: A Chains instance.
    """
    cls_instance = cls.__new__(cls)
    cls_instance.data = np.empty(len(mda_universe.atoms), dtype=cls_instance.dtype)
    cls_instance.data["label"] = mda_universe.atoms.chainIDs
    cls_instance.data["auth"] = mda_universe.atoms.chainIDs
    _, cls_instance.data["id"] = np.unique(cls_instance.data["auth"], return_inverse=True)
    cls_instance.data["id"] += 1

    cls_instance.mapping = dict(zip(cls_instance.data["auth"], cls_instance.data["id"], strict=True))

    return cls_instance

ARC

The ARC class models and manages the properties of a biological system consisting of atoms, residues, and chains.

The ARC class integrates the Atoms, Residues, and Chains (ARC) module, by creating and storing instances of Atoms, Residues, and Chains classes. Depending on the type of the input object (either GemmiLoader or TopologyLoader), it uses the appropriate method from Atoms, Residues, and Chains classes to initialize them.

It provides methods to retrieve atom, residue, and chain information individually or together, as well as methods to iterate over and access this data.

Attributes:

Name Type Description
_atoms Atoms

An instance of the Atoms class.

_residues Residues

An instance of the Residues class.

_chains Chains

An instance of the Chains class.

Examples:

>>> from arc import ARC, GemmiLoader
>>> loader = GemmiLoader("path_to_structure")
>>> arc = ARC(loader, loader.site_data)
>>> atom_0 = arc.get_atom(0)
>>> print(atom_0)
Atom(name=..., id=..., element=..., type=..., resname=..., resid=..., chain_label=..., chain_id=...)

>>> print(arc.atoms)
Atoms(name=..., id=..., element=..., type=...)

>>> print(arc.residues)
Residues(resname=..., resid=...)
Source code in lahuta/core/arc.py
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
class ARC:
    """The ARC class models and manages the properties of a biological system consisting of atoms, residues, and chains.

    The ARC class integrates the Atoms, Residues, and Chains (ARC) module, by creating and storing
    instances of Atoms, Residues, and Chains classes.
    Depending on the type of the input object (either GemmiLoader or TopologyLoader), it uses the
    appropriate method from Atoms, Residues, and Chains classes to initialize them.

    It provides methods to retrieve atom, residue, and chain information individually or together,
    as well as methods to iterate over and access this data.

    Attributes:
        _atoms (Atoms): An instance of the Atoms class.
        _residues (Residues): An instance of the Residues class.
        _chains (Chains): An instance of the Chains class.

    Examples:
        ``` py
        >>> from arc import ARC, GemmiLoader
        >>> loader = GemmiLoader("path_to_structure")
        >>> arc = ARC(loader, loader.site_data)
        >>> atom_0 = arc.get_atom(0)
        >>> print(atom_0)
        Atom(name=..., id=..., element=..., type=..., resname=..., resid=..., chain_label=..., chain_id=...)

        >>> print(arc.atoms)
        Atoms(name=..., id=..., element=..., type=...)

        >>> print(arc.residues)
        Residues(resname=..., resid=...)
        ```
    """

    def __init__(
        self,
        obj: Union["GemmiLoader", "TopologyLoader"],
        site_data: dict[str, Any] | AtomGroupType,
    ):
        obj_name: str = obj.__class__.__name__
        obj_map = self._obj_map(obj_name)
        self._atoms: Atoms = getattr(Atoms, obj_map)(site_data)
        self._residues: Residues = getattr(Residues, obj_map)(site_data)
        self._chains: Chains = getattr(Chains, obj_map)(site_data)

    def _obj_map(self, obj_name: str) -> str:
        """Map the object name to the appropriate class method.

        Args:
            obj_name (str): The name of the object.

        Returns:
            str: The name of the class method.
        """
        mapping = {
            "GemmiLoader": "from_gemmi",
            "TopologyLoader": "from_mda",
        }
        return mapping[obj_name]

    def get_atom(self, index: int) -> "Atom":
        """Get an atom at a given index.

        Args:
            index (int): The index of the atom.

        Returns:
            Atom: An Atom instance.
        """
        atom_info = self._atoms[index]
        residue_info = self._residues[index]
        chain_info = self._chains[index]

        atom_kwargs = {
            "name": atom_info["name"],
            "id": atom_info["id"],
            "element": atom_info["element"],
            "type": atom_info["type"],
            "resname": residue_info["resname"],
            "resid": residue_info["resid"],
            "chain_label": chain_info["label"],
            "chain_id": chain_info["id"],
        }

        return Atom(**atom_kwargs)

    @property
    def atoms(self) -> "Atoms":
        """Atoms instance."""
        return self._atoms

    @property
    def residues(self) -> "Residues":
        """Residues instance."""
        return self._residues

    @property
    def chains(self) -> "Chains":
        """Chains instance."""
        return self._chains

    def __len__(self) -> int:
        return len(self._atoms)

    def __getitem__(self, index: int | slice) -> Union["Atom", list["Atom"]]:
        if isinstance(index, int):
            return self.get_atom(index)

        indices = np.arange(len(self))[index]
        return [self.get_atom(i) for i in indices]

    def __iter__(self) -> Iterator["Atom"]:
        """Iterate over atoms."""
        return (self.get_atom(i) for i in range(len(self)))

atoms property

atoms

Atoms instance.

residues property

residues

Residues instance.

chains property

chains

Chains instance.

get_atom

get_atom(index)

Get an atom at a given index.

Parameters:

Name Type Description Default
index int

The index of the atom.

required

Returns:

Name Type Description
Atom Atom

An Atom instance.

Source code in lahuta/core/arc.py
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
def get_atom(self, index: int) -> "Atom":
    """Get an atom at a given index.

    Args:
        index (int): The index of the atom.

    Returns:
        Atom: An Atom instance.
    """
    atom_info = self._atoms[index]
    residue_info = self._residues[index]
    chain_info = self._chains[index]

    atom_kwargs = {
        "name": atom_info["name"],
        "id": atom_info["id"],
        "element": atom_info["element"],
        "type": atom_info["type"],
        "resname": residue_info["resname"],
        "resid": residue_info["resid"],
        "chain_label": chain_info["label"],
        "chain_id": chain_info["id"],
    }

    return Atom(**atom_kwargs)

Atom dataclass

The Atom class models and manages the properties of an atom in a system.

The Atom class stores information related to a single atom in a system. It's created using keyword arguments, which allows it to dynamically store any attributes passed. The attributes include, but are not limited to, atom name, ID, element, type, residue name, residue ID, chain label, and chain ID.

The Atom class includes methods for representing and printing atom information. Note that all attributes are optional and can be passed as keyword arguments.

Examples:

>>> from arc import Atom
>>> atom = Atom(name='CA', id=1, element='C', type='C.3', resname='ALA', resid=1, chain_label='A', chain_id=1)
>>> print(atom)
Atom(name=CA, id=1, element=C, type=C.3, resname=ALA, resid=1, chain_label=A, chain_id=1)
Source code in lahuta/core/arc.py
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
@dataclass
class Atom:
    """The Atom class models and manages the properties of an atom in a system.

    The Atom class stores information related to a single atom in a system.
    It's created using keyword arguments, which allows it to dynamically store any attributes passed.
    The attributes include, but are not limited to, atom name, ID, element, type,
    residue name, residue ID, chain label, and chain ID.

    The Atom class includes methods for representing and printing atom information.
    Note that all attributes are optional and can be passed as keyword arguments.

    Examples:
        ``` py
        >>> from arc import Atom
        >>> atom = Atom(name='CA', id=1, element='C', type='C.3', resname='ALA', resid=1, chain_label='A', chain_id=1)
        >>> print(atom)
        Atom(name=CA, id=1, element=C, type=C.3, resname=ALA, resid=1, chain_label=A, chain_id=1)
        ```
    """

    # TODO @bisejdiu: specify the type of kwargs
    def __init__(self, **kwargs: Any):  # noqa: ANN401
        self.__dict__.update(kwargs)

    def __repr__(self) -> str:
        attrs = ", ".join(f"{k}={v}" for k, v in self.__dict__.items())
        return f"Atom({attrs})"