sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.36k stars 462 forks source link

Add generators for fullerenes #14618

Closed nvcleemp closed 11 years ago

nvcleemp commented 11 years ago

In the discussion of ticket #9136, it was mentioned that a generator for fullerenes would be a great addition. The fullerene generator fullgen by Gunnar Brinkmann can't be added due to licensing problems. Brinkmann's student Jan Goedgebeur implemented a new version using a different algorithm which is faster for the `small' cases: http://caagt.ugent.be/buckygen/ This program is available under the GPL 3, so I assume it can be integrated in Sage.

New spkg: http://users.ugent.be/~nvcleemp/buckygen-1.0.spkg

Apply:

Depends on #14532

CC: @sagetrac-azi @sagetrac-Slani @sagetrac-Stefan @nathanncohen

Component: packages: optional

Author: Nico Van Cleemput

Reviewer: Nathann Cohen

Merged: sage-5.11.beta0

Issue created by migration from https://trac.sagemath.org/ticket/14618

nvcleemp commented 11 years ago
comment:1

I'm willing to work on this. I belong to the same research group and have some familiarity with the program and the used file formats, since I integrated it into CaGe (http://caagt.ugent.be/CaGe). I'm quite new to Sage, so I might however need some tips as to how to go about integrating it into Sage.

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:2

This would be a great addition to Sage ! this being said, a bad license does not necessarily mean that the software will never be used through Sage : it just means that it cannot be distributed with Sage. But we can use Nauty, which is not GPL-compatible, through the Nauty spkg :-)

Nathann

ca0b67cc-9d10-44c6-be51-5d9e2cdee96a commented 11 years ago
comment:3

Indeed that would be nice!

Let us know if you have any questions about integrating this into Sage.

nvcleemp commented 11 years ago
comment:4

Replying to @nathanncohen:

This would be a great addition to Sage ! this being said, a bad license does not necessarily mean that the software will never be used through Sage : it just means that it cannot be distributed with Sage. But we can use Nauty, which is not GPL-compatible, through the Nauty spkg :-)

Nathann

Yes, but for most cases buckygen outperforms fullgen, so it is the better choice. This is also the reason why it is now used in CaGe, except when the fullerenes need to be filtered based on the symmetry group or when they are needed in a specific order. These are all arguments which are mostly important for chemists, and even for them only in specific situations.

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:5

Yooooooo !

Yes, but for most cases buckygen outperforms fullgen, so it is the better choice.

Oh. Well, that's even better :-P

Nathann

nvcleemp commented 11 years ago
comment:6

Replying to @sagetrac-azi:

Indeed that would be nice!

Let us know if you have any questions about integrating this into Sage.

Well, buckygen supports export in graph6, sparse6 and planar_code format. Using the first two is no problem, since they are already supported by Sage. However, this looses some information: buckygen generates plane graphs. This doesn't seem to be supported in Sage. Is that correct? Is it something that might be added in the near future?

Secondly, I had a look at the geng generator to get an idea how to integrate this kind of functionality. The Sage-part seems rather straight-forward. What I do have a question about, is how to add the buckygen program and make sure that it gets compiled, is available, ...

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:7

Well, buckygen supports export in graph6, sparse6 and planar_code format. Using the first two is no problem, since they are already supported by Sage. However, this looses some information: buckygen generates plane graphs. This doesn't seem to be supported in Sage. Is that correct? Is it something that might be added in the near future?

"Planar graphs are not supported" ? What do you mean ? Do you mean that the embedding, or the positions are lost ? May it be what you need ?

http://www.sagemath.org/doc/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.get_embedding

I never used it myself, though it looks "useful" if you really, really work on planar graphs :-)

Secondly, I had a look at the geng generator to get an idea how to integrate this kind of functionality. The Sage-part seems rather straight-forward. What I do have a question about, is how to add the buckygen program and make sure that it gets compiled, is available, ...

You have to build a spkg.

http://www.sagemath.org/doc/developer/producing_spkgs.html

Nathann

nvcleemp commented 11 years ago
comment:8

OK, thanks. That seems to answer my questions for now. I know what to do for the next couple of days. ;-)

nvcleemp commented 11 years ago
comment:9

Replying to @nvcleemp:

OK, thanks. That seems to answer my questions for now. I know what to do for the next couple of days. ;-)

So, I think I have a first version ready. You will need the following spkg:

http://users.ugent.be/~nvcleemp/buckygen-1.0.spkg

I guess this can become a standard package, since it is GPL v3.

