How to add groups for group distribution plot?

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
[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”

Load previusly saved results, computed in the previous script

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

Plot with two subplots


Plot the total mddf

movavg(results.mddf,n=10).x, # Smooth example with a running average

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

Thanks in advance

1 Like

You error is unrelated to the plotting, and only has ro do with SolventGroup not being defined. I can see from here 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:

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 :slight_smile:

1 Like

@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

import Pkg; Pkg.update()

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

1 Like

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


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.