07 February 2012

58. Higher resolution on a Dell E177FPb monitor using modelines in xorg.conf on Debian Testing

Update 24 May 2013: this still works fine on the optiplex (with intel onboard graphics) but when trying it on a different machine with an external nvidia card I couldn't get it to work. There only "xrandr --output VGA-0 --scale 1.1x1.1" worked.

Original post:
I've hooked up my fancy new-ish optiplex 990 to an old Dell E177FPb monitor which I bought back in 2007. For various reasons I've also removed the nvidia quattro graphics card that the optiplex 990 came with -- the main reasons being 1) I hate displayport and _need_ vga and 2) the bios forces you to press 'any key' on each boot if you leave the card in, even though you've configured the OS to use the integrated onboard graphics.

At any rate, hooking my old screen to my dell lead to a less than overwhelming experience -- and querying the 'Displays' setting in gnome showed only two resolution options: 1024x768 and 800x600. Well, I knew for a fact that the maximum resolution should be 1280x1024.

This was a bit of a surprise given that the same xorg.conf had been used together with a fancy widescreen 1920x1080 display -- yet it would not handle a 1280x1024 display? I guess this might say more about my lack of understanding how display drivers work, but whatever.

Well, in the end it turned out to be easy to enable the missing resolution mode.

First, a minimal amount of googling told me that the max resolution was 1280x1024 at 75 Hz.
"Preset Resolution: 1280 x 1024 @ 75 Hz"

Next, using gtf I generated a Modeline line.

gtf 1280 1024 75
Modeline     "1280x1024_75.00" 138.54 1280 1368 1504 1728 1024 1025 1028 1069 -HSync +Vsync

Finally, I then edited the xorg.conf (again, see this post for the entire xorg.conf), changing


Section "Monitor"
Identifier   "Monitor0"
VendorName   "Monitor Vendor"
ModelName    "Monitor Model"
EndSection

to


Section "Monitor"
Identifier   "Monitor0"
VendorName   "Monitor Vendor"
ModelName    "Monitor Model"
Modeline     "1280x1024_75.00" 138.54 1280 1368 1504 1728 1024 1025 1028 1069 -HSync +Vsync
EndSection

Doing startx to start up gnome, followed by selecting Displays, then selecting Resolution: 1280x1024 (5:4) yielded a beautifully satisfying  user experience.

I'm not one to fiddle with xorg.conf, but this time it turned out that the fix was easy once I had figured out what to do.

01 February 2012

57. Making life in linux easier -- Small fixes and tasks

Here's a list over simple fixes and tasks in Debian that I've been running into the past few weeks. I'll be adding to it over time.

Index of the ever-growing list
1. INIT: Id "co" respawning too fast: disabled for 5 minutes
2. Boot into terminal instead of gdm (kdm/xdm etc.)
3. Change the logical name of an ethernet card -- why do I have eth1 and rename2 and how to get eth0 and eth1 instead?
4. Configuring ethernet cards in gnome3/gnome-shell -- can't save changes in network-manager
5. Gnome3/gnome-shell -- Alt+f2 yields "command not found"
6. /etc/hosts keep on being overwritten
7. Getting Leadtek DTV1000s to work in Linux
8. Turning off terminal beep
9. Trouble with apt-get  -- can't do apt-get update
10. Adding and removing pages in a pdf using pdftk
11. Updating the locate database
12. My gateway doesn't play well with sinfo
13. Basic proxy via ssh
14. Using a Compose key to type non-standard characters like å, ä, ö
15. Command not found, did you mean ..? Installing command-not-found
16. apt-listbugs
17. Thunar is the default file manager in spite of me running Gnome!
18. Nautilus recognises compressed files, but doesn't know how to open them
19. Finding out when a package was installed
20. Showing your kernel and debian version
21. Screen dump in the terminal
22. Enable java in chrome
23. Changing element colour in gdis
24. CCSD mercury /lib/libc6.so
25. Daemons...rcconf, sysv-rc-conf and update-rc.d
26. Adjusting your webcam
27. Command line burning of iso
29. USB support in virtualbox
30. Start-up applications in Gnome 3.4
31. Changing pulseaudio volume from the command line


1. INIT: Id "co" respawning too fast: disabled for 5 minutes
References: http://www.linuxquestions.org/questions/fedora-35/init-id-co-respawning-too-fast-disabled-for-5-minutes-736393/ and http://www.linuxquestions.org/questions/linux-newbie-8/reload-inittab-without-reboot-366505/

Instructions: 
Edit /etc/inittab
Find a line saying
co:2345:respawn:/sbin/getty hvc0 9600 linux
and comment it out by prefixing it with a #;

#co:2345:respawn:/sbin/getty hvc0 9600 linux

Run 
sudo init q
to make the changes take effect.

2. Boot into terminal instead of gdm (kdm/xdm etc.)
Instructions:
Method 1:
Edit /etc/default/grub
Change
GRUB_CMDLINE_DEFAULT="quiet splash nomodeset nouveau.modeset=0"
to
GRUB_CMDLINE_DEFAULT="quiet splash text nomodeset nouveau.modeset=0"

(You may obviously not have nomodset etc. in that line. )
IMPORTANT: run
sudo update-grub

to make the changes take effect.

To start up a desktop type startx

3. Change the logical name of an ethernet card -- why do I have eth1 and rename2 and how to get eth0 and eth1 instead?  
Edit /etc/udev/rules.d/70-persistent-net.rules
You'll find lines like this one:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:e9:90:00", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

You can bind a logical name (NAME="eth0") to a mac address (ATTR{address}=="") here.

NOTE that interfaces handled by network-manager won't show up here. Unless you initialise a network interface in /etc/network/interfaces they will be handled by network-manager.

4. Configuring ethernet cards in gnome3/gnome-shell -- can't save changes in network-manager
If you click on the network icon in gnome3/gnome-shell, then network settings, wired, configure and edit the connection, then hit save, you may find that it won't save the changes. You may even see a black box asking for admin password flash by and disappearing.

There's no real fix -- make sure to start the Network Connections application the 'normal' way instead (top left corner, type in networ... and pick network connections. You'll be able to save your changes now.

5. Gnome3/gnome-shell -- Alt+f2 yields "command not found"
Edit /usr/share/gnome-shell/js/misc/util.js 
Delete all instances of argc e.g. if it say success, argc, argv -- change to success, argv

6. /etc/hosts keep on being overwritten
The culprit is -- no surprise --- network-manager. You can either fight it, or use network-manager to manage your configuration.

My particular case was this: my computer is called tantalum. I don't want tantalum to be associated with 127.0.1.1 or 127.0.0.1 though (mpich2 reasons), but want to associate the host name with the external ip address (192.168.1.102). This is a typical case where you'd edit /etc/hosts and you'd be done. Apart from the fact that the file gets overwritten on each boot.

To force it using network manager, start network-admin in the terminal or using alt+f2, go to Hosts, and remove your hostname from 127.0.1.1 and add it using the desired ip address.

Reading this it seems like it's possible making changes in the configuration files directly. In particular, the option to define unmanaged devices looks interesting.

Network Manager is one of those programs which are great when you need basic functionality from your system, but an absolute pain in the arse when you need to do something non-standard.


7. Getting Leadtek DTV1000s to work in Linux
This is a bit of a non-fix...the card should work out of the box, so to speak.
However, it didn't for me. 

If lspci gives Philips something or other and rev ff rather than e.g. rev 01 as well as MMIO errors, check your BIOS! I kept on getting very little information about my card when doing lspci -vn and it turned out that I had disabled PnP in the BIOS. Once the bios was set to allow the OS to configure PCI devices (Plug-and-play OS), everything worked like a charm.

I put
options saa7134 tuner=48 card=175
in my /etc/modules, but I'm not sure this matters.