I looked at different spkg and copied what they did, so I hope that everything is in order. The same goes for the patch. Let me know what needs to be changed.

nvcleemp commented 11 years ago
comment:11

Ow, just saw that I completely forgot the error handling: I still need to replace those passes. I'm sorry.

nvcleemp commented 11 years ago
comment:13

OK, errors are now handled.

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:14

Helloooooooooooooooooooooooooooooooooooo !!!

NIiiiiiiice to have this in Sage ! I already know a couple of persons who will be interested in this feature :-)

Some comments:

That's all I can think of right now :-)

And thank you very much again for adding this. That's good stuff !

Nathann

nvcleemp commented 11 years ago
comment:15

OK, I'll change all of that. I used ipr, because also in the literature this is almost always referred to as IPR and hardly ever as Isolated Pentagon Rule.

The naming buckygen was only based on nauty_geng: it's certainly no problem to rename it to fullerenes. Btw, that's the way we do it in CaGe.

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:16

Well, if it is that standard then it is probably better to stick with "ipr". The alternative is really very long.

And I don't think that nauty_geng is such a good name either, but it has been like that since before I first used Sage, and I don't have a great idea of what it could be replaced with either ^^;

Nathann

nvcleemp commented 11 years ago
comment:17

Btw, since buckygen is GPL, is there a reason why the spkg can't be included as a standard spkg?

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:18

I believe that it has to be optional for a while... But then again it's pretty small. Could you ask on sage-devel ?

By the way, I forgot to add a couple of things to my earlier review : could you remove the patches/ directory from your spkg ? It's not needed unless it is nonempty :-)

Oh, and SPKG.txt file has the +x flag for no reason.

Nathann

nvcleemp commented 11 years ago
comment:19

Hi, thanks for the feedback. I've modified the spkg, it is still at

http://users.ugent.be/~nvcleemp/buckygen-1.0.spkg

I've indeed found the explanation that a spkg should first be optional for a while on the wiki. I had missed that at first.

I'll also add a new version of the patch.

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:20

