<jupyter_start><jupyter_text>AMUSE tutorial on modules and channels====================AMUSE is composed of domain-specific modules (i.e. the physics modules), which are often written in some native compiled language, and data-handling.the latter tends to be confusing for novel users.Data representation in AMUSE is often replicated.So can there be a parameter *mass* to indicate a property of a star in a stellar-evolution code, in a gravitational dynamics code and in your user script. These three parameters *mass* can mean the same, or they can have a different meaning. This makes running amuse somewhat confusing at times.Here we show how to formally separate these data streams.But first we will enter the realm of modules.<jupyter_code>#Load in the amuse units module, the particle module and 
# some generator for producing some conditions.
from amuse.units import units, constants
from amuse.lab import Particles<jupyter_output><empty_output><jupyter_text>We now like to generate the Solar system, as it was observed on April 5th 2063 using the [JPL emphemeris](https://ssd.jpl.nasa.gov/horizons.cgitop).Let's start with the inner most planet, Mercury, in the Sun's barycenter, which gives the following output:*******************************************************************************$$SOE2474649.500000000 = A.D. 2063-Apr-05 00:00:00.0000 TDB  X =-2.689701945882702E-01 Y = 1.947622508089924E-01 Z = 4.148911797144442E-02 VX=-2.230751806031045E-02 VY=-2.157655548570704E-02 VZ= 2.791759037949523E-04 LT= 1.932846451835678E-03 RG= 3.346619889187973E-01 RR= 5.406475142917982E-03 We can use these to start an AMUSE particle set, as follows<jupyter_code>Sun = Particles(1)
Sun.mass = 1 | units.MSun
Sun.position = (0,0,0) | units.km
Sun.velocity = (0,0,0) | units.km/units.s
planets = Particles(8)
planets[0].mass = 3.302e+23 | units.kg # also according to JPL)
planets[0].position = (-2.689701945882702E-01,
                       1.947622508089924E-01,
                       4.148911797144442E-02) | units.au
planets[0].velocity = (-2.230751806031045E-02,
                       -2.157655548570704E-02,
                       2.791759037949523E-04) | units.au/units.yr<jupyter_output><empty_output><jupyter_text>And continue doing this for the other 7 planets.Then add the Sun and we have the Solar system's particle set.It would be easier if there is a handy routine with the same effect, in particular because of frequently will be using the Solar system as some sort of template for a rather typical planetary system, or for specifically sutdying this planetary system. We therefore have a handy routine that gives allows us to initialize the Solar system.<jupyter_code>from amuse.ext.solarsystem import new_solar_system
sun_and_planets = new_solar_system()
#sun_and_planets = sun_and_planets[0].as_set()
print(sun_and_planets)<jupyter_output>|S11
                 key         mass         name       radius           vx           vy           vz            x            y            z
                   -         MSun         none         RSun       km / s       km / s       km / s           AU           AU           AU
====================  ===========  ===========  ===========  ===========  ===========  ===========  ===========  ===========  ===========
 6651284024525347701    1.000e+00          SUN    1.000e+00   -1.874e-03   -1.560e-02    1.104e-04   -8.354e-03    1.923e-03    2.145e-04
11361453784849012877    1.660e-07      MERCURY    5.654e-03    1.032e+01   -4.214e+01   -4.388e+00   -3.923e-01   -1.749e-01    2.101e-02
 7973865882662013015    2.448e-06        VENUS    1.403e-02   -1.704e+01    3.049e+01    1.401e+00    6.251e-01    3.518e-01   -3.157e-02
 9336316391706255048    3.040e-06     EARTHMOO    1.482e-02    2.844e+01    6.966e+00    1.301e-04    2.337e-01   -9.855e-01    2.100e-04
12320338445353835314    3.227[...]<jupyter_text>We adopted the module `ext.new_solar_system` to generate a ready-made solar system. You can also make a solar system that includes it's moons. For this you will have to use the routine 'new_lunar_system', which is a module from the 'amuse.ic.solar_system_moons' package.Now, plot the positions of the sun and planets in the orbital plane. In 1984  [<NAME>](https://ui.adsabs.harvard.edu/abs/1984Natur.308..713W/abstract) and [Davies et al 1984](https://ui.adsabs.harvard.edu/abs/1984Natur.308..715D)([preprint](https://escholarship.org/uc/item/9gm5c682)) argued that the Solar system was orbited by a hypothetical star called nemesis, named after the goddessof Rhamnous who punished those who did not honor the Olympians.This companion to the Sun would have an orbital separation of about 95,000 au, and due to its interaction with the Oort cloud would initiate periodic comet shouwers in the inner Solar system; punishing life on Earth for being atheistic?Let's adopt the Solar system as we have just initialized and add Nemesis as an 0.2MSun main-sequence star in a 95,000 au orbit with an eccentricity of 0.7.Let's construct tha binary system of the Sun (without planets) and Nemesis.<jupyter_code>msun = sun_and_planets.mass.sum()
mnemesis = 0.2 | units.MSun
a = 95000 | units.au
e = 0.7
from amuse.ext.orbital_elements import new_binary_from_orbital_elements
sun_and_nemesis = new_binary_from_orbital_elements(msun, mnemesis, 
                                          a, e, G=constants.G)
setattr(sun_and_nemesis, "name", ["Companion", "Nemesis"])
print(sun_and_nemesis)<jupyter_output>key         mass         name           vx           vy           vz            x            y            z
                   -         MSun         none  3646245880.3572216 * m * s**-1  3646245880.3572216 * m * s**-1  3646245880.3572216 * m * s**-1  149597870691.0 * m  149597870691.0 * m  149597870691.0 * m
====================  ===========  ===========  ===========  ===========  ===========  ===========  ===========  ===========
  388603917714193344    1.001e+00    Companion    0.000e+00   -1.151e-08   -0.000e+00   -4.745e+03   -0.000e+00   -0.000e+00
 1364133191765162363    2.000e-01      Nemesis    0.000e+00    5.764e-08    0.000e+00    2.376e+04    0.000e+00    0.000e+00
====================  ===========  ===========  ===========  ===========  ===========  ===========  ===========  ===========<jupyter_text>Now, the sun in this binary-particle set and the sun in the Solar system particle-set do not have the same position.<jupyter_code>sun = sun_and_planets[sun_and_planets.name=="SUN"]
print(sun.position.in_(units.au))
print(sun_and_nemesis[sun_and_nemesis.mass>0.9|units.MSun].position.in_(units.au))<jupyter_output>[[-0.00835408821766, 0.0019229394648, 0.000214547107396]] au
[[-4744.69448798, -0.0, -0.0]] au<jupyter_text>And, equally wise they will have different velocity.however, we would like to adot these binary parameters for the Sun-Nemesis binary system. For this, we first move the entire Solar system to the Sun barycenter, move it to Nemesis' companion and add Nemesis.<jupyter_code>sun_and_planets.position -= sun.position
sun_and_planets.velocity -= sun.velocity
companion = sun_and_nemesis[sun_and_nemesis.name=="Companion"]
nemesis = sun_and_nemesis[sun_and_nemesis.name=="Nemesis"]
sun_and_planets.position += companion.position
sun_and_planets.velocity += companion.velocity
sun_and_planets.add_particle(sun_and_nemesis[1])
print(sun_and_planets)<jupyter_output>key         mass         name       radius           vx           vy           vz            x            y            z
                   -         MSun         none         RSun       km / s       km / s       km / s           AU           AU           AU
====================  ===========  ===========  ===========  ===========  ===========  ===========  ===========  ===========  ===========
 6651284024525347701    1.000e+00          SUN    1.000e+00    0.000e+00   -4.198e-02    0.000e+00   -4.745e+03    0.000e+00    0.000e+00
11361453784849012877    1.660e-07      MERCURY    5.654e-03    1.032e+01   -4.217e+01   -4.389e+00   -4.745e+03   -1.769e-01    2.080e-02
 7973865882662013015    2.448e-06        VENUS    1.403e-02   -1.704e+01    3.046e+01    1.400e+00   -4.744e+03    3.499e-01   -3.179e-02
 9336316391706255048    3.040e-06     EARTHMOO    1.482e-02    2.845e+01    6.939e+00    1.967e-05   -4.744e+03   -9.875e-01   -4.543e-06
12320338445353835314    3.227e-07 [...]
{'fraction_non_alphanumeric': 0.14762132440831938, 'fraction_numerical': 0.1495338273966053, 'mean_word_length': 2.917134831460674, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 23, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '221511', 'license': 'CNRI-Python', 'n_tokens_mistral': 3574, 'n_tokens_neox': 2772, 'n_words': 753, 'path': 'Nemesis_and_the_Sun.ipynb', 'repo_name': 'spzwart/AMUSE-Tutorial', 'size': '8381'}