SDFile#

class biotite.structure.io.mol.SDFile(records=None)[source]#

Bases: File, MutableMapping

This class represents an SD file for storing small molecule structures.

The records for each molecule in the file can be accessed and modified like a dictionary. The structures can be parsed and written from/to each SDRecord object via get_structure() or set_structure(), respectively.

Examples

Read a SD file and parse the molecular structure:

>>> import os.path
>>> file = SDFile.read(os.path.join(path_to_structures, "molecules", "TYR.sdf"))
>>> molecule = file.record.get_structure()
>>> print(molecule)
        0             N         1.320    0.952    1.428
        0             C        -0.018    0.429    1.734
        0             C        -0.103    0.094    3.201
        0             O         0.886   -0.254    3.799
        0             C        -0.274   -0.831    0.907
        0             C        -0.189   -0.496   -0.559
        0             C         1.022   -0.589   -1.219
        0             C        -1.324   -0.102   -1.244
        0             C         1.103   -0.282   -2.563
        0             C        -1.247    0.210   -2.587
        0             C        -0.032    0.118   -3.252
        0             O         0.044    0.420   -4.574
        0             O        -1.279    0.184    3.842
        0             H         1.977    0.225    1.669
        0             H         1.365    1.063    0.426
        0             H        -0.767    1.183    1.489
        0             H         0.473   -1.585    1.152
        0             H        -1.268   -1.219    1.134
        0             H         1.905   -0.902   -0.683
        0             H        -2.269   -0.031   -0.727
        0             H         2.049   -0.354   -3.078
        0             H        -2.132    0.523   -3.121
        0             H        -0.123   -0.399   -5.059
        0             H        -1.333   -0.030    4.784

Note that important atom annotations may be missing. These can be set afterwards:

>>> molecule.res_name[:] = "TYR"
>>> molecule.atom_name[:] = create_atom_names(molecule)
>>> print(molecule)
        0  TYR N1     N         1.320    0.952    1.428
        0  TYR C1     C        -0.018    0.429    1.734
        0  TYR C2     C        -0.103    0.094    3.201
        0  TYR O1     O         0.886   -0.254    3.799
        0  TYR C3     C        -0.274   -0.831    0.907
        0  TYR C4     C        -0.189   -0.496   -0.559
        0  TYR C5     C         1.022   -0.589   -1.219
        0  TYR C6     C        -1.324   -0.102   -1.244
        0  TYR C7     C         1.103   -0.282   -2.563
        0  TYR C8     C        -1.247    0.210   -2.587
        0  TYR C9     C        -0.032    0.118   -3.252
        0  TYR O2     O         0.044    0.420   -4.574
        0  TYR O3     O        -1.279    0.184    3.842
        0  TYR H1     H         1.977    0.225    1.669
        0  TYR H2     H         1.365    1.063    0.426
        0  TYR H3     H        -0.767    1.183    1.489
        0  TYR H4     H         0.473   -1.585    1.152
        0  TYR H5     H        -1.268   -1.219    1.134
        0  TYR H6     H         1.905   -0.902   -0.683
        0  TYR H7     H        -2.269   -0.031   -0.727
        0  TYR H8     H         2.049   -0.354   -3.078
        0  TYR H9     H        -2.132    0.523   -3.121
        0  TYR H10    H        -0.123   -0.399   -5.059
        0  TYR H11    H        -1.333   -0.030    4.784

Create a SD file and write it to disk:

>>> another_molecule = residue("ALA")
>>> file = SDFile()
>>> record = SDRecord()
>>> record.set_structure(molecule)
>>> file["TYR"] = record
>>> record = SDRecord()
>>> record.set_structure(another_molecule)
>>> file["ALA"] = record
>>> file.write(os.path.join(path_to_directory, "some_file.cif"))
>>> print(file)
TYR


 24 24  0     0  0  0  0  0  0  1 V2000
    1.3200    0.9520    1.4280 N   0  0  0  0  0  0  0  0  0  0  0  0
   -0.0180    0.4290    1.7340 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.1030    0.0940    3.2010 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.8860   -0.2540    3.7990 O   0  0  0  0  0  0  0  0  0  0  0  0
   -0.2740   -0.8310    0.9070 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.1890   -0.4960   -0.5590 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.0220   -0.5890   -1.2190 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.3240   -0.1020   -1.2440 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.1030   -0.2820   -2.5630 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.2470    0.2100   -2.5870 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.0320    0.1180   -3.2520 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.0440    0.4200   -4.5740 O   0  0  0  0  0  0  0  0  0  0  0  0
   -1.2790    0.1840    3.8420 O   0  0  0  0  0  0  0  0  0  0  0  0
    1.9770    0.2250    1.6690 H   0  0  0  0  0  0  0  0  0  0  0  0
    1.3650    1.0630    0.4260 H   0  0  0  0  0  0  0  0  0  0  0  0
   -0.7670    1.1830    1.4890 H   0  0  0  0  0  0  0  0  0  0  0  0
    0.4730   -1.5850    1.1520 H   0  0  0  0  0  0  0  0  0  0  0  0
   -1.2680   -1.2190    1.1340 H   0  0  0  0  0  0  0  0  0  0  0  0
    1.9050   -0.9020   -0.6830 H   0  0  0  0  0  0  0  0  0  0  0  0
   -2.2690   -0.0310   -0.7270 H   0  0  0  0  0  0  0  0  0  0  0  0
    2.0490   -0.3540   -3.0780 H   0  0  0  0  0  0  0  0  0  0  0  0
   -2.1320    0.5230   -3.1210 H   0  0  0  0  0  0  0  0  0  0  0  0
   -0.1230   -0.3990   -5.0590 H   0  0  0  0  0  0  0  0  0  0  0  0
   -1.3330   -0.0300    4.7840 H   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  1  0  0  0  0
  1 14  1  0  0  0  0
  1 15  1  0  0  0  0
  2  3  1  0  0  0  0
  2  5  1  0  0  0  0
  2 16  1  0  0  0  0
  3  4  2  0  0  0  0
  3 13  1  0  0  0  0
  5  6  1  0  0  0  0
  5 17  1  0  0  0  0
  5 18  1  0  0  0  0
  6  7  2  0  0  0  0
  6  8  1  0  0  0  0
  7  9  1  0  0  0  0
  7 19  1  0  0  0  0
  8 10  2  0  0  0  0
  8 20  1  0  0  0  0
  9 11  2  0  0  0  0
  9 21  1  0  0  0  0
 10 11  1  0  0  0  0
 10 22  1  0  0  0  0
 11 12  1  0  0  0  0
 12 23  1  0  0  0  0
 13 24  1  0  0  0  0
M  END
$$$$
ALA


 13 12  0     0  0  0  0  0  0  1 V2000
   -0.9660    0.4930    1.5000 N   0  0  0  0  0  0  0  0  0  0  0  0
    0.2570    0.4180    0.6920 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.0940    0.0170   -0.7160 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.0560   -0.6820   -0.9230 O   0  0  0  0  0  0  0  0  0  0  0  0
    1.2040   -0.6200    1.2960 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.6610    0.4390   -1.7420 O   0  0  0  0  0  0  0  0  0  0  0  0
   -1.3830   -0.4250    1.4820 H   0  0  0  0  0  0  0  0  0  0  0  0
   -0.6760    0.6610    2.4520 H   0  0  0  0  0  0  0  0  0  0  0  0
    0.7460    1.3920    0.6820 H   0  0  0  0  0  0  0  0  0  0  0  0
    1.4590   -0.3300    2.3160 H   0  0  0  0  0  0  0  0  0  0  0  0
    0.7150   -1.5940    1.3070 H   0  0  0  0  0  0  0  0  0  0  0  0
    2.1130   -0.6760    0.6970 H   0  0  0  0  0  0  0  0  0  0  0  0
    0.4350    0.1820   -2.6470 H   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  1  0  0  0  0
  1  7  1  0  0  0  0
  1  8  1  0  0  0  0
  2  3  1  0  0  0  0
  2  5  1  0  0  0  0
  2  9  1  0  0  0  0
  3  4  2  0  0  0  0
  3  6  1  0  0  0  0
  5 10  1  0  0  0  0
  5 11  1  0  0  0  0
  5 12  1  0  0  0  0
  6 13  1  0  0  0  0
M  END
$$$$
Attributes:
recordCIFBlock

The sole record of the file. If the file contains multiple records, an exception is raised.

copy()#

Create a deep copy of this object.

Returns:
copy

A copy of this object.

static deserialize(text)#

Create an object by deserializing the given text content.

Parameters:
contentstr

The content to be deserialized.

classmethod read(file)#

Read a SD file.

Parameters:
filefile-like object or str

The file to be read. Alternatively a file path can be supplied.

Returns:
file_objectSDFile

The parsed file.

serialize()#

Convert this object into text content.

Returns:
contentstr

The serialized content.

write(file)#

Write the contents of this object into a SD file.

Parameters:
filefile-like object or str

The file to be written to. Alternatively a file path can be supplied.