gchemutils-main
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gchemutils-main] How to draw atoms in the gtk window


From: Jean Bréfort
Subject: Re: [Gchemutils-main] How to draw atoms in the gtk window
Date: Sat, 09 Aug 2008 14:18:16 +0200

You must start with gtk_init and you need both a widget and a window,
something like:
using namespace std;
#include <iostream>

// graphic libraries:
#include <gcu/chemistry.h>
#include <gcu/gtkchem3dviewer.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <libgnomevfs/gnome-vfs.h>

int main( int argc, char* argv[] ) {

gtk_init (&argc, &argv);
gnome_vfs_init ();

GtkWidget *widget = gtk_chem3d_viewer_new (NULL);  <---problematic line!

GtkWindow *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

gtk_window_set_title (GTK_WINDOW (window), "GtkCrystalViewer test");
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK
(gtk_main_quit), NULL);

gtk_window_set_title (GTK_WINDOW (window), "Structure viewer");

g_signal_connect (G_OBJECT (window), "destroy",
                 G_CALLBACK (gtk_main_quit),
                 NULL);

char const my_data[] =
       "6\n"
       "\n"
       "O 0.87 0 0\n"
       "O 1.73 0.5 0\n"
       "O 1.73 1.5 0\n"
       "O 0.87 2 0\n"
       "O 0 1.5 0 \n"
       "O 0 0.5 0 \n";

gtk_chem3d_viewer_set_data (GTK_CHEM3D_VIEWER (widget), my_data,
"chemical/x-xyz");

gtk_container_add (GTK_CONTAINER (window), widget);

gtk_widget_show_all (window);

gtk_main ();

}


