Jump to page: 1 24  
Page
Thread overview
D for project in computational chemistry
Aug 02, 2015
Yura
Aug 02, 2015
ZombineDev
Aug 02, 2015
Daniel N
Aug 02, 2015
bachmeier
Aug 03, 2015
Rikki Cattermole
Aug 03, 2015
yawniek
Aug 03, 2015
Laeeth Isharc
Aug 03, 2015
FreeSlave
Aug 03, 2015
jmh530
Aug 04, 2015
Chris
Aug 04, 2015
maarten van damme
Aug 04, 2015
Chris
Aug 04, 2015
bachmeier
Aug 04, 2015
Chris
Aug 04, 2015
jmh530
Aug 04, 2015
bachmeier
Aug 04, 2015
John Colvin
Aug 04, 2015
John Colvin
Aug 04, 2015
jmh530
Aug 04, 2015
bachmeier
Aug 04, 2015
John Colvin
Aug 05, 2015
Yura
Aug 05, 2015
Chris
Aug 05, 2015
Laeeth Isharc
Aug 05, 2015
bachmeier
Aug 05, 2015
Laeeth Isharc
Aug 06, 2015
jmh530
Aug 06, 2015
Laeeth Isharc
Aug 06, 2015
Laeeth Isharc
Aug 06, 2015
Gerald Jansen
Aug 06, 2015
ixid
Aug 06, 2015
John Colvin
Aug 16, 2015
Yura
Aug 16, 2015
Rikki Cattermole
Aug 16, 2015
Idan Arye
Aug 17, 2015
John Colvin
Aug 17, 2015
jmh530
August 02, 2015
Dear D coders/developers,

I am just thinking on one project in computational chemistry, and it is sort of difficult for me to pick up the right language this project to be written. The project is going to deal with the generation of the molecular structures and will resemble to some extent some bio-informatic stuff. Personally I code in two languages - Python, and a little bit in C (just started to learn this language).

While it is easy to code in Python there are two things I do not like:

1) Python is slow for nested loops (much slower comparing to C)
2) Python is not compiled. However, I want to work with a code which can be compiled and distributed as binaries (at least at the beginning).

When it comes to C, it is very difficult to code (I am a chemist rather than computer scientist). The pointers, memory allocation, absence of the truly dynamically allocated arrays, etc, etc make the coding very long. C is too low level I believe.

I just wander how D would be suitable for my purpose? Please, correct me if I am wrong, but in D the need of pointers is minimal, there is a garbage collector, the arrays can be dynamically allocated, the arrays can be sliced, ~=, etc which makes it similar to python at some extent. I tried to write a little code in D and it was very much intuitive and similar to what I did both in Python and C.

Any hints/thoughts/advises?

With kind regards,
Yury

August 02, 2015
On Sunday, 2 August 2015 at 16:25:18 UTC, Yura wrote:
> Dear D coders/developers,
>
> I am just thinking on one project in computational chemistry, and it is sort of difficult for me to pick up the right language this project to be written. The project is going to deal with the generation of the molecular structures and will resemble to some extent some bio-informatic stuff. Personally I code in two languages - Python, and a little bit in C (just started to learn this language).
>
> While it is easy to code in Python there are two things I do not like:
>
> 1) Python is slow for nested loops (much slower comparing to C)
> 2) Python is not compiled. However, I want to work with a code which can be compiled and distributed as binaries (at least at the beginning).
>
> When it comes to C, it is very difficult to code (I am a chemist rather than computer scientist). The pointers, memory allocation, absence of the truly dynamically allocated arrays, etc, etc make the coding very long. C is too low level I believe.
>
> I just wander how D would be suitable for my purpose? Please, correct me if I am wrong, but in D the need of pointers is minimal, there is a garbage collector, the arrays can be dynamically allocated, the arrays can be sliced, ~=, etc which makes it similar to python at some extent. I tried to write a little code in D and it was very much intuitive and similar to what I did both in Python and C.
>
> Any hints/thoughts/advises?
>
> With kind regards,
> Yury

I'd say go for it. My experience with D is that you can use it both for fast (to write and execute) scripts and for large enterprise applications. You can certainly view it as a easier version of C, though it can offer a lot more if you need it. 90% of the syntax is the same as C, so there shouldn't be gotchas in the basic stuff.

Recently at DConf [1] John Colvin gave a talk [2] about using D for science which will probably be interesting for you.