(I just rebased your patch on Sage 5.10.beta4, as it did not apply cleanly. #14532 was to blame)

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago

Dependencies: #14532

nvcleemp commented 11 years ago
comment:21

Hmm, ok, what does that mean for me? Anything I need to do? Apply those patches and then remake my patch?

nvcleemp commented 11 years ago
comment:22

ok, I'm blind: I didn't see that you've already done that. :-)

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:23

Nonono. I did that for you. But it means that right now you own patch will not apply cleanly on your own version of Sage anymore. And because I will probably write a small reviewer's patch, you will not be able to apply this on your version of Sage either, unless you add the dependencies yourself.

If you don't need your cpu for a couple of hours, then it's probably the right time to download and compile sage 5.10.beta4.

Have fuuuuuuuuuuuuuuuuuuuuuuuuunnn !!

Nathann

nvcleemp commented 11 years ago
comment:24

Since I wrote most of the original patch, I assume I can't review this? ;-)

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:25

Ahahah. No you can't and you should not. I intended to write a reviewer's patch for this ticket but I had some problems with my copy of Sage, and it was delayed. You will have it by today !

Sorry for that !

Nathann

nvcleemp commented 11 years ago
comment:26

hehe, no problem. I was just wondering if there was anything more I needed to do. But I guess I can just lay back and relax. Or maybe start marking the projects of my students. :-(

No hurry!

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago

Attachment: trac_14618_buckygen.patch.gz

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:27

(new version of the original patch without trailing whitespaces)

nvcleemp commented 11 years ago
comment:28

hmm, I just noted a small typo on line 990: 20 should be removed there. Currently not at my own computer, so I can't fix it at the moment.

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago

Description changed:

--- 
+++ 
@@ -1 +1,8 @@
 In the discussion of ticket #9136, it was mentioned that a generator for fullerenes would be a great addition. The fullerene generator fullgen by Gunnar Brinkmann can't be added due to licensing problems. Brinkmann's student Jan Goedgebeur implemented a new version using a different algorithm which is faster for the `small' cases: http://caagt.ugent.be/buckygen/ This program is available under the GPL 3, so I assume it can be integrated in Sage.
+
+New spkg: http://users.ugent.be/~nvcleemp/buckygen-1.0.spkg
+
+Apply: 
+* [attachment: trac_14618_buckygen.patch](https://github.com/sagemath/sage-prod/files/10657822/trac_14618_buckygen.patch.gz)
+* [attachment: trac_14618-rev.patch](https://github.com/sagemath/sage-prod/files/10657823/trac_14618-rev.patch.gz)
+
6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago

Reviewer: Nathann Cohen

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:29

Heeeeeeeeeeere it is !

This patch touches small things, but mostly simplifies code that could be simplified, and adds some doc. If you agree with it you can set this ticket to positive_review, otherwise let's talk about it :-)

Thank you again for this patch !

Nathann

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:30

Oh, by the way... I replaced a "ValueError" (when the number of vertices is not even) by a StopIteration. Is that a problem ? Now, here is what you get :

sage: list(graphs.fullerenes(30))                                 
[Graph on 30 vertices, Graph on 30 vertices, Graph on 30 vertices]
sage: list(graphs.fullerenes(20))
[Graph on 20 vertices]
sage: list(graphs.fullerenes(10))
[]
sage: list(graphs.fullerenes(15))
[]

There's no problem to me if the method returns an empty list when no graph exists.... Tell me what you think !

Nathann

nvcleemp commented 11 years ago
comment:31

Yes, I can agree with that. I think it can be argued whether asking for a fullerene with an odd number of vertices should give an error or just no graphs. I guess that this is the most friendly solution.

Maybe just a short note on the reason why I handled the header like I did. I was writing a bit more general code which could be used to handle all variants of planar code: >>planar_code<<, >>planar_code le<< or >>planarcode be<<.

I wanted to test whether buckygen would generate any of the other headers if the graphs became quite large. This way I noticed that buckygen will only generate planar code up to 254 vertices. Beyond that it just gives an error message. I will ask Jan (the author of buckygen) about this, but he's currently out of the office.

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:32

Maybe just a short note on the reason why I handled the header like I did. I was writing a bit more general code which could be used to handle all variants of planar code: >>planar_code<<, >>planar_code le<< or >>planarcode be<<.

I wanted to test whether buckygen would generate any of the other headers if the graphs became quite large. This way I noticed that buckygen will only generate planar code up to 254 vertices. Beyond that it just gives an error message. I will ask Jan (the author of buckygen) about this, but he's currently out of the office.

ARGGGGGGGGGG ! I totally forgot ! Of course I wanted to try graphs with 300 vertices, as obviously you can't store that on one byte... So, do we change that to 256 in the code ? Unless there is a trick to be found :-)

Nathann

nvcleemp commented 11 years ago
comment:33

Attachment: trac_14618-rev.patch.gz

Well, planar code fixes this by using two bytes. That's why the header is needed to specify whether little endian or big endian is used. However, it appears that this is not implemented in buckygen. I'll ask the buckygen author what he thinks. I know he output larger graphs, but I don't know if he used a special patched version or so. I see the author tomorrow.

Nico

nvcleemp commented 11 years ago
comment:34

As I expected, the output of graphs with more than 254 vertices is not supported. Instead one can output the dual, which has roughly half the number of vertices.

On the other hand, there are 1 985 250 572 fullerenes with 254 vertices and buckygen takes 2.5 days to generate those. Translating the graphs to Sage graphs will take even more time. Do we really want to support graphs with that many vertices or should we just hold the limit at 254 vertices? 254 vertices is already a bit too high for practical use in Sage.

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:35

Ahahahah. No, I think that it would make sense indeed to change Sage's bound to 254 :-)

Nathann

nvcleemp commented 11 years ago

Attachment: trac_14618_bound_254.patch.gz

nvcleemp commented 11 years ago

Description changed:

--- 
+++ 
@@ -5,4 +5,5 @@
 Apply: 
 * [attachment: trac_14618_buckygen.patch](https://github.com/sagemath/sage-prod/files/10657822/trac_14618_buckygen.patch.gz)
 * [attachment: trac_14618-rev.patch](https://github.com/sagemath/sage-prod/files/10657823/trac_14618-rev.patch.gz)
+* [attachment: trac_14618_bound_254.patch](https://github.com/sagemath/sage-prod/files/10657824/trac_14618_bound_254.patch.gz)
nvcleemp commented 11 years ago
comment:36

OK, this new patch sets the maximum number of vertices to 254. I think that was the last issue.

Nico

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:37

Okayyyyyyy... Then I guess that it is good to go :-)

Nathann

haraldschilly commented 11 years ago
comment:40

buckygen successfully landed on the server

6bdad4c1-1e26-4f2f-a442-a01a2292c181 commented 11 years ago
comment:41

Coool ! Thanks :-)

Nathann

jdemeyer commented 11 years ago

Merged: sage-5.11.beta0