mcocdawc / chemcoord

A python module for manipulating cartesian and internal coordinates.
GNU Lesser General Public License v3.0
72 stars 19 forks source link

Substitution function? #60

Closed sarahkha closed 5 years ago

sarahkha commented 5 years ago

Hello,

I was wondering whether there is any function to substitute a line of coordinate by another line of coordinate?

Thank you Sarah

mcocdawc commented 5 years ago

What exactly do you want to do?

The general answer is probably just do use the loc or iloc selection methods with boolean indexing and assign to slices.

molecule.loc[index, :] = iterable

I strongly recommend to have a look at some pandas tutorials to understand boolean slicing etc.

Lets, assume you want to to move all carbon atoms in a molecule 1 Å into the x direction. This task becomes.

molecule.loc[molecule.atom == 'C', 'x'] = molecule.loc[molecule.atom == 'C', 'x'] + 1
sarahkha commented 5 years ago

I would like:

Frag1 C 0.000000 0.000000 0.000000 H 0.000000 0.000000 1.089000​ H -0.513360 -0.889165 -0.363000​ H -0.513360 0.889165 -0.363000 H 1.026720 0.000000 -0.362996 = substitute by Frag2 ?

Frag2 C 1.414215 0.000000 -0.499995​ H 1.414220 0.000000 -1.569995​ H 1.918617 0.873651 -0.143326​ H 1.918617 -0.873651 -0.143326

Final frag = frag1 substitute the last line by frag2 C 0.000000 0.000000 0.000000 H 0.000000 0.000000 1.089000 H -0.513360 -0.889165 -0.363000​ H -0.513360 0.889165 -0.363000 C 1.414215 0.000000 -0.499995​ H 1.414220 0.000000 -1.569995​ H 1.918617 0.873651 -0.143326​ H 1.918617 -0.873651 -0.143326​


De : Oskar Weser notifications@github.com Envoyé : mercredi 9 octobre 2019 18:20 À : mcocdawc/chemcoord chemcoord@noreply.github.com Cc : sarahkha sarahkha@mit.edu; Author author@noreply.github.com Objet : Re: [mcocdawc/chemcoord] Substitution function? (#60)

What exactly do you want to do?

The general answer is probably just do use the loc or iloc selection methods with boolean indexing and assign to slices.

molecule.loc[index, :] = iterable

I strongly recommend to have a look at some pandas tutorialshttps://pandas.pydata.org/pandas-docs/stable/getting_started/tutorials.html to understand boolean slicing etc.

Lets, assume you want to to move all carbon atoms in a molecule 1 Å into the x direction. This task becomes.

molecule.loc[molecule.atom == 'C', 'x'] = molecule.loc[molecule.atom == 'C', 'x'] + 1

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/mcocdawc/chemcoord/issues/60?email_source=notifications&email_token=AIATCZG7PQ3ZAY57IEDJAK3QNYADTA5CNFSM4I7AE772YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAYOSYI#issuecomment-540076385, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AIATCZEDTIEWRWYR34RDRRTQNYADTANCNFSM4I7AE77Q.

sarahkha commented 5 years ago

I would like:

Frag1 C 0.000000 0.000000 0.000000 H 0.000000 0.000000 1.089000​ H -0.513360 -0.889165 -0.363000​ H -0.513360 0.889165 -0.363000 H 1.026720 0.000000 -0.362996 = substitute by Frag2 ?

Frag2 C 1.414215 0.000000 -0.499995​ H 1.414220 0.000000 -1.569995​ H 1.918617 0.873651 -0.143326​ H 1.918617 -0.873651 -0.143326

Final frag = frag1 substitute the last line by frag2 C 0.000000 0.000000 0.000000 H 0.000000 0.000000 1.089000 H -0.513360 -0.889165 -0.363000​ H -0.513360 0.889165 -0.363000 C 1.414215 0.000000 -0.499995​ H 1.414220 0.000000 -1.569995​ H 1.918617 0.873651 -0.143326​ H 1.918617 -0.873651 -0.143326

mcocdawc commented 5 years ago
cc.xyz_functions.concat([frag1.iloc[:-1, :], frag2], ignore_index=True)

If you are working with fragments and want to change their relative position, I would use a Z-matrix.