Good luck :)

[1]: http://dconf.org/2015/schedule/index.html
[2]: https://www.youtube.com/watch?v=edjrSDjkfko D Is For Science
August 02, 2015
On Sunday, 2 August 2015 at 16:25:18 UTC, Yura wrote:
>
> Any hints/thoughts/advises?
>
> With kind regards,
> Yury

Dear Yura,

D is a perfect fit.

For performance reasons, when releasing your binary make sure to use one of these compilers:
GDC - GCC  D Compiler (comparable performance to gcc)
LDC - LLVM D Compiler (comparable performance to clang)

Usually D is on par with C, if performance is less than expected it probably means you forgot one optimization switch, especially singleobj is non-intuitive for ldc2, but can have a dramatic impact.

ex
ldc2 -O5 -inline -release -singleobj -boundscheck=off

Best Regards,
Daniel N

August 02, 2015
On Sunday, 2 August 2015 at 16:25:18 UTC, Yura wrote:
> I just wander how D would be suitable for my purpose? Please, correct me if I am wrong, but in D the need of pointers is minimal, there is a garbage collector, the arrays can be dynamically allocated, the arrays can be sliced, ~=, etc which makes it similar to python at some extent. I tried to write a little code in D and it was very much intuitive and similar to what I did both in Python and C.

If you can do it in C, you can do it in D. Full stop.

You get a lot of nice additional features with D, and unlike C++, there are not a thousand ways to shoot yourself in the foot with a hundred line program. You can easily call C libraries from D so you lose nothing wrt to legacy C code. You can use pyd to interoperate with Python, so you can move as quickly or as slowly as desired from Python to D. You can even call D from C, so if D doesn't work out, you don't lose the code you've written.

I primarily use R but have been moving a lot of code into D for speed and the nice language features for two years now, and I have no regrets. When I started with D, I read lots of comments about the compiler being buggy, but have yet to encounter a compiler bug. Thankfully that myth seems to be dying.
August 03, 2015
On 3/08/2015 4:25 a.m., Yura wrote:
> Dear D coders/developers,
>
> I am just thinking on one project in computational chemistry, and it is
> sort of difficult for me to pick up the right language this project to
> be written. The project is going to deal with the generation of the
> molecular structures and will resemble to some extent some
> bio-informatic stuff. Personally I code in two languages - Python, and a
> little bit in C (just started to learn this language).
>
> While it is easy to code in Python there are two things I do not like:
>
> 1) Python is slow for nested loops (much slower comparing to C)
> 2) Python is not compiled. However, I want to work with a code which can
> be compiled and distributed as binaries (at least at the beginning).
>
> When it comes to C, it is very difficult to code (I am a chemist rather
> than computer scientist). The pointers, memory allocation, absence of
> the truly dynamically allocated arrays, etc, etc make the coding very
> long. C is too low level I believe.
>
> I just wander how D would be suitable for my purpose? Please, correct me
> if I am wrong, but in D the need of pointers is minimal, there is a
> garbage collector, the arrays can be dynamically allocated, the arrays
> can be sliced, ~=, etc which makes it similar to python at some extent.
> I tried to write a little code in D and it was very much intuitive and
> similar to what I did both in Python and C.
>
> Any hints/thoughts/advises?
>
> With kind regards,
> Yury

Everyone else seems to be focusing on the technical aspects of why choose/not D.

To put it simply, just have a go!
Write a small prototype.
- Did you enjoy it?
- Did it reflect what you were thinking well?
- Can others understand it?

If you need help, feel free to jump on and post on D.learn.
If you need more interactive help, come on IRC. We have a channel on FreeNode and even OFTC.

August 03, 2015
On Sunday, 2 August 2015 at 16:25:18 UTC, Yura wrote:

> While it is easy to code in Python there are two things I do not like:
>
> 1) Python is slow for nested loops (much slower comparing to C)
> 2) Python is not compiled. However, I want to work with a code which can be compiled and distributed as binaries (at least at the beginning).
>

you can use the best of both worlds with pyd:
https://github.com/ariovistus/pyd

- write python Modules in D
and/or
- make your D code scriptable with python
August 03, 2015
On Sunday, 2 August 2015 at 16:25:18 UTC, Yura wrote:
> Dear D coders/developers,
>
> I am just thinking on one project in computational chemistry, and it is sort of difficult for me to pick up the right language this project to be written. The project is going to deal with the generation of the molecular structures and will resemble to some extent some bio-informatic stuff. Personally I code in two languages - Python, and a little bit in C (just started to learn this language).
>
> [...]