Le samedi 09 août 2008 à 13:54 +0200, Filippo Bovo a écrit :
> I tryed the program but the output is this:
> 
> (process:12616): GLib-GObject-CRITICAL
> **: /tmp/buildd/glib2.0-2.16.3/gobject/gtype.c:2248: initialization
> assertion failed, use IA__g_type_init() prior to this function
> 
> (process:12616): GLib-CRITICAL **: g_once_init_leave: assertion
> `initialization_value != 0' failed
> 
> (process:12616): GLib-GObject-CRITICAL
> **: /tmp/buildd/glib2.0-2.16.3/gobject/gtype.c:2248: initialization
> assertion failed, use IA__g_type_init() prior to this function
> 
> (process:12616): GLib-GObject-CRITICAL
> **: /tmp/buildd/glib2.0-2.16.3/gobject/gtype.c:2248: initialization
> assertion failed, use IA__g_type_init() prior to this function
> 
> (process:12616): GLib-GObject-CRITICAL
> **: /tmp/buildd/glib2.0-2.16.3/gobject/gtype.c:2248: initialization
> assertion failed, use IA__g_type_init() prior to this function
> 
> (process:12616): GLib-GObject-CRITICAL **:
> g_type_add_interface_static: assertion `G_TYPE_IS_INSTANTIATABLE
> (instance_type)' failed
> 
> (process:12616): GLib-GObject-CRITICAL
> **: /tmp/buildd/glib2.0-2.16.3/gobject/gtype.c:2248: initialization
> assertion failed, use IA__g_type_init() prior to this function
> 
> (process:12616): GLib-GObject-CRITICAL **:
> g_type_add_interface_static: assertion `G_TYPE_IS_INSTANTIATABLE
> (instance_type)' failed
> 
> (process:12616): GLib-GObject-CRITICAL
> **: /tmp/buildd/glib2.0-2.16.3/gobject/gtype.c:2248: initialization
> assertion failed, use IA__g_type_init() prior to this function
> 
> (process:12616): GLib-GObject-CRITICAL
> **: /tmp/buildd/glib2.0-2.16.3/gobject/gtype.c:2248: initialization
> assertion failed, use IA__g_type_init() prior to this function
> 
> (process:12616): GLib-GObject-CRITICAL **:
> g_type_add_interface_static: assertion `G_TYPE_IS_INSTANTIATABLE
> (instance_type)' failed
> 
> (process:12616): GLib-GObject-CRITICAL
> **: /tmp/buildd/glib2.0-2.16.3/gobject/gtype.c:2248: initialization
> assertion failed, use IA__g_type_init() prior to this function
> 
> (process:12616): GLib-CRITICAL **: g_once_init_leave: assertion
> `initialization_value != 0' failed
> 
> (process:12616): GLib-GObject-CRITICAL
> **: /tmp/buildd/glib2.0-2.16.3/gobject/gtype.c:2248: initialization
> assertion failed, use IA__g_type_init() prior to this function
> 
> (process:12616): GLib-GObject-CRITICAL **: g_object_new: assertion
> `G_TYPE_IS_OBJECT (object_type)' failed
> 
> 
> The problem is in this line:
>  GtkWidget *w = gtk_chem3d_viewer_new (NULL);
> 
> 
> The entire program is this:
> 
> using namespace std;
> #include <iostream>
> 
> // graphic libraries:
> #include <gcu/chemistry.h>
> #include <gcu/gtkchem3dviewer.h>
> #include <glib.h>
> #include <gtk/gtk.h>
> #include <stdio.h>
> #include <libgnomevfs/gnome-vfs.h>
> 
> int main( int argc, char* argv[] ) {
> 
> GtkWidget *window = gtk_chem3d_viewer_new (NULL);  <---problematic
> line!
> 
> gtk_init (&argc, &argv);
> 
> window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
> 
> gtk_window_set_title (GTK_WINDOW (window), "GtkCrystalViewer test");
> g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK
> (gtk_main_quit), NULL);
> 
> gtk_window_set_title (GTK_WINDOW (window), "Structure viewer");
> 
> g_signal_connect (G_OBJECT (window), "destroy",
>                  G_CALLBACK (gtk_main_quit),
>                  NULL);
> 
> char const my_data[] =
>        "6\n"
>        "\n"
>        "O 0.87 0 0\n"
>        "O 1.73 0.5 0\n"
>        "O 1.73 1.5 0\n"
>        "O 0.87 2 0\n"
>        "O 0 1.5 0 \n"
>        "O 0 0.5 0 \n";
> 
> gtk_chem3d_viewer_set_data (GTK_CHEM3D_VIEWER (window), my_data,
> "chemical/x-xyz");
> 
> gtk_widget_show_all (window);
> 
> gtk_main ();
> 
> }
> 
> 
> I also tryed the program without the part written in italic but the
> output is the same.
> I hope only it is not a gtk bug!
> Do you know how to fix this problem?
> 
> Best regards,
>  Filippo
> 
> 2008/8/9 Jean Bréfort <address@hidden>
>         Le samedi 09 août 2008 à 10:54 +0200, Filippo Bovo a écrit :
>         > Thank you very much!!!
>         > I will try this algorithm this afternoon, then I will say if
>         it works.
>         >
>         > ( Oh, two atoms have the same coordinates...the last has to
>         be 0 0.5
>         > 0...a copy and paste mistake! :-) )
>         >
>         > The reason I use this program is that I'm doing a university
>         work
>         > on hexagonal and cubic ice simulations and properties and I
>         was trying
>         > to rappresent them in a window to have some images (the
>         coordinates I
>         > wrote in the email are the coordinates of a regular
>         hexagon...just to
>         > have something to plot in the window).
>         
>         
>         Ths easiest way is to use Gnome Crystal. I join a file for
>         cubic ice I
>         use with my students. If you are able to install by yourself a
>         0.9.x
>         version, you might also import cif files.
>         
>         > I have some other short questions:
>         
>         >      1. How can I rappresent a bond (i.e.: the bonds that
>         the oxygen
>         >         has with the two hydorgen atoms) in the window?
>         
>         
>         Just add the hydrogen atoms, the framework adds the bonds
>         automatically.
>         
>         >      1. How can I save the image I have in the window in a
>         format
>         >         like .jpg?
>         
>         Use Gnome Crystal, it has this feature. Otherwise, You might
>         use the
>         gcu::CrystalDoc class, add atoms and bonds, and you can use
>         the
>         GLView::SaveAsImage method, but its much easier to use the
>         existing
>         program.
>         
>         >      1. You said that this library would stay unused outside
>         of the
>         >         Gnome Chemistry Utils. So which library would you
>         suggest me
>         >         to use?
>         
>         
>         I don't say it should stay unused, but nobody tried to use it
>         for years
>         except me for GChemPaint, so that I thought it was not useful
>         to keep
>         installing the development files now that GChemPaint is
>         included in the
>         tarball (0.9.x or later), so that packagers life might be a
>         bit easier.
>         If anybody wants to use it, I can easily restore the
>         functionality (just
>         need to add the pc file (for pkg-config)).
>         
>         
>         > Thank you very much for the answers!!
>         >
>         > Best regards,
>         >  Filippo
>         >
>         >
>         > On 09/08/2008, Jean Bréfort <address@hidden>
>         wrote:
>         >         Le samedi 09 août 2008 à 09:36 +0200, Filippo Bovo a
>         écrit :
>         >         > My Goal:
>         >         > I have an array of vectors. Every vector contains
>         the
>         >         coordinates in
>         >         > the 3d space: x, y, z. I want to plot them in the
>         gtk
>         >         window.
>         >         >
>         >         > How do I do this?
>         >         >
>         >         > Observations:
>         >         >      1. The reason I used CrystalAtom class and
>         not simply
>         >         the
>         >         >         Atom class is that it has the same basic
>         use of the
>         >         Atom
>         >         >         one but has many related member functions.
>         I did not
>         >         thought
>         >         >         to miller indexes so I don't want to
>         express the
>         >         coordinates
>         >         >         with numbers between 0 and 1.
>         >         >         To make things simpler I can use Atom
>         class if it is
>         >         useful to
>         >         >         explain things better.
>         >         >      2. I tried to use the Application class to
>         create a
>         >         document and
>         >         >         a related view but if only I include the
>         >         application.h in the
>         >         >         file and then compile it I have errors of
>         >         declaration of
>         >         >         DATADIR and PACKAGE_BUGREPORT.
>         >
>         >         You don't need an Application object, unless you
>         derive your
>         >         own class.
>         >         The current API does not easily allow what you want
>         to do. The
>         >         3d viewer
>         >         doesn't use the gcu::Atom class at the moment for
>         historical
>         >         reasons but
>         >         OpenBabel::OBAtom.
>         >         The easiest way for you is to get an xyz file from
>         your data
>         >         (which
>         >         might be in memory) then load it in a
>         GtkChem3DViewer and
>         >         disply the
>         >         widget.
>         >
>         >         Something as:
>         >
>         >         char const my_data[] =
>         >                "6\n"
>         >                "\n"
>         >                "O 0.87 0 0\n"
>         >                "O 1.73 0.5 0\n"
>         >                "O 1.73 1.5 0\n"
>         >                "0 0.87 2 0\n"
>         >                "O 0 1.5 0 \n"
>         >                "O 0.87 0 0 \n";
>         >
>         >         GtkWidget *w = gtk_chem3d_viewer_new (NULL);
>         >         gtk_chem_3d_viewer_set_data (GTK_CHEM3D_VIEWER (w),
>         my_data,
>         >         "chemical/x-xyz");
>         >         gtk_widget_show (w);
>         >
>         >         Then, you need to add the widget to the appropriate
>         container
>         >         as usual
>         >         in gtk+. I did not test, but it should work ;-)
>         >
>         >         Note that two of your atoms have the same
>         coordinates which is
>         >         dubious,
>         >         and that OpenBabel will add bonds between neighbor
>         atoms.
>         >
>         >         Btw, I was thinking that this library would stay
>         unused
>         >         outside of the
>         >         Gnome Chemistry Utils and dropped the devel files
>         from the
>         >         0.10 branch.
>         >         If you want to go on using it, please tell me, I'll
>         put them
>         >         back.
>         >         If you have specific needs not currently supported,
>         please
>         >         file as many
>         >         bugs reports as necessary.
>         >
>         >         Best regards,
>         >         Jean
>         >
>         >
>         >
>         
> 
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]