I frequently work with Protein Data Bank files. These are text files that contain atomic level structure information of molecules. They can be recognized by their '.pdb' extension.

Whenever editing them in Emacs (GNU Emacs 24.3.1), in the main buffer I see a small box in the top left corner and the minibuffer has the instructions, "Type C-c C-c to view the image as text." In the bar between the minibuffer and the main buffer, it list that the mode is (Image[imagemagick]). After pressing C-c C-c, this mode changes to (Fundamental Image[imagemagick]). It has got to the point where I quickly type C-c C-c almost without thinking about it to view and edit the text file but I would rather not have to. How do I make it default to the (Fundamental Image[imagemagick]) mode? I would think I could add some hook to my init.el file but I am not sure what.

Here is an example of text that when saved as test.pdb produces the behavior described:

ATOM      1  O5' CYT X   1      32.071  -1.490 114.864  1.00  0.00      DNA1 O
ATOM      2  C5' CYT X   1      30.711  -1.577 114.398  1.00  0.00      DNA1 C
ATOM      3  C4' CYT X   1      30.171  -0.188 114.035  1.00  0.00      DNA1 C
ATOM      4  O4' CYT X   1      30.040   0.620 115.241  0.00  0.00      DNA1 O
ATOM      5  C1' CYT X   1      30.111   1.904 114.881  0.00  0.00      DNA1 C
ATOM      6  C2' CYT X   1      31.383   1.832 114.043  0.00  0.00      DNA1 C
ATOM      7  C3' CYT X   1      31.091   0.649 113.121  1.00  0.00      DNA1 C
ATOM      8  O3' CYT X   1      30.453   0.939 111.890  1.00  0.00      DNA1 O
ATOM      9  P   THY X   2      29.768   2.098 111.098  1.00  0.00      DNA1 P

I noticed that when opening files in a terminal using the 'no window' option, emacs -nw test.pdb, it opens using (Fundamental Image) mode, without the [imagemagick] part. I am not sure the difference but if I would be happy if I could get that behavior in the windowed version (I do not intend to only edit within the terminal).

I do wonder why Emacs tries to render the file as an image. It is clearly related to having ImageMagick installed but I am not sure the specifics. Does anyone know if it actually can correctly read and render the molecule/s contained in pdb files?

Searching Google for a solution, I see several hit regarding python interactive debugger, the pdb package, and using that from Emacs. Obviously that is not what I am looking for.

This behavior has been consistent over multiple Emacs updates for the past several years on several computers but the specific version info for the Emacs I am currently using is the following: GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.7) of 2014-03-07 on lamiak, modified by Debian.

If you have recommendations of better Tags which will help this get seen by people that would have input, please let me know.

  • 1
    What if you just do: (add-to-list 'auto-mode-alist '("\\.pdb$" . text-mode))?
    – wvxvw
    Commented Mar 10, 2015 at 16:27
  • 3
    Do you get this same behavior with emacs -Q, i.e. with the default Emacs configuration?
    – glucas
    Commented Mar 10, 2015 at 16:35
  • 1
    Using the example I just added, saved as test.pdb, I do get the same behavior when opening the file using emacs -Q test.pdb. Commented Mar 11, 2015 at 13:55

1 Answer 1


This is controlled by the variable auto-mode-alist, which you can modify by adding the following line to your emacs init file:

(add-to-list 'auto-mode-alist '("\\.pdb$" . text-mode))

The "\\.pdb$" part is a regular expression that matches files ending in pdb. The part after the period is the mode you want to use instead of the default.

  • 1
    +1, but I'm curious where that behavior is coming from in the first place. Pdb files open in fundamental mode for me, unless there is something about the content itself that isn't reflected in the sample I copied from a web page.
    – glucas
    Commented Mar 10, 2015 at 17:32
  • @glucas I just added the lines for a short example file which produces the behavior. I am not sure the origin of the behavior. Commented Mar 11, 2015 at 13:58
  • Changing @Sue's add-to-list command to (add-to-list 'auto-mode-alist '("\\.pdb$" . fundamental-image-mode)) opens the file using (Fundamental) mode. I am pretty sure this is an incorrect mode as it does not use (Fundamental Image[imagemagick]) mode but it is better than text-mode as it does not load the flyspell library I use for txt files (I do not want to spell check pdb files). I think I will settle on (add-to-list 'auto-mode-alist '("\\.pdb$" . fundamental-mode)) as I think this may be a real mode. Commented Mar 11, 2015 at 14:54
  • I haven't used Emacs to edit images or image files much, so take the following with a grain of salt. When no mode has been selected, Emacs falls back to fundamental mode, and it displays in the mode line as (Fundamental). There is a mode that ships with Emacs called image-mode, and it displays in the mode line as (Image[...]), where the ... refers to the type of image being displayed/edited. The only way I can see that both of them can be displayed at once is by using image-minor-mode, which is (obviously?) a variant of image-mode. Commented Mar 11, 2015 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.