Did you try PyPy implementation of python? It's claimed to be faster than CPython.
If it's still not enough for you, then try D for sure. Write sample program that do calculations on real data, use gdc or ldc to get the optimized code and see if you're happy with results.
August 03, 2015
On Monday, 3 August 2015 at 14:25:21 UTC, FreeSlave wrote:
> On Sunday, 2 August 2015 at 16:25:18 UTC, Yura wrote:
>> Dear D coders/developers,
>>
>> I am just thinking on one project in computational chemistry, and it is sort of difficult for me to pick up the right language this project to be written. The project is going to deal with the generation of the molecular structures and will resemble to some extent some bio-informatic stuff. Personally I code in two languages - Python, and a little bit in C (just started to learn this language).
>>
>> [...]
>
> Did you try PyPy implementation of python? It's claimed to be faster than CPython.
> If it's still not enough for you, then try D for sure. Write sample program that do calculations on real data, use gdc or ldc to get the optimized code and see if you're happy with results.

Last time I checked there's lots of stuff that you can't use with pypy.
August 03, 2015
On Monday, 3 August 2015 at 06:16:57 UTC, yawniek wrote:
> On Sunday, 2 August 2015 at 16:25:18 UTC, Yura wrote:
>
>> While it is easy to code in Python there are two things I do not like:
>>
>> 1) Python is slow for nested loops (much slower comparing to C)
>> 2) Python is not compiled. However, I want to work with a code which can be compiled and distributed as binaries (at least at the beginning).
>>
>
> you can use the best of both worlds with pyd:
> https://github.com/ariovistus/pyd
>
> - write python Modules in D
> and/or
> - make your D code scriptable with python

Also, note that you can write D in the ipython/jupyter notebook and have it interoperate with D libraries from code.dlang.org and with python.  It's at an early stage, but so far I have found it to work well.

https://github.com/DlangScience/PydMagic
August 04, 2015
On Sunday, 2 August 2015 at 16:25:18 UTC, Yura wrote:
> Dear D coders/developers,
>
> I am just thinking on one project in computational chemistry, and it is sort of difficult for me to pick up the right language this project to be written. The project is going to deal with the generation of the molecular structures and will resemble to some extent some bio-informatic stuff. Personally I code in two languages - Python, and a little bit in C (just started to learn this language).
>
> While it is easy to code in Python there are two things I do not like:
>
> 1) Python is slow for nested loops (much slower comparing to C)
> 2) Python is not compiled. However, I want to work with a code which can be compiled and distributed as binaries (at least at the beginning).
>
> When it comes to C, it is very difficult to code (I am a chemist rather than computer scientist). The pointers, memory allocation, absence of the truly dynamically allocated arrays, etc, etc make the coding very long. C is too low level I believe.
>
> I just wander how D would be suitable for my purpose? Please, correct me if I am wrong, but in D the need of pointers is minimal, there is a garbage collector, the arrays can be dynamically allocated, the arrays can be sliced, ~=, etc which makes it similar to python at some extent. I tried to write a little code in D and it was very much intuitive and similar to what I did both in Python and C.
>
> Any hints/thoughts/advises?
>
> With kind regards,
> Yury

I agree with bachmeier. You cannot go wrong. You mentioned nested loops. D allows you to concatenate (or "pipe") loops. So instead of

foreach
{
  foreach
  {
    foreach
    {
    }
  }
}

you have something like

int[] numbers = [-2, 1, 6, -3, 10];
foreach (ref n; numbers
  .map!(a => a * 5)  // multiply each value by 5
  .filter!(a => a > 0))  // filter values that are 0 or less
{
  //  Do something
}

or just write

auto result = numbers.map!(a => a * 5).filter!(a => a > 0);
// ==> result = [5, 30, 50]

You'd probably want to have a look at:

http://dlang.org/phobos/std_algorithm.html

and ranges (a very important concept in D):

http://ddili.org/ders/d.en/ranges.html
http://wiki.dlang.org/Component_programming_with_ranges

Excessive use of nested loops is not necessary in D nor is it very common. This makes the code easier to maintain and less buggy in the end.
« First   ‹ Prev
1 2 3 4