# How to add groups for group distribution plot?

**URL:** <https://discourse.julialang.org/t/how-to-add-groups-for-group-distribution-plot/112119>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 26, 2024, 3:45am UTC](https://discourse.julialang.org/t/how-to-add-groups-for-group-distribution-plot/112119 "2024-03-26T03:45:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![faizanazar](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@faizanazar](https://discourse.julialang.org/u/faizanazar)\
**Post date:** [March 26, 2024, 3:45am UTC](https://discourse.julialang.org/t/how-to-add-groups-for-group-distribution-plot/112119/1 "2024-03-26T03:45:45Z")

</div>

Hello !  
I am new to julia programming language and I am trying to do tutorial for group distribution plot as mentioned in the script but everytime I am getting an error of UndefVarError: SolventGroup not defined  
Stacktrace:  
[1] top-level scope  
@ ./REPL[38]:2

Kindly help me out to resolve this error. Here is the input

import Pkg; Pkg.activate(“.”)  
using ComplexMixtures  
using Plots  
using LaTeXStrings  
using EasyFit: movavg

# Some default settings for the plots

plot\_font = “Computer Modern”  
Plots.default(  
fontfamily=plot\_font,  
linewidth=1.5,  
framestyle=:box,  
label=nothing,  
grid=false,  
)

# Load previusly saved results, computed in the previous script

results = load(“./mddf.json”)

# Plot with two subplots

plot(layout=(2,1))

# Plot the total mddf

plot!(  
results.d,  
movavg(results.mddf,n=10).x, # Smooth example with a running average  
label=“Total”,  
subplot=1  
)

# Plot DMF group contributions to the MDDF. We use a dictionary where

# the keys are the group names, and the values are the atom names of the group

groups = (  
“CO” =\> [“C”,“O”], # carbonyl  
“N” =\> [“N”],  
“Methyl groups” =\> [“CC”,“CT”,“HC1”,“HC2”,“HC3”,“HT1”,“HT2”,“HT3”],  
)  
for (group\_label, group\_atoms) in groups  
# Retrieve the contributions of the atoms of this group  
group\_contrib = contributions(results, SolventGroup(group\_atoms))  
# Plot the contributions of this groups, with the appropriate label  
plot!(  
results.d,  
movavg(group\_contrib,n=10).x,  
label=group\_label,  
subplot=1  
)  
end

Thanks in advance

---

<div class="post-metadata">

**Author:** ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Post date:** [March 26, 2024, 7:38am UTC](https://discourse.julialang.org/t/how-to-add-groups-for-group-distribution-plot/112119/2 "2024-03-26T07:38:49Z")

</div>

> [@faizanazar](#):
>
> ComplexMixtures

You error is unrelated to the plotting, and only has ro do with SolventGroup not being defined. I can see from [here](https://m3g.github.io/ComplexMixtures.jl/stable/selection/#ComplexMixtures.SolventGroup) that the structure exists in the package you load. Can you try doing `ComplexMixtures.SolventGroup`, i.e. access the type from the module `ComplexMixtures`? This is requires if the package does not export `SolventGroup`.

Ps: always post code enclosed in single backticks for inline code (`code here`), or triple backticks for multiline code:

```julia
code_here = true

```

A backtick is the ` symbol. Preview your comments/posts to check the formatting - most people mess it up the first few times 🙂

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [March 26, 2024, 11:53pm UTC](https://discourse.julialang.org/t/how-to-add-groups-for-group-distribution-plot/112119/3 "2024-03-26T23:53:19Z")

</div>

@faizanazar, I’m the developer of the package. It’s late now here, but tomorrow I’ll answer you carefully.

Let me know of any other difficulty you might be having with the package.

Edit: I don’t see anything wrong in principle with the code. It should work. Can you try updating the package, with

```julia
import Pkg; Pkg.update()

```

The `SolventGroup` type was implemented in version 2, it should be available unless you are running an 1.X version.

---

<div class="post-metadata">

**Author:** ![faizanazar](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@faizanazar](https://discourse.julialang.org/u/faizanazar)\
**Post date:** [March 28, 2024, 4:30am UTC](https://discourse.julialang.org/t/how-to-add-groups-for-group-distribution-plot/112119/4 "2024-03-28T04:30:26Z")

</div>

Thank you so much everyone. Now it is working simply I used this  
for group in groups  
# Retrieve the contributions of the atoms of this group  
group\_contrib = contributions(solvent,results.solvent\_atom,group[1])  
y = movavg(group\_contrib,n=10).x  
plot!(x,y,label=group[2],subplot=1)  
end

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [April 3, 2024, 3:53pm UTC](https://discourse.julialang.org/t/how-to-add-groups-for-group-distribution-plot/112119/5 "2024-04-03T15:53:53Z")

</div>

You are using a version 1.X of the package, which is not the latest one.

You can use without problems, but then be careful in following the corresponding manual. The version of the manual is written in the bottom left of the manual pages.

If I may guess, you ended up using that version because the Julia version you are using is old. If you had a Julia version 1.9 or greater, you would have installed the latest version of ComplexMixtures.

Please message me if you need any support. You can send a message here or send me a DM. It is my greatest interest that users find the package useful and easy to use.