Long before discovering that I built and installed the v4l-dvb media build from the git repos,
(Easily done like this:
git clone git://linuxtv.org/media_build.git
cd media_build
./build
)
 and downloaded the firmware packages by Mike Krufky (http://tw1965.myweb.hinet.net/), and spent time reading forum posts (starting with http://forums.whirlpool.net.au/archive/942269). What I'm saying is that I don't THINK you will need to install or compile anything, but you MAY have to. Make sure your BIOS settings are right first though.

Here's lcpci -vvnn for a working leadtek dtv1000s:

01:06.0 Multimedia controller [0480]: Philips Semiconductors SAA7130 Video Broadcast Decoder [1131:7130] (rev 01)
Subsystem: LeadTek Research Inc. WinFast DTV1000S [107d:6655]
Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
Latency: 64 (21000ns min, 8000ns max)
Interrupt: pin A routed to IRQ 19
Region 0: Memory at deeffc00 (32-bit, non-prefetchable) [size=1K]
Capabilities: <access denied>l
Kernel driver in use: saa7134

Here's dmesg|grep saa
    7.213108] saa7130/34: v4l2 driver version 0, 2, 17 loaded
[    7.213383] saa7134 0000:01:06.0: PCI INT A -> Link[LNKC] -> GSI 19 (level, low) -> IRQ 19
[    7.213387] saa7130[0]: found at 0000:01:06.0, rev: 1, irq: 19, latency: 64, mmio: 0xdeeffc00
[    7.213392] saa7130[0]: subsystem: 107d:6655, board: Leadtek Winfast DTV1000S [card=175,autodetected]
[    7.213407] saa7130[0]: board init: gpio is 2020000
[    7.260128] input: saa7134 IR (Leadtek Winfast DTV as /devices/pci0000:00/0000:00:04.0/0000:01:06.0/rc/rc0/input6
[    7.260181] rc0: saa7134 IR (Leadtek Winfast DTV as /devices/pci0000:00/0000:00:04.0/0000:01:06.0/rc/rc0
[    7.412048] saa7130[0]: i2c eeprom 00: 7d 10 55 66 54 20 1c 00 43 43 a9 1c 55 d2 b2 92
[    7.412055] saa7130[0]: i2c eeprom 10: 00 ff 82 0e ff 20 ff ff ff ff ff ff ff ff ff ff
[    7.412060] saa7130[0]: i2c eeprom 20: 01 40 01 01 01 ff 01 03 08 ff 00 8a ff ff ff ff
[    7.412065] saa7130[0]: i2c eeprom 30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412070] saa7130[0]: i2c eeprom 40: ff 35 00 c0 00 10 03 02 ff 04 ff ff ff ff ff ff
[    7.412074] saa7130[0]: i2c eeprom 50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412079] saa7130[0]: i2c eeprom 60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412084] saa7130[0]: i2c eeprom 70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412089] saa7130[0]: i2c eeprom 80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412093] saa7130[0]: i2c eeprom 90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412098] saa7130[0]: i2c eeprom a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412103] saa7130[0]: i2c eeprom b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412108] saa7130[0]: i2c eeprom c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412113] saa7130[0]: i2c eeprom d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412117] saa7130[0]: i2c eeprom e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412122] saa7130[0]: i2c eeprom f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.608255] saa7130[0]: registered device video0 [v4l2]
[    7.608280] saa7130[0]: registered device vbi0


8. Turning off terminal beep
To remove immediately:
sudo modprobe -r pcspkr snd_pcsp

To turn off permanently:
create a file called blacklist.conf in /etc/modprobe.d
Put the following in it:
blacklist pcspkr
blacklist snd_pcsp
9. Trouble with apt-get  -- can't do apt-get update
The issue:
On running

sudo apt-get update

you get

Reading package lists... Error!
E: Encountered a section with no Package: header
E: Problem with MergeList /var/lib/apt/lists/192.168.1.1:3142_ftp.au.debian.org_debian_dists_testing_contrib_i18n_Translation-en
E: The package lists or status file could not be parsed or opened.
The solution:
First, look in /var/lib/apt/lists

ls /var/lib/apt/lists/ -lah | grep contrib |grep i18n| grep testing

which gives

-rw-r--r-- 1 root root  34K Feb  3 07:01 192.168.1.1:3142_ftp.au.debian.org_debian_dists_testing_contrib_i18n_Translation-en
-rw-r--r-- 1 root root 121K Feb  3 07:01 192.168.1.1:3142_ftp.au.debian.org_debian_dists_testing_contrib_i18n_Translation-en%5fAU

Then remove the offending file:

sudo rm /var/lib/apt/lists/192.168.1.1:3142_ftp.au.debian.org_debian_dists_testing_contrib_i18n_Translation-en

And do sudo apt-get update again -- it should now work.

If it doesn't then you're lacking bzip2 and should look at this post.

10. Adding and removing pages in a pdf using pdftk
Scenario:
I have a pdf document which I need to sign on the last page. Instead of printing the entire document and scanning it, I print the last page, scan it and replace the last page of the original pdf with it.

How to do:
In my case I have a 27 page document and want to replace pages 25, 26 and 27..

Remove pages 25-27 from original document i.e.keep 1-24:
pdftk original.pdf cat 1-24 output new.pdf

Add new pages 25,26 and 27 which make up signatures.pdf
pdftk cat new.pdf signatures.pdf output final_document

11. Updating the locate database
locate is a good command for finding certain types of files. It seems to be continously, but not immediately, updated.

To force the locate database to update:
sudo updatedb

12. My gateway doesn't play well with sinfo
My gateway is a computer with two eth cards -- one connected to the internet and one to a switch making up a local subnet. All the boxes on the local subnet can see each other's sinfod instances, but not the gateway machine.

Turns out the fix is simple -- change /etc/default/sinfo:
from
#OPTS="${OPTS} --bcastaddress=127.0.0.1"
to
OPTS="${OPTS} --bcastaddress=192.168.1.255"
which is the appropriate broadcast for my subnet.

Sinfo is cool and a 'must' for anyone running a small LAN for computational reasons:

/ 3 nodes, 11 CPUs   total CPU utilization:   2.7% ( 0.351 GHz / 12.800 GHz )
beryllium                     uuuuuusssiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii-------------------------
( 4) mem: 55.6% swap:  0.0%   us:  4.8%    id: 92.7%        me S   8.9   0 chrome     
me S   6.6   0 vmd_LINUXAMD64
     
me S   5.5   0 chrome
     
me S   4.5   0 gnome-shell
     
root R   4.0   0 Xorg

kookaburra                    iiii---------------------------------------------------------------------------------------------------------------------------------------------------------
( 1) mem: 22.9% swap:  0.0%   us:  0.0%                            sy:  0.0%                            ni:  0.0%    wa:  0.0%                            id:100.0%     
me S   0.2   0 sinfo
   
daemon R   0.1  10 sinfod
       
ntp S   0.0   0 ntpd
     
root S   0.0   0 rsyslogd
       
root S   0.0   0 /usr/sbin/apach
tantalum                      iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii( 1) mem: 20.9% swap:  0.0%   us:  0.0%                            sy:  0.0%                            ni:  0.0%                            wa:  0.0%    ;id:100.0%     
me S   0.3   0 conky
       
root S   0.2   0 Xorg
     
me S   0.1   0 gnome-shell
     
me  S   0.1   0 dropbox
     
me S   0.0   0 linphone-3

If you can't see all the boxes on your gateway, change all the LAN boxes to broadcast on 192.168.1.255 (or the appropriate replacement).

13. Basic proxy via ssh
If you have an ssh account on another server you can use it as a proxy

ssh -C -D 9889 me@remote.server.org

-C turns on compression
-D redirects traffic sent to port 9889 to the remote.server.org

Chrome/Chromium use the system settings for the network connection:
To use the proxy for web browsing on gnome 3/gnome-shell, left-click on the connection icon in the top right corner of your desktop (or just go to System Settings), select Network Settings, Click on the tab called Network Proxy, Method: Manual, and set SOCKS host to localhost and port to 9889. You can also change it in Chrome/Chromium -- preferences/proxy which opens the system-wide network settings.


Iceweasel/Firefox by default uses it's own settings:
Edit/Preferences/Network tab/Connections - Settings... -- Select Manual Proxy Configuration, SOCKS hosts: localhost, port 9889.

14. Using a Compose key to type non-standard characters like å, ä, ö
In gnome 3/gnome-shell, open Region and Languages in the System Settings; select the Layout tab. Pick your usual language (e.g. English (US)) and click on options. Expand the Compose Key Position and pick a key to use as the Compose Key, e.g. right alt or the windows symbol key.

Now you can type fancy European characters with a lot more ease -- for a list over key sequences, look here.

Two example -- to type É first touch the compose key (don't hold it down), then ', then shift+E. For å do compose, o, a. For € do compose, =, c. For ö, do compose, ", o.

15. Command not found, did you mean ..? Installing command-not-found
On a basic install of debian, typing nfs gets you

me@lithium:~$ nfs
-bash: nfs: command not found
Linux can do better than that:

Install command-not-found
sudo apt-get install command-not-found
sudo update-command-not-found

Restart the shell (or log in and out)

Now, when typing nfs you get:
me@lithium:~$ nfs
No command 'nfs' found, did you mean:
 Command 'lfs' from package 'lustre-utils' (main)
 Command 'xfs' from package 'xfs' (main)
 Command 'knfs' from package 'openafs-client' (main)
 Command 'nns' from package 'tcllib' (main)
 Command 'ns' from package 'ns2' (main)
 Command 'fs' from package 'openafs-client' (main)
 Command 'zfs' from package 'zfs-fuse' (main)
 Command 'hfs' from package 'hfsutils-tcltk' (main)
nfs: command not found

16. apt-listbugs
A useful tool for catching problematic packages when you upgrade/dist-upgrade is to use apt-listbugs. It gets invoked automatically when you run sudo apt-get...

Install by
sudo apt-get install apt-listbugs

For an example of it in action, see http://www.worksinmymind.com/blog/?p=1125

17. Thunar is the default file manager in spite of me running Gnome!
You can either remove thunar -- which you probably got through install xfce4 -- or you can edit .config/xfc4/helpers.rc


me@niobium:~$ cat .config/xfce4/helpers.rc
MailReader=evolution
#FileManager=Thunar
FileManager=nautilus
WebBrowser=google-chrome

18. Nautilus recognises compressed files, but doesn't know how to open them
Install file-roller. You may want to install additional packages as per aptitude show file-roller:
Suggests: arj, binutils, cpio, lha, lzip, lzma, lzop, ncompress, rpm2cpio, rzip, sharutils, unace, unalz, unrar |
          p7zip-rar, unzip, xz-utils, zip, zoo
19. Finding out when a package was installed
Look here.

Listing all packages according to time, most recent last.
ls /var/lib/dpkg/info/*.list -lrth| grep "info/lib"
Looking for a specific subset of packages
ls /var/lib/dpkg/info/*.list -lrth| grep "info/lib"
20. Showing your kernel and debian version
Someone searched for www.google.co.kr — linux debian version check and ended up on this blog. Well, here are the answers:
me@beryllium:~$ uname -a
Linux beryllium 3.2.0-1-amd64 #1 SMP Sun Feb 5 15:17:15 UTC 2012 x86_64 GNU/Linux
me@beryllium:~$ cat /etc/debian_version
wheezy/sid

21. Screen dump in the terminal
Method 1. Works in the 'true' terminals i.e. ttyX:
If you want to save what is already on the screen into a text file, do
sudo cat /dev/vcsX > screendump.txt
where X is the number of your terminal (e.g. tty1, tty2 etc.)

This method does not seem to add linebreaks -- instead it presumes that you're using a standard 80 char terminal.


Method 2. Using framebuffer
First check if you are using the framebuffer
ls /dev/fb0
If so, install fbcat
sudo apt-get install fbcat

Get a screen dump by running
fbgrab screendump.png




22. Enable java in chrome
Java has always been tricky. Sometimes icedtea-plugin has worked, sometimes it hasn't. At the moment it works:
sudo apt-get install icedtea-plugin

update-alternatives: using /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws to provide /usr/bin/javaws (javaws) in auto mode.update-alternatives: using /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/itweb-settings to provide /usr/bin/itweb-settings (itweb-settings) in auto mode.
Not sure about the java-6-openjdk-amd64 since I actually have openjdk-7 installed and not 6. Try installing openjdk7-7-jdk first.


i A openjdk-6-jre                   - OpenJDK Java runtime, using Hotspot JIT   
i A openjdk-6-jre-headless          - OpenJDK Java runtime, using Hotspot JIT (h
i A openjdk-6-jre-lib               - OpenJDK Java runtime (architecture indepen
i   openjdk-7-jdk                   - OpenJDK Development Kit (JDK)             
i   openjdk-7-jre                   - OpenJDK Java runtime, using Hotspot JIT   
i A openjdk-7-jre-headless          - OpenJDK Java runtime, using Hotspot JIT (h
i A openjdk-7-jre-lib               - OpenJDK Java runtime (architecture indepent

23. Changing element colour in gdis
GDIS is, in my opinion, the best linux program for generating povray files from crystallographic data. Mainly this is due to the number of different representations which can be selected: from ball-and-stick to polyhedral to surface -- and it allows mixing different representations in  the same molecule, which is what sets it apart.

Long story short, in order to change the default element colours you have to manually edit /usr/share/gdis/gdis.elements

Each element is contained between a %gdis_elemen and and a %gdis_end tag. The colour is given in RGB code ranging from 0 to 65k. To look up RGB codes, look e.g. here http://www.tayloredmktg.com/rgb/.

%gdis_elem
symbol: Na
  name: Sodium
number: 11
weight: 22.989799
  cova: 0.970000
   vdw: 1.450000
charge: 1.000000
colour: 30000 52600 60600
%gdis_end
You can also change the covalent and van der Waal radii here -- these are used to determine bonding  so if you have too many or not enough bonds in the molecule, you can fiddle with this.

As an aside, I'm having problems in general with converting .tga and .png to good-looking eps. This is the best I've got so far and uses inkscape. Convert and GIMP don't yield results which are as good.

povray +W400 +H400 $1.pov +A
inkscape --verb FileSave --verb FileClose --export-eps=$1.eps $1.png 

Odd though that povray can't directly output vector-based image formats.
Edit: Here are the technical reasons why we're stuck with bitmap formats: http://news.povray.org/povray.pov4.discussion.general/message/%3C4a79fd58%241%40news.povray.org%3E/#%3C4a79fd58%241%40news.povray.org%3E

24. CCSD mercury /lib/libc.so.6

Mercury is a program for displaying crystal structures from the CCSD.
./mercury 
Using native OpenGL
Warning: mercury requires /lib/libc.so.6 but not found

sudo ln -s /lib/x86_64-linux-gnu/libc.so.6 /lib/libc.so.6
ls /lib/libc.so.6 -lah
/lib/libc.so.6 -> /lib/x86_64-linux-gnu/libc.so.6
./mercury 
Using native OpenGL
INFO: The environment variable CSDHOME is not set.
You can set CSDHOME by including
export CSDHOME=/home/me/mercury
(use the correct path)
in your ~/.bashrc

25. Daemons...rcconf and update-rc.d
You can easily enable and disable services to load on boot by using rcconf, which is an curses type tool.

Or use sysv-rc-conf:


Alternative, use update-rc.d which doesn't faff around with any gui.
Usage is described here.
To remove a daemon:
update-rc.d -f apt-cacher-ng remove
To add a daemon:
update-rc.d apt-cacher-ng defaults

If you're more adventurous:
update-rc.d apt-cacher-ng start 20 2 3 4 5 . stop 20 0 1 6 .

where 20 is a two-digit seq code used by init to decide which order to run the script in, and numbers between 1 and 9 and S are the run levels. More information in /etc/inittab

Here: "Default Debian installation does not make any difference between runlevels 2-5. You may customize them to your liking. Runlevels S (single) and 1 are used for maintenance. They start services minimally to avoid possible problems." 0 is halt and 6 is reboot.



26. Adjusting your webcam
I've had problems with webcam images being overly dark -- trying to adjust the image with cheese leads to nothing.

v4l2ucp, which is in the debian repos, however, is a good GUI-based configuration tool which allows you to adjust most things, including, importantly, light sensitivity rather than just brightness.
v4l2ucp on a much-too-small screen
27. Command line burning of iso
sudo apt-get install burn
sudo burn -I -n debian.iso
Simple as that.

For burning audio cds from mp3 files I use a slightly different approach:

sudo apt-get install brasero-cdrkit mpg123
for i in *.mp3; do mpg123 --rate 44100 --stereo --buffer 3072 --resync -w "`basename "$i" .mp3`".wav "$i"; done
Then name the files in a way that they are listed in desired play order.

ls /dev/cdr
cdrom1  cdrw1
 wodim -v -pad speed=1 dev=/dev/cdrw1 -dao -swab *.wav

burns.

28. Finding a file in a package
Two methods:
dpkg --search libglib
apt-file search libglib
(apt-file update before first use)

29. USB support in virtualbox
If you keep getting errors along the lines of:
Failed to access the USB subsystem
and
NS_ERROR_FAILURE
in virtualbox when trying to enable USB devices, make sure that you've added yourself to the vboxusers group in /etc/group. You'll need to reinit before it takes effect (e.g. by rebooting)

30. Startup applications in gnome 3.4
In the past I've always used gnome-session-properties, but it's a hit and miss affair at the moment. So it would be nice with an alternative approach.

According to this: http://ubuntuforums.org/showthread.php?t=1992296
anything which is found in /etc/xdg/autostart will be automatically executed, e.g.

cat /etc/xdg/autostart/guake.desktop 
[Desktop Entry]
Name=Guake Terminal
Name[pt]=Guake Terminal
Name[pt_BR]=Guake Terminal
Comment=Use the command line in a Quake-like terminal
Comment[pt]=Utilizar a linha de comando em um terminal estilo Quake
Comment[pt_BR]=Utilizar a linha de comando em um terminal estilo Quake
TryExec=guake
Exec=guake
Icon=/usr/share/pixmaps/guake/guake.png
Type=Application
Categories=GNOME;GTK;Utility;TerminalEmulator;
StartupNotify=true
X-GNOME-Autostart-enabled=false
Also, it's been suggested that there's a bug in guake: http://motorscript.com/guake-patch-to-fix-focus-on-gnome/
Guake starts well for me on my laptop, but not on my nvidia boxes.

31. Changing pulseaudio volume from the command line
Copy this script (https://gist.github.com/814634) and make executable. Requires ruby.
Invoke using the arguments up, down, toggle.

24 January 2012

56. Gromacs -- setting up and running energy minimisation of methanol in water. Using itp files

* First browse through this tutorial.
* I'm not an expert at GROMACS -- I'm writing this up as I am learning myself. Use what I show here as a starting point for your own explorations. Don't treat it like a scientifically complete piece of work.

1. Building the .gro
Draw a methanol molecule in e.g. Avogadro (available in the debian repos) and save as .xyz.
6

C         -1.60284       -0.81294        0.00066
O         -0.18719       -0.81849       -0.00206
H         -1.97028       -1.66300        0.58111
H         -1.97029       -0.87387       -1.02686
H         -1.95386        0.11552        0.45631
H          0.09473       -1.65393       -0.41207
You should edit the file to give the atoms unique names -- keep them short though, as each string field is limited to 5 chars in the .gro file. You will refer to these names later in your metahnol.itp file.

Here's my new methanol.xyz:
6
meth
COH         -1.60284       -0.81294        0.00066
OHC         -0.18719       -0.81849       -0.00206
HC1         -1.97028       -1.66300        0.58111
HC2         -1.97029       -0.87387       -1.02686
HC3         -1.95386        0.11552        0.45631
HO          0.09473       -1.65393       -0.41207
Next we convert it to a .gro file and create a 2.5 nm x 2.5 nm x 2.5 nm box around it. 

editconf -f methanol.xyz -o methanol.gro -box 2.5 2.5 2.5 

methanol.gro:

meth
    6
    1 ???   COH    1   1.216   1.264   1.257
    1 ???   OHC    2   1.358   1.263   1.257
    1 ???   HC1    3   1.179   1.179   1.315
    1 ???   HC2    4   1.179   1.258   1.154
    1 ???   HC3    5   1.181   1.357   1.302
    1 ???    HO    6   1.386   1.180   1.216
   2.50000   2.50000   2.50000

2. Building the .top
We're going to make it a bit easier and more modular for ourselves by using the #include directive and by (re)using .itp files -- this way we can pull instructions and data from stock files.

step1.top:
[defaults]
1   1   yes   1.0   1.0

#include "atomtypes.itp"
#include "methanol.itp"
#include "water.itp"

[system]
wood liquor

[molecules]
meth   1
SOL   1
It now remains for us to define the molecule meth in methanol.itp, SOL in water.itp and define the proper atomtypes in atomtypes.itp.

3. Building the methanol.itp

First create a .gzmat file from the .xyz using openbabel


babel methanol.xyz methanol.gzmat

methanol.gzmat:


#Put Keywords Here, check Charge and Multiplicity.
 meth
0  1
Xx
Xx  1  r2
Xx  1  r3  2  a3
Xx  1  r4  2  a4  3  d4
Xx  1  r5  2  a5  3  d5
Ho  2  r6  1  a6  3  d6
Variables:
r2= 1.4157
r3= 1.0929
a3= 109.52
r4= 1.0929
a4= 109.52
d4= 239.22
r5= 1.0922
a5= 109.00
d5= 119.61
r6= 0.9724
a6= 107.10
d6=  60.39


The zmat format gives an easy overview over bond-lengths and angles, which is what I use it for. For something as small as methanol you don't really need a zmat file, but it can come in handy for large molecules. We'll also include #ifndef, #else and #endif -- this way we have an easy way of switching between using constraints and not doing so. ifndef checks to see whether FLEXIBLE is defined or not (ifndef=If Not Defined).

Remember that the atom order in methanol.itp should be the same as in the .gro file.

The partial charges are addressed under atomtypes. Be aware that while gzmat outputs bond lengths in  Ångström you should use nanometres in your .itp file or things will get weird.

methanol.itp:


;;;;;;;;;;;;;;;;;;
; Methanol
;;;;;;;;;;;;;;;;;;
[ moleculetype ]
meth    3
[atoms]
;nr type    resnr   res atom    cgnr    chrg    mass
1   COH 1   meth    COH   1   0.1450   12.011
2   OHC 1   meth    OHC   1   -0.683   15.9994
3   HC  1   meth    HC1   1   0.0400   1.00079
4   HC  1   meth    HC2   1   0.0400   1.00079
5   HC  1   meth    HC3   1   0.0400   1.00079
6   HO  1   meth    HO   1   0.4180   1.00079
#ifndef FLEXIBLE
[constraints]
;ai aj  f   nm
3   1   1   0.110929  ; H-C
4   1   1   0.110929  ; H-C
5   1   1   0.110929  ; H-C
1   2   1   0.14157  ; C-O
6   2   1   0.09724  ; H-O
[exclusions]
1   2   3   4   5   6
2   1   3   4   5   6
3   1   2   4   5   6
4   1   2   3   5   6
5   1   2   3   4   6
6   1   2   3   4   5
#else
[bonds]
;ai aj  f   nm  kb
3   1   1   0.110929  10  ; H-C, r3
4   1   1   0.110929  10  ; H-C, r4
5   1   1   0.110929  10  ; H-C, r5
2   1   1   0.14157  100  ; C-O, r2
6   2   1   0.09724  1  ; H-O, r6
;[ pairs ]
; i j   funct
;2   6
;3   6
;4   6
[angles]
;ai aj ak   f   angle   k_a
3   1   2   1   109.52  500   ; H-C-O a3
4   1   2   1   109.52  500   ; H-C-O a4
5   1   2   1   109.52  500   ; H-C-O a5
6   2   1   1   107.10  500   ; H-O-C a6
3   1   4   1   120.00  500
4   1   5   1   120.00  500
3   1   5   1   120.00  500

[dihedrals];proper - f=1
6   2   1   3   1   60   300    2    ;H(O)-O-C-H(C) d6
;6   2   1   4   1      
;6   2   1   5   1
[dihedrals];improper - f=2
4   1   2   3   2   239.22  300    ;H-C-O-H(C) d4
5   1   2   3   2   119.61  300    ;H-C-O-H(C) d5
#endif



3. Building the water.itp
The partial charges are addressed under atomtypes, but this is essentially a copy of the (/usr/local/gromacs/share/gromacs/)top/oplsaa.ff/spce.itp file.

water.itp:
[moleculetype]
sol 2
[atoms]
;nr type resnr res atom cgnr charge mass
1   OW  1   SOL OW  1   -0.8476 15.9994
2   HW  1   SOL HW1 1   0.4238  1.00079
3   HW  1   SOL HW2 1   0.4238  1.00079


#ifndef FLEXIBLE
[settles]
;OW fun doh dhh
1   1   0.1 0.16330
[exclusions]
1   2   3
2   1   3
3   1   2
#else
[bonds]
;i  j   f   l(nm)  kb
1   2   1   0.1 34.5e3
1   3   1   0.1 34.5e3
[angles]
;ai aj ak f angle k_a
2   1   3   1   109.47  383
#endif

4. Building the atomtypes.itp
This is the tricky bit -- you need to pick the correct parameters for your atoms, and as they are empirical it is difficult to know what is 'right'.

A quick way of getting decent starting values is to
cat /usr/local/gromacs/share/gromacs/top/oplsaa.ff/ffnonbonded.itp

and look through the OPLS-AA for different atoms.

e.g.

cat /usr/local/gromacs/share/gromacs/top/oplsaa.ff/ffnonbonded.itp | grep OH

gives 
; name  bond_type    mass    charge   ptype          sigma      epsilon
 opls_023   OH 8      15.99940    -0.700       A    3.07000e-01  7.11280e-01 ; SIG

 opls_078   OH 8     15.99940    -0.700       A    3.07000e-01  7.11280e-01 ; SIG
 opls_154   OH  8     15.99940    -0.683       A    3.12000e-01  7.11280e-01
 opls_162   OH  8     15.99940    -0.635       A    3.07000e-01  7.11280e-01
 opls_167   OH   8  15.99940    -0.585       A    3.07000e-01  7.11280e-01
 opls_169   OH  8   15.99940    -0.700       A    3.07000e-01  7.11280e-01
 opls_171   OH  8   15.99940    -0.730       A    3.07000e-01  7.11280e-01
 opls_187   OH   8  15.99940    -0.700       A    3.07000e-01  7.11280e-01
 opls_268   OH   8  15.99940    -0.530       A    3.00000e-01  7.11280e-01
 opls_420   OH   8  15.99940    -0.980       A    3.15000e-01  1.04600e+00
 opls_434   OH   8  15.99940    -1.300       A    3.20000e-01  1.04600e+00

For most definitions sigma=3.07000e-01 and epsilon=7.11280e-01, so we'll use that. However, we want to use c6 and c12 notation, where c6=4*epsilon*sigma^6 and c12=4*epsilon*sigma^12.

An alternative is to look through the literature for suitable values.

An advantage with making an atomtypes.itp file yourself is that you can slowly expand it between experiments.

Here's my atomtypes.itp:
[atomtypes]
;atom no mass charge ptype c6 c12
;water
OW  8   15.9994 -0.8476 A   0.261710e-02    0.26331e-5
HW  1   1.00079 0.42380 A   0.000000e-02    0.00000e-5
;methanol
; Methanol, Jorgensen et al. JACS 118 pp. 11225 (1996)
;opls-aa/ffnonbonded.itp
COH 6     12.01100     0.145       A    0.20305e-2  0.37326e-5      ;s/e 3.50000e-01  2.76144e-01
OHC 8     15.99940    -0.683       A    0.26244e-2  0.24208e-5      ;s/e 3.12000e-01  7.11280e-01
HC  1      1.00800     0.040       A    0.012258e-2 0.0029926e-5    ;s/e 2.50000e-01  1.25520e-01
HO  1      1.00800     0.418       A    0.00000000  0.000000000     ;s/e 0.00000e+00  0.00000e+00
;CO2
OC  8   15.9994 -0.35   A   2.5438e-1   2.0478e-4
CO  6   12.0107 0.700   A   5.2044e-2   2.5080e-5
;CO3
OCO2    8   15.9994 -1.0450 A   0.261710e-2 0.26331e-05
CO3     6   12.0107 1.13500  A   0.234020e-2 0.33740e-05



5. Our em.mdp
This is from one of Justin Lemkul's tutorials


; Parameters describing what to do, when to stop and what to save
define = -DFLEXIBLE ; relaxes constraints in the .itp files
integrator = steep ; Algorithm (steep = steepest descent minimization)
emtol = 1000.0   ; Stop minimization when the maximum force < 1000.0 kJ/mol/nm
emstep          = 0.01          ; Energy step size
nsteps = 50000   ; Maximum number of (minimization) steps to perform
; Parameters describing how to find the neighbors of each atom and how to calculate the interactions
nstlist = 1 ; Frequency to update the neighbor list and long range forces
ns_type = grid ; Method to determine neighbor list (simple, grid)
rlist = 1.2 ; Cut-off for making neighbor list (short range forces)
coulombtype = PME ; Treatment of long range electrostatic interactions
rcoulomb = 1.2 ; Short-range electrostatic cut-off
rvdw = 1.2 ; Short-range Van der Waals cut-off
pbc = xyz ; Periodic Boundary Conditions (yes/no)

6. Energy minimisation
I'll keep it brief:

Add water
genbox_dd  -cp methanol.gro -cs /usr/local/gromacs/share/gromacs/top/spc216.gro -o step1.gro -p step1.top 

Prepare mdrun input
grompp_dd -f em.mdp -po step2.mdp -c step1.gro -p step1.top -pp step2.top -o step2.tpr 

Do energy minimsation
mdrun_dd -v -s step2.tpr -o step3.trr -x step3.xtc -c step3.gro -e step3.edr -g step3.log


Using a run.sh

I get tired of typing the same thing over and over - especially when troubleshooting

Create a run.sh file and call it with sh run.sh every time
editconf_dd -f methanol.xyz -o methanol.gro -box 2.5 2.5 2.5
genbox_dd  -cp methanol.gro -cs /usr/local/gromacs/share/gromacs/top/spc216.gro -o step1.gro -p step1.top
grompp_dd -f em.mdp -po step2.mdp -c step1.gro -p step1.top -pp step2.top -o step2.tpr
mdrun_dd -v -s step2.tpr -o step3.trr -x step3.xtc -c step3.gro -e step3.edr -g step3.log

7. Equilibration and production runs
See previous tutorial for mdp files.

I know it's a bit of a cop-out, but no time to make a more detailed tutorial right now.

20 January 2012

55. Building/compiling OpenMM4.0 from source on debian testing

Pre-requisites:
sudo apt-get install swig doxygen openjdk-7-jdk

Also, patience...the build can be temperamental. However, go through the steps enough times and it will work. Why, I don't know.

Also:
1. download (see error 4 below) py-dom-xpath-0.1 from here:
https://code.google.com/p/py-dom-xpath/downloads/list

sudo apt-get install python-setuptools
wget https://py-dom-xpath.googlecode.com/files/py-dom-xpath-0.1.tar.gz


2. Unzip it
3. Change to the directory py-dom-xpath-0.1/ and run
sudo python setup.py install

And
add this to your ~/.bashrc or /etc/profile

export LD_LIBRARY_PATH=/lib/openmm:/usr/lib/nvidia-cuda-toolkit:/usr/lib/nvidia:$LD_LIBRARY_PATH
export OPENMM_PLUGIN_DIR=/usr/local/openmm/lib/plugins
export OPENMM_ROOT_DIR=/usr/local/openmm
Finally (and this is truly ridiculous):

mkdir ~/tmp/OpenMM4.0-Source/docs/UsersGuide
cp OpenMM4.0-Source/docs/OpenMMUsersGuide.pdf OpenMM4.0-Source/docs/UsersGuide/


Start here:

As usual we'll do our work in ~/tmp
so
mkdir ~/tmp 
if that directory doesn't exist

To download the OpenMM4.0-Source.zip file you need to register at simtk.org

Put the file in ~/tmp

Run:
cd ~/tmp
unzip OpenMM4.0-Source.zip
cd OpenMM4.0-Source/
cmake CMakeList.txt
make OpenMM
sudo make install

If all goes well (it took me three hours to iron out the details...) you'll see
[..]
-- Installing: /usr/local/openmm/include/openmm/internal/AmoebaUreyBradleyForceImpl.h
-- Installing: /usr/local/openmm/include/openmm/internal/AmoebaTorsionTorsionForceImpl.h
-- Installing: /usr/local/openmm/include/openmm/internal/AmoebaStretchBendForceImpl.h
-- Installing: /usr/local/openmm/lib/libOpenMMAmoeba.so
-- Removed runtime path from "/usr/local/openmm/lib/libOpenMMAmoeba.so"
-- Installing: /usr/local/openmm/lib/plugins/libOpenMMAmoebaCuda.so
-- Removed runtime path from "/usr/local/openmm/lib/plugins/libOpenMMAmoebaCuda.so"
-- Installing: /usr/local/openmm/lib/plugins/libOpenMMAmoebaSerialization.so
-- Removed runtime path from "/usr/local/openmm/lib/plugins/libOpenMMAmoebaSerialization.so"
-- Installing: /usr/local/openmm/include/openmm/RPMDIntegrator.h
-- Installing: /usr/local/openmm/include/openmm/RpmdKernels.h
-- Installing: /usr/local/openmm/lib/libOpenMMRPMD.so
-- Removed runtime path from "/usr/local/openmm/lib/libOpenMMRPMD.so"
-- Installing: /usr/local/openmm/lib/plugins/libOpenMMRPMDOpenCL.so
-- Removed runtime path from "/usr/local/openmm/lib/plugins/libOpenMMRPMDOpenCL.so"
-- Installing: /usr/local/openmm/include/openmm/serialization/SerializationNode.h
-- Installing: /usr/local/openmm/include/openmm/serialization/SerializationProxy.h
-- Installing: /usr/local/openmm/include/openmm/serialization/XmlSerializer.h
-- Installing: /usr/local/openmm/lib/libOpenMMSerialization.so
-- Removed runtime path from "/usr/local/openmm/lib/libOpenMMSerialization.so"


And you're are done! SUCCESS!



Errors and solutions:
I hate cmake, possibly because I don't really understand it.
Anyway, every time you hit one of the errors below you need to do the following after fixing it:
make clean
cmake CMakeList.txt
make OpenMM
or you'll get error # 6

1. Doxygen missing:

Symptom:
Swig version must be 1.3.39 or greater! (You have 0.0.0)
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:91 (MESSAGE):
  Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
Call Stack (most recent call first):
  /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:252 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-2.8/Modules/FindDoxygen.cmake:80 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  wrappers/python/CMakeLists.txt:82 (find_package)
Solution:
sudo apt-get install doxygen

2. Swig missing:
Symptom:
Swig version must be 1.3.39 or greater! (You have 0.0.0)
-- Java version 1.6.0.24 configured successfully!
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:91 (MESSAGE):
  Could NOT find Java (missing: Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE)
  (found version "1.6.0.24")
Call Stack (most recent call first):
  /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:252 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-2.8/Modules/FindJava.cmake:174 (find_package_handle_standard_args)
  wrappers/python/CMakeLists.txt:85 (find_package)
Solution:
sudo apt-get install swig

3. Java found and missing at the same time
Symptom:
-- Java version 1.6.0.24 configured successfully!
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:91 (MESSAGE):
  Could NOT find Java (missing: Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE)
  (found version "1.6.0.24")
Call Stack (most recent call first):
  /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:252 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-2.8/Modules/FindJava.cmake:174 (find_package_handle_standard_args)
  wrappers/python/CMakeLists.txt:85 (find_package)
Solution:
sudo apt-get install openjdk-7-jdk

4. No module named xpath
Symptom:
Execution time: 1072 milliseconds
Memory used: 21270968
NamePool contents: 89 entries in 86 chains. 6 prefixes, 6 URIs
[ 87%] Creating OpenMM Python swig input files...
Traceback (most recent call last):
  File "/home/me/tmp/OpenMM4.0-Source/python/src/swig_doxygen/swigInputBuilder.py", line 15, in <module>
    import xpath
ImportError: No module named xpath
make[2]: *** [python/src/swig_doxygen/swig_lib/python/pythonprepend.i] Error 1
make[1]: *** [wrappers/python/CMakeFiles/BuildModule.dir/all] Error 2
make: *** [all] Error 2
Solution:
Download py-dom-xpath-0.1.tar.gz:

wget https://py-dom-xpath.googlecode.com/files/py-dom-xpath-0.1.tar.gz

Untar (tar -xvf) in ~/tmp
cd py-dom-xpath-0.1/
sudo python setup.py install

What didn't work:
sudo apt-get install libxml-xpath-perl
sudo apt-get install libghc-hxt-xpath-dev

5. Missing OpenMMUsersGuide.pdf
Symptom:
-- Installing: /usr/local/openmm/docs/API Reference.html
CMake Error at cmake_install.cmake:119 (FILE):
  file INSTALL cannot find
  "/home/me/tmp/OpenMM4.0-Source/docs/UsersGuide/OpenMMUsersGuide.pdf".

make: *** [install] Error 1

Solution:
WTF??? The build can fail over something so trivial???
Anyway,
mkdir ~/tmp/OpenMM4.0-Source/docs/UsersGuide
cp ~/tmp/OpenMM4.0-Source/docs/OpenMMUsersGuide.pdf ~/tmp/OpenMM4.0-Source/docs/UsersGuide/

6. Linking CXX shared library libOpenMM.so failure
Symptom:
[  6%] Building CXX object CMakeFiles/OpenMM.dir/src/cuda/kCalculateLocalForces.cu_OpenMMCuda_generated.cpp.o
Linking CXX shared library libOpenMM.so
CMakeFiles/OpenMM.dir/src/cuda/kCalculateCDLJForces.cu_OpenMMCuda_generated.cpp.o: In function `__device_stub__Z29kFindBlockBoundsCutoff_kernelv()':
kCalculateCDLJForces.cu_OpenMMCuda_generated.cpp:(.text+0x200): multiple definition of `__device_stub__Z29kFindBlockBoundsCutoff_kernelv()'
CMakeFiles/OpenMM.dir/src/cuda/kCalculateNonbondedSoftcore.cu_OpenMMFreeEnergyCuda_generated.cpp.o:kCalculateNonbondedSoftcore.cu_OpenMMFreeEnergyCuda_generated.cpp:(.text+0x1b0): first defined here
[..]
CMakeFiles/OpenMM.dir/src/cuda/kCalculateAmoebaCudaUtilities.cu_OpenMMAmoebaCuda_generated.cpp.o: In function `kFindInteractionsWithinBlocksPeriodic_kernel(unsigned int*)':
kCalculateAmoebaCudaUtilities.cu_OpenMMAmoebaCuda_generated.cpp:(.text+0x1d0): multiple definition of `kFindInteractionsWithinBlocksPeriodic_kernel(unsigned int*)'
CMakeFiles/OpenMM.dir/src/cuda/kCalculateNonbondedSoftcore.cu_OpenMMFreeEnergyCuda_generated.cpp.o:kCalculateNonbondedSoftcore.cu_OpenMMFreeEnergyCuda_generated.cpp:(.text+0x3a0): first defined here
collect2: ld returned 1 exit status
make[2]: *** [libOpenMM.so] Error 1
make[1]: *** [CMakeFiles/OpenMM.dir/all] Error 2
make: *** [all] Error 2

Solution:
You had one of errors 1-5, you solved it and tried to run make again. You need to do

make clean
cmake CMakeList.txt

first before proceeding with make or you end up with this error.


54. Compiling GROMACS with GPU support using OpenMM (OpenMM 4.0 source or 3.1.1 Linux 64 binaries) on debian testing

To compile gromacs without GPU support (and that's probably what you should do) look here:
http://verahill.blogspot.com.au/2012/05/gromacs-with-external-fftw3-and-blas-on.html
GPU support is most likely NOT going to be useful for you.

For a better way (out-of-tree) of building a newer openMM, see:
http://verahill.blogspot.com.au/2012/06/compiling-openmm-41-on-debian-testing.html

The method below describes an in-tree build of OpenMM. Do an out of tree build (e.g. see link above) to avoid headaches.

OK, enough with the 'bold'. Basically, I wrote the post below at a time when I was at a very early stage of learning how to compile my own programs. I'm obviously still learning, but I have published better methods now -- see the links above for those.
Be aware that in-tree (when you build your package in the root of the source tree) building is not supported for OpenMM and you will probably be told so if posting on forums asking for help. Out-of-tree (when you build in a directory outside the source tree structure) is supported and is described above. So, while I'm leaving this post here for posterity, use it as inspiration, but don't follow it blindly.

/25th of September 2012.


Original Post:
First read this: 1. Use EITHER the OpenMM3.1.1-Linux64 binaries
 2. OR, which is better, compile OpenMM4.0 from source -- see here http://verahill.blogspot.com/2012/01/debian-testing-64-wheezy_20.html -- if you do this you can skip step 3.

Do NOT use: 1. the Open4.0MM-Linux64 binaries or the OpenMM3.1.1-Source source -- at least I have had issues with those versions.



The following guide was last tested: 20/01/2012
It has not been checked for typos -- whenever you use a command with 'sudo' in it, try to understand what it does first.

Finally: if it doesn't work the first time, try a few more times. I've never managed to build on the first try, but restarting with make clean, cmake CMakeList.txt, make works in the end every time. Sigh...

You may also want to remove CMakCache.txt in the source root.

1. Things to install first

Install cmake and autoconf if you haven't already

sudo apt-get install cmake autoconf

2. edit ~/.bashrc  or /etc/profiles
Put this at the end of your ~/.bashrc  (or /etc/profiles for multi-user systems)

export LD_LIBRARY_PATH=/lib/openmm:/usr/lib/nvidia-cuda-toolkit:/usr/lib/nvidia:$LD_LIBRARY_PATH
export OPENMM_PLUGIN_DIR=/usr/local/openmm/lib/plugins
export OPENMM_ROOT_DIR=/usr/local/openmm 

load its content by
source ~/.bashrc

3. OpenMM
To download OpenMM you need to register with simtk.org. Registering is all thing considered fairly easy and quick.

Either follow this guide for compiling OpenMM4.0 from source (preferred) or follow the steps below to use the 3.1.1 binaries:

Download the OpenMM3.1.1-Linux64.zip file (if applicable).

Put the .zip file in ~/tmp

unzip OpenMM3.1.1-Linux64.zip
cd ~/tmp/OpenMM3.1.1-Linux64.zip

sudo mkdir -p /lib/openmm/plugins
sudo mkdir -p /lib/openmm/include

sudo cp lib/*.so /lib/openmm
sudo cp include/* -R /lib/openmm/include
sudo cp plugins/* -R /lib/openmm/plugins

This is the structure you're aiming for:

/lib/openmm
|-- include
|   |-- internal
|   |-- openmm
|   `-- serialization
`-- plugins


Next:

sudo mkdir /usr/local/openmm
sudo cp ~/tmp/OpenMM3.1.1/* -R /usr/local/openmm


So that you end up with

/usr/local/openmm
|-- bin
|-- docs
|   `-- api
|       `-- search
|-- include
|   `-- openmm
|       |-- internal
|       `-- serialization
|-- lib
|   `-- plugins
|-- licenses
`-- python
    |-- simtk
    |   |-- openmm
    |   `-- unit
    `-- src
        `-- swig_doxygen
            |-- doxygen
            `-- swig_lib
                `-- python
4. Gromacs-4.5.5
Get and untar gromacs:
cd ~/tmp
wget ftp://ftp.gromacs.org/pub/gromacs/gromacs-4.5.5.tar.gz
tar -xvf gromacs-4.5.5.tar.gz
mv gromacs-4.5.5/ gromacs_gpu/

Let's start preparing our build:
cd gromacs_gpu/
make clean
autoconf 
export OPENMM_ROOT_DIR=/usr/local/openmm
cmake CMakeList.txt -DGMX_OPENMM=ON -DGMX_THREADS=OFF

EDIT/COMMENT:  I think autoconf /automake and cmake are mutually exclusive. I only let autoconf stay here since I did invoke it when I did my build.

The output of a successful run of cmake follows below -- note the binary suffix, as well as the Found CUDA and Found OpenMM.

-- Using default binary suffix: "-gpu"
-- Using default library suffix: "_gpu"
-- No external FFT libraries needed for the OpenMM build, switching to fftpack!
-- Switching off CPU-based acceleration, the OpenMM build does not support/need any!
-- Found CUDA: /usr (Required is at least version "3.1")
-- Found OpenMM: /usr/local/openmm
-- Looking for fseeko
-- Looking for fseeko - found
-- Using internal FFT library - fftpack
-- Configuring done
-- Generating done
-- Build files have been written to: /home/me/tmp/gromacs_mopac



Next, some editing - first we copy two of the files that the DGMX_OPENMM switch on the cmake command above created, then we remove two offending lines.

This command should be on a single line:
cp gromacs_gpu/src/kernel/gmx_gpu_utils/CMakeFiles/gmx_gpu_utils_generated_gmx_gpu_utils.cu.o.cmake ~/tmp

This command is also a single line:
cp gromacs_gpu/src/kernel/gmx_gpu_utils/CMakeFiles/gmx_gpu_utils_generated_memtestG80_core.cu.o.cmake ~/tmp


We now have two *.cu.o files in our ~/tmp
Open each one and remove all instances of -fexcess-precision=fast in them. Then copy the files back to their original location:

(This command should be on a single line:)
cp gmx_gpu_utils_generated_gmx_gpu_utils.cu.o.cmake gromacs_gpu/src/kernel/gmx_gpu_utils/CMakeFiles/

(This command is also a single line:)
cp gmx_gpu_utils_generated_memtestG80_core.cu.o.cmake gromacs_gpu/src/kernel/gmx_gpu_utils/CMakeFiles/

We cope and edit since these files get regenerated every time you do the cmake -DGMX_OPENMM=ON command.
----------------------------------------------------------------------------------------------------------
Quick aside: a clue to  -fexcess-precision:
Here: "On x86 targets, code containing floating-point calculations may run significantly slower when compiled with GCC 4.5 in strict C99 conformance mode than they did with earlier GCC versions. This is due to stricter standard conformance of the compiler and can be avoided by using the option -fexcess-precision=fast." * Here: "-fexcess-precision=fast # disables the GCC 4.5 strict floating point C99 standards conformance for improved floating point performance "* I'm running gcc (Debian) 4.6.2-12 and g++ 4.6.2-4* I've tried with both -fexcess-precision=fast and -fexcess-precision=standard. Neither works.
* Not all excess-precision options work with all languages.
* Using g++ 4.5 someone got "cc1plus: sorry, unimplemented: -fexcess-precision=standard for C++" and comes to the conclusion that "Bah. Still, at least the -ffloat-store workaround still helps, for this
case at any rate. Also, if you get GCC to use SSE instructions, there's no
issue with excess precision".
I think the conclusion is that removing -fexcess-precision=fast MAY lead to a speed penalty (up to 2x) but will not change the results of the sim/calc.
----------------------------------------------------------------------------------------------------------
OK, time to build!
cd gromacs_gpu/
make 

and then install:
sudo make install

If all went well you'll now have mdrun-gpu in your /usr/local/gromacs/bin folder together with 93 other -gpu bin files!


Files for benchmarking can be downloaded from here: http://www.gromacs.org/@api/deki/files/128/=gromacs-gpubench-dhfr.tar.gz

If you get:

Program mdrun-gpu, VERSION 4.5.5
Source code file: /home/me/tmp/gromacs_gpu/src/kernel/openmm_wrapper.cpp, line: 1324
Fatal error:
The selected GPU (#0, GeForce GT 430) is not supported by Gromacs! Most probably you have a low-end GPU which would not perform well, or new hardware that has not been tested with the current release. If you still want to try using the device, use the force-device=yes option.
For more information and tips for troubleshooting, please check the GROMACS
website at http://www.gromacs.org/Documentation/Errors

when trying to benchmark, use

mdrun-gpu -device "OpenMM:deviceid=0, force-device=yes" -v

to force execution.

Make sure to monitor your GPU temperature -- it will easily reach 80 degrees for a fan-less video card.

Early 'results':
Test                             GPU: GT 430    GT520      CPU (6 core AMD Phenom II, 2.8 GHz)
dhfr-impl-1nm.bench           31.8          19.5            27.2 ns/day
dhfr-impl-2nm.bench           31.9          19.9            5.8 ns/day
dhfr-solv-PME.bench           2.7             1.7             8.6 ns/day


Two significant problems are present:
1. The card heats up quickly to 80 degrees Celsius. It may thus be throttled.
2. The video card is in use by GNOME at the same time. Will rerun later without x.

The difference in speed for the 2nm text is significant.



5. Optional
If you haven't already, add this to ~/.bashrc (or /etc/profile)
PATH=$PATH:/usr/local/gromacs/bin

then run
source ~/.bashrc
to load the new settings


Addendum: Errors and solutions
Do a fresh cycle of make clean, cmake, make and make install after each fix. Also, remove CMakeCache.txt

1. Missing libxml2-dev

Symptom:
[ 89%] Building C object src/mdlib/CMakeFiles/md.dir/gmx_qhop_xml.c.o
/home/me/tmp/gromacs_gpu/src/mdlib/gmx_qhop_xml.c:48:27: fatal error: libxml/parser.h: No such file or directory
compilation terminated.
make[3]: *** [src/mdlib/CMakeFiles/md.dir/gmx_qhop_xml.c.o] Error 1
make[2]: *** [src/mdlib/CMakeFiles/md.dir/all] Error 2
make[1]: *** [src/kernel/CMakeFiles/mdrun.dir/rule] Error 2
make: *** [mdrun] Error 2

Solution:
sudo apt-get install libxml2-dev

2. Missing OpenMM.h
Symptom:
Linking C shared library libgmxpreprocess_gpu.so
[ 98%] Built target gmxpreprocess
Scanning dependencies of target openmm_api_wrapper
[ 98%] Building CXX object src/kernel/CMakeFiles/openmm_api_wrapper.dir/openmm_wrapper.cpp.o
/home/me/tmp/gromacs_gpu/src/kernel/openmm_wrapper.cpp:59:20: fatal error: OpenMM.h: No such file or directory
compilation terminated.
make[3]: *** [src/kernel/CMakeFiles/openmm_api_wrapper.dir/openmm_wrapper.cpp.o] Error 1
make[2]: *** [src/kernel/CMakeFiles/openmm_api_wrapper.dir/all] Error 2
make[1]: *** [src/kernel/CMakeFiles/mdrun.dir/rule] Error 2
make: *** [mdrun] Error 2

Solution:
 sudo mkdir /usr/local/openmm/lib/include
sudo cp ~/tmp/OpenMM3.1.1-Source/openmmapi/include/* -R /usr/local/openmm/include/

3. Missing Kernel.h
Symptom:
Linking CXX static library libgmx_gpu_utils.a
[  0%] Built target gmx_gpu_utils
[  0%] Building CXX object src/kernel/CMakeFiles/openmm_api_wrapper.dir/openmm_wrapper.cpp.o
In file included from /usr/local/openmm/include/OpenMM.h:36:0,
                 from /home/me/tmp/gromacs_gpu/src/kernel/openmm_wrapper.cpp:59:
/usr/local/openmm/include/openmm/BrownianIntegrator.h:36:27: fatal error: openmm/Kernel.h: No such file or directory
compilation terminated.
make[3]: *** [src/kernel/CMakeFiles/openmm_api_wrapper.dir/openmm_wrapper.cpp.o] Error 1
make[2]: *** [src/kernel/CMakeFiles/openmm_api_wrapper.dir/all] Error 2
make[1]: *** [src/kernel/CMakeFiles/mdrun.dir/rule] Error 2
make: *** [mdrun] Error 2
make: *** No rule to make target `mdrun-install'.  Stop.

Solution:
Kernel.h was missing from the openmmapi folder when I compiled OpenMM myself. Use the pre-compiled version

4. cc1plus: Unrecognised option -fexcess-precision=fast

Symptom:
 (the % depends on whether you used make, make mdrun, make gmx_gpu_utils etc)
[  0%] Building NVCC (Device) object src/kernel/gmx_gpu_utils/./gmx_gpu_utils_generated_memtestG80_core.cu.o
cc1plus: error: unrecognized command line option "-fexcess-precision=fast"
CMake Error at CMakeFiles/gmx_gpu_utils_generated_memtestG80_core.cu.o.cmake:198 (message):
  Error generating
  /home/me/tmp/gromacs_gpu/src/kernel/gmx_gpu_utils/./gmx_gpu_utils_generated_memtestG80_core.cu.o

make[3]: *** [src/kernel/gmx_gpu_utils/./gmx_gpu_utils_generated_memtestG80_core.cu.o] Error 1
make[2]: *** [src/kernel/gmx_gpu_utils/CMakeFiles/gmx_gpu_utils.dir/all] Error 2
make[1]: *** [src/kernel/CMakeFiles/mdrun.dir/rule] Error 2
make: *** [mdrun] Error 2


Solution: 
You need to edit gmx_gpu_utils_generated_memtestG80_core.cu.o.cmake and gmx_gpu_utils_generated_gmx_gpu_utils.cu.o.cmake and remove all instances of -fexcess-precision=fast
The files in src/kernel/gmx_gpu_utils/ will be overwritten every time you run cmake so make copies of the two edited files to keep around if you need to re-build.

Here's the diff (edit vs unedited) for gmx_gpu_utils_generated_gmx_gpu_utils.cu.o.cmake:

88c88
< set(CMAKE_HOST_FLAGS  -Wall -Wno-unused   )
---
> set(CMAKE_HOST_FLAGS  -fexcess-precision=fast -Wall -Wno-unused   )

Here's the diff (edit vs unedited) for gmx_gpu_utils_generated_memtestG80_core.cu.o.cmake:

88c88
< set(CMAKE_HOST_FLAGS  -Wall -Wno-unused   )
---
> set(CMAKE_HOST_FLAGS  -fexcess-precision=fast -Wall -Wno-unused   )



5. Nonbonded kernel
Symptom:
[ 78%] Building C object src/gmxlib/CMakeFiles/gmx.dir/nonbonded/nb_kernel_x86_64_sse/nb_kernel400_x86_64_sse.c.o
/home/me/tmp/gromacs_gpu/src/gmxlib/nonbonded/nb_kernel_x86_64_sse/nb_kernel400_x86_64_sse.c: In function ‘nb_kernel400nf_x86_64_sse’:
/home/me/tmp/gromacs_gpu/src/gmxlib/nonbonded/nb_kernel_x86_64_sse/nb_kernel400_x86_64_sse.c:629:32: error: ‘gmx_invsqrt_exptab’ undeclared (first use in this function)
/home/me/tmp/gromacs_gpu/src/gmxlib/nonbonded/nb_kernel_x86_64_sse/nb_kernel400_x86_64_sse.c:629:32: note: each undeclared identifier is reported only once for each function it appears in
/home/me/tmp/gromacs_gpu/src/gmxlib/nonbonded/nb_kernel_x86_64_sse/nb_kernel400_x86_64_sse.c:629:59: error: ‘gmx_invsqrt_fracttab’ undeclared (first use in this function)
make[3]: *** [src/gmxlib/CMakeFiles/gmx.dir/nonbonded/nb_kernel_x86_64_sse/nb_kernel400_x86_64_sse.c.o] Error 1
make[2]: *** [src/gmxlib/CMakeFiles/gmx.dir/all] Error 2
make[1]: *** [src/kernel/CMakeFiles/mdrun.dir/rule] Error 2
make: *** [mdrun] Error 2



Solution: instead of just using cmake, use cmake ../gromacs_gpu/ -DGMX_OPENMM=ON -DGMX_THREADS=OFF

Links to this page:
http://lists.gromacs.org/pipermail/gmx-users/2012-February/068121.html
http://gromacs.5086.n6.nabble.com/gromacs-on-GPU-td5004295.html;cid=1358868814898-115