PdosPlot¶
[1]:
import sisl
import sisl.viz.plotly
# This is just for convenience to retreive files
siesta_files = sisl._environ.get_environ_variable("SISL_FILES_TESTS") / "sisl" / "io" / "siesta"
We are going to get the PDOS from a SIESTA .PDOS
file, but we could get it from a hamiltonian as well.
[2]:
plot = sisl.get_sile(siesta_files / "SrTiO3.PDOS").plot(Erange=[-10,10])
info:0: SislInfo:
The plot has been initialized correctly, but the current settings were not enough to generate the figure.
Error: Could not read or generate data for PdosPlot from any of the possible sources.
Here are the errors for each source:
- TB trans: TypeError.expected str, bytes or os.PathLike object, not NoneType
- hamiltonian: TypeError.expected str, bytes or os.PathLike object, not NoneType
- siesta output: FileNotFoundError.[Errno 2] No such file or directory: '_THIS_DIRECTORY_DOES_NOT_EXIST_/sisl/io/siesta/SrTiO3.PDOS'
By default, a PDOS plot shows the total density of states:
[3]:
plot
PDOS requests¶
There’s a very important setting in the PdosPlot
: requests
. This setting expects a list of PDOS requests, where each request is a dictionary that can specify - species
- atoms
- orbitals
(the orbital name) - n
, l
, m
(the quantum numbers) - Z
(the Z shell of the orbital) - spin
involved in the PDOS line that you want to draw. Apart from that, a request also accepts the name
, color
, linewidth
and dash
keys that manage the aesthetics of the line and normalize
, which indicates if the PDOS should be normalized (divided by number of orbitals).
Here is an example of how to use the requests
setting to create a line that displays the Oxygen 2p PDOS:
[4]:
plot.update_settings(requests=[{"name": "My first PDOS (Oxygen)", "species": ["O"], "n": 2, "l": 1}])
# or (it's equivalent)
plot.update_settings(requests=[{
"name": "My first PDOS (Oxygen)", "species": ["O"],
"orbitals": ["2pzZ1", "2pzZ2", "2pxZ1", "2pxZ2", "2pyZ1", "2pyZ2"]
}])
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_4610/1701002284.py in <module>
----> 1 plot.update_settings(requests=[{"name": "My first PDOS (Oxygen)", "species": ["O"], "n": 2, "l": 1}])
2 # or (it's equivalent)
3 plot.update_settings(requests=[{
4 "name": "My first PDOS (Oxygen)", "species": ["O"],
5 "orbitals": ["2pzZ1", "2pzZ2", "2pxZ1", "2pxZ2", "2pyZ1", "2pyZ2"]
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in update_settings(self, *args, **kwargs)
419 # the available kwargs for the plot class and provide more help to the user
420 def update_settings(self, *args, **kwargs):
--> 421 return self._update_settings(*args, **kwargs)
422
423 update_settings.__doc__ = f"Updates the settings of this plot.\n\nDocs for {new_cls.__name__}:\n\n{get_configurable_docstring(new_cls)}"
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in _update_settings(self, run_updates, **kwargs)
554 #Do things after updating the settings
555 if len(self.settings_history.last_updated) > 0 and run_updates:
--> 556 self._run_updates(self.settings_history.last_updated)
557
558 return self
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in _run_updates(self, for_keys)
582 # Execute the functions that we need to execute.
583 for f_name in func_names:
--> 584 getattr(self, f_name)()
585
586 return self
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plotutils.py in apply_to_all_plots(obj, childs_sel, *args, **kwargs)
817 else:
818
--> 819 return method(obj, *args, **kwargs)
820
821 return apply_to_all_plots
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in func(obj, *args, **kwargs)
881 def func(obj, *args, **kwargs):
882 getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 883 return method(obj, *args, **kwargs)
884
885 elif when == 'after':
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plot.py in set_data(self, update_fig, **kwargs)
1126 self._starting_traces = len(self.data)
1127
-> 1128 self._set_data()
1129
1130 if update_fig:
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in f_default_setting_args(self, *args, **kwargs)
962 pass
963
--> 964 return f(self, *args, **kwargs)
965
966 return f_default_setting_args
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plots/pdos.py in _set_data(self, requests, E0, Erange)
364
365 #Get only the part of the arra
--> 366 E_PDOS = self.PDOS.where(
367 (self.PDOS.E > Emin) & (self.PDOS.E < Emax), drop=True)
368
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plot.py in __getattr__(self, key)
734 pass
735
--> 736 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its figure, or in shared attributes.")
737
738 def __setattr__(self, key, val):
AttributeError: The attribute 'PDOS' was not found either in the plot, its figure, or in shared attributes.
And now we are going to create three lines, one for each species
[5]:
plot.update_settings(requests=[
{"name": "Oxygen", "species": ["O"], "color": "darkred", "dash": "dash", "normalize": True},
{"name": "Titanium", "species": ["Ti"], "color": "grey", "linewidth": 3, "normalize": True},
{"name": "Sr", "species": ["Sr"], "color": "green", "normalize": True},
], Erange=[-5, 5])
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_4610/4228651768.py in <module>
----> 1 plot.update_settings(requests=[
2 {"name": "Oxygen", "species": ["O"], "color": "darkred", "dash": "dash", "normalize": True},
3 {"name": "Titanium", "species": ["Ti"], "color": "grey", "linewidth": 3, "normalize": True},
4 {"name": "Sr", "species": ["Sr"], "color": "green", "normalize": True},
5 ], Erange=[-5, 5])
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in update_settings(self, *args, **kwargs)
419 # the available kwargs for the plot class and provide more help to the user
420 def update_settings(self, *args, **kwargs):
--> 421 return self._update_settings(*args, **kwargs)
422
423 update_settings.__doc__ = f"Updates the settings of this plot.\n\nDocs for {new_cls.__name__}:\n\n{get_configurable_docstring(new_cls)}"
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in _update_settings(self, run_updates, **kwargs)
554 #Do things after updating the settings
555 if len(self.settings_history.last_updated) > 0 and run_updates:
--> 556 self._run_updates(self.settings_history.last_updated)
557
558 return self
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in _run_updates(self, for_keys)
582 # Execute the functions that we need to execute.
583 for f_name in func_names:
--> 584 getattr(self, f_name)()
585
586 return self
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plotutils.py in apply_to_all_plots(obj, childs_sel, *args, **kwargs)
817 else:
818
--> 819 return method(obj, *args, **kwargs)
820
821 return apply_to_all_plots
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in func(obj, *args, **kwargs)
881 def func(obj, *args, **kwargs):
882 getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 883 return method(obj, *args, **kwargs)
884
885 elif when == 'after':
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plot.py in read_data(self, update_fig, **kwargs)
784
785 # We try to read from the different entry points available
--> 786 self._read_from_sources()
787
788 # We don't update the last dataread here in case there has been a succesful data read because we want to
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plot.py in _read_from_sources(self)
825 else:
826 self.source = None
--> 827 raise ValueError("Could not read or generate data for {} from any of the possible sources.\nHere are the errors for each source:\n{}"
828 .format(self.__class__.__name__, "\n".join(errors)))
829
ValueError: Could not read or generate data for PdosPlot from any of the possible sources.
Here are the errors for each source:
- TB trans: TypeError.expected str, bytes or os.PathLike object, not NoneType
- hamiltonian: TypeError.expected str, bytes or os.PathLike object, not NoneType
- siesta output: FileNotFoundError.[Errno 2] No such file or directory: '_THIS_DIRECTORY_DOES_NOT_EXIST_/sisl/io/siesta/SrTiO3.PDOS'
It’s interesting to note that the atoms
key of each request accepts the same possibilities as the atoms
argument of the Geometry
methods. Therefore, you can use indices, categories, dictionaries, strings…
For example:
[6]:
# Let's import the AtomZ and AtomOdd categories just to play with them
from sisl.geom import AtomZ, AtomOdd
plot.update_settings(requests=[
{"atoms": [0,1], "name": "Atoms 0 and 1"},
{"atoms": {"Z": 8}, "name": "Atoms with Z=8"},
{"atoms": AtomZ(8) & ~ AtomOdd(), "name": "Oxygens with even indices"}
])
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_4610/2426909493.py in <module>
2 from sisl.geom import AtomZ, AtomOdd
3
----> 4 plot.update_settings(requests=[
5 {"atoms": [0,1], "name": "Atoms 0 and 1"},
6 {"atoms": {"Z": 8}, "name": "Atoms with Z=8"},
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in update_settings(self, *args, **kwargs)
419 # the available kwargs for the plot class and provide more help to the user
420 def update_settings(self, *args, **kwargs):
--> 421 return self._update_settings(*args, **kwargs)
422
423 update_settings.__doc__ = f"Updates the settings of this plot.\n\nDocs for {new_cls.__name__}:\n\n{get_configurable_docstring(new_cls)}"
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in _update_settings(self, run_updates, **kwargs)
554 #Do things after updating the settings
555 if len(self.settings_history.last_updated) > 0 and run_updates:
--> 556 self._run_updates(self.settings_history.last_updated)
557
558 return self
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in _run_updates(self, for_keys)
582 # Execute the functions that we need to execute.
583 for f_name in func_names:
--> 584 getattr(self, f_name)()
585
586 return self
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plotutils.py in apply_to_all_plots(obj, childs_sel, *args, **kwargs)
817 else:
818
--> 819 return method(obj, *args, **kwargs)
820
821 return apply_to_all_plots
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in func(obj, *args, **kwargs)
881 def func(obj, *args, **kwargs):
882 getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 883 return method(obj, *args, **kwargs)
884
885 elif when == 'after':
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plot.py in set_data(self, update_fig, **kwargs)
1126 self._starting_traces = len(self.data)
1127
-> 1128 self._set_data()
1129
1130 if update_fig:
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in f_default_setting_args(self, *args, **kwargs)
962 pass
963
--> 964 return f(self, *args, **kwargs)
965
966 return f_default_setting_args
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plots/pdos.py in _set_data(self, requests, E0, Erange)
364
365 #Get only the part of the arra
--> 366 E_PDOS = self.PDOS.where(
367 (self.PDOS.E > Emin) & (self.PDOS.E < Emax), drop=True)
368
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plot.py in __getattr__(self, key)
734 pass
735
--> 736 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its figure, or in shared attributes.")
737
738 def __setattr__(self, key, val):
AttributeError: The attribute 'PDOS' was not found either in the plot, its figure, or in shared attributes.
Easy and fast DOS splitting¶
As you might have noticed, sometimes it might be cumbersome to build all the requests you want. If your needs are simple and you don’t need the flexibility of defining every parameter by yourself, there is a set of methods that will help you explore your PDOS data faster than ever before. These are: split_DOS
, split_requests
, update_requests
, remove_requests
and add_requests
.?
Let’s begin with split_DOS
. As you can imagine, this method splits the density of states:
[7]:
plot.split_DOS()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_4610/3569591731.py in <module>
----> 1 plot.split_DOS()
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plots/pdos.py in split_DOS(self, on, only, exclude, clean, **kwargs)
742 >>> plot.split_DOS(on="n+l", species=["Au"], name="Au $ns")
743 """
--> 744 requests = self.get_param('requests')._generate_queries(
745 on=on, only=only, exclude=exclude, query_gen=self._new_request, **kwargs)
746
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _generate_queries(self, on, only, exclude, query_gen, **kwargs)
458 only those that belong to carbon atoms.
459 """
--> 460 return self._split_query({}, on=on, only=only, exclude=exclude, query_gen=query_gen, **kwargs)
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _split_query(self, query, on, only, exclude, query_gen, ignore_constraints, **kwargs)
378
379 # Knowing what are our constraints (which may be none), get the available options
--> 380 values = self.get_options("+".join(on), **constraints)
381
382 # We are going to make sure that, even if there was only one parameter to split on,
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in get_options(self, key, **kwargs)
259 """
260 # Get the tadatframe
--> 261 df = self.orb_filtering_df
262
263 # Filter the dataframe according to the constraints imposed by the kwargs,
AttributeError: 'OrbitalQueries' object has no attribute 'orb_filtering_df'
By default, it splits on the different species, but you can use the on
argument to change that.
[8]:
plot.split_DOS(on="atoms")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_4610/3590190964.py in <module>
----> 1 plot.split_DOS(on="atoms")
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plots/pdos.py in split_DOS(self, on, only, exclude, clean, **kwargs)
742 >>> plot.split_DOS(on="n+l", species=["Au"], name="Au $ns")
743 """
--> 744 requests = self.get_param('requests')._generate_queries(
745 on=on, only=only, exclude=exclude, query_gen=self._new_request, **kwargs)
746
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _generate_queries(self, on, only, exclude, query_gen, **kwargs)
458 only those that belong to carbon atoms.
459 """
--> 460 return self._split_query({}, on=on, only=only, exclude=exclude, query_gen=query_gen, **kwargs)
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _split_query(self, query, on, only, exclude, query_gen, ignore_constraints, **kwargs)
378
379 # Knowing what are our constraints (which may be none), get the available options
--> 380 values = self.get_options("+".join(on), **constraints)
381
382 # We are going to make sure that, even if there was only one parameter to split on,
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in get_options(self, key, **kwargs)
259 """
260 # Get the tadatframe
--> 261 df = self.orb_filtering_df
262
263 # Filter the dataframe according to the constraints imposed by the kwargs,
AttributeError: 'OrbitalQueries' object has no attribute 'orb_filtering_df'
Now we have the contribution of each atom.
But here comes the powerful part: split_DOS
accepts as keyword arguments all the keys that a request accepts. Then, it adds that extra constrain to the splitting by adding the value to each request. So, if we want to get the separate contributions of all oxygen atoms, we can impose an extra constraint on species:
[9]:
plot.split_DOS(on="atoms", species=["O"], name="Oxygen $atoms")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_4610/2490990499.py in <module>
----> 1 plot.split_DOS(on="atoms", species=["O"], name="Oxygen $atoms")
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plots/pdos.py in split_DOS(self, on, only, exclude, clean, **kwargs)
742 >>> plot.split_DOS(on="n+l", species=["Au"], name="Au $ns")
743 """
--> 744 requests = self.get_param('requests')._generate_queries(
745 on=on, only=only, exclude=exclude, query_gen=self._new_request, **kwargs)
746
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _generate_queries(self, on, only, exclude, query_gen, **kwargs)
458 only those that belong to carbon atoms.
459 """
--> 460 return self._split_query({}, on=on, only=only, exclude=exclude, query_gen=query_gen, **kwargs)
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _split_query(self, query, on, only, exclude, query_gen, ignore_constraints, **kwargs)
378
379 # Knowing what are our constraints (which may be none), get the available options
--> 380 values = self.get_options("+".join(on), **constraints)
381
382 # We are going to make sure that, even if there was only one parameter to split on,
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in get_options(self, key, **kwargs)
259 """
260 # Get the tadatframe
--> 261 df = self.orb_filtering_df
262
263 # Filter the dataframe according to the constraints imposed by the kwargs,
AttributeError: 'OrbitalQueries' object has no attribute 'orb_filtering_df'
and then we have only the oxygen atoms, which are all equivalent.
Note that we also set a name for all requests, with the additional twist that we used the templating supported by split_DOS
. If you are splitting on parameter
, you can use $parameter
inside your name and the method will replace it with the value for each request. In this case parameter
was atoms
, but it could be anything you are splitting the DOS on.
You can also exclude some values of the parameter you are splitting on:
[10]:
plot.split_DOS(on="atoms", exclude=[1,3])
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_4610/4016990935.py in <module>
----> 1 plot.split_DOS(on="atoms", exclude=[1,3])
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plots/pdos.py in split_DOS(self, on, only, exclude, clean, **kwargs)
742 >>> plot.split_DOS(on="n+l", species=["Au"], name="Au $ns")
743 """
--> 744 requests = self.get_param('requests')._generate_queries(
745 on=on, only=only, exclude=exclude, query_gen=self._new_request, **kwargs)
746
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _generate_queries(self, on, only, exclude, query_gen, **kwargs)
458 only those that belong to carbon atoms.
459 """
--> 460 return self._split_query({}, on=on, only=only, exclude=exclude, query_gen=query_gen, **kwargs)
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _split_query(self, query, on, only, exclude, query_gen, ignore_constraints, **kwargs)
378
379 # Knowing what are our constraints (which may be none), get the available options
--> 380 values = self.get_options("+".join(on), **constraints)
381
382 # We are going to make sure that, even if there was only one parameter to split on,
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in get_options(self, key, **kwargs)
259 """
260 # Get the tadatframe
--> 261 df = self.orb_filtering_df
262
263 # Filter the dataframe according to the constraints imposed by the kwargs,
AttributeError: 'OrbitalQueries' object has no attribute 'orb_filtering_df'
Or indicate the only values that you want:
[11]:
plot.split_DOS(on="atoms", only=[0,2])
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_4610/3410607585.py in <module>
----> 1 plot.split_DOS(on="atoms", only=[0,2])
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plots/pdos.py in split_DOS(self, on, only, exclude, clean, **kwargs)
742 >>> plot.split_DOS(on="n+l", species=["Au"], name="Au $ns")
743 """
--> 744 requests = self.get_param('requests')._generate_queries(
745 on=on, only=only, exclude=exclude, query_gen=self._new_request, **kwargs)
746
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _generate_queries(self, on, only, exclude, query_gen, **kwargs)
458 only those that belong to carbon atoms.
459 """
--> 460 return self._split_query({}, on=on, only=only, exclude=exclude, query_gen=query_gen, **kwargs)
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _split_query(self, query, on, only, exclude, query_gen, ignore_constraints, **kwargs)
378
379 # Knowing what are our constraints (which may be none), get the available options
--> 380 values = self.get_options("+".join(on), **constraints)
381
382 # We are going to make sure that, even if there was only one parameter to split on,
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in get_options(self, key, **kwargs)
259 """
260 # Get the tadatframe
--> 261 df = self.orb_filtering_df
262
263 # Filter the dataframe according to the constraints imposed by the kwargs,
AttributeError: 'OrbitalQueries' object has no attribute 'orb_filtering_df'
Finally, if you want to split on multiple parameters at the same time, you can use +
between different parameters. For example, to get all the oxygen orbitals:
[12]:
plot.split_DOS(on="n+l+m", species=["O"], name="Oxygen")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_4610/3210370979.py in <module>
----> 1 plot.split_DOS(on="n+l+m", species=["O"], name="Oxygen")
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plots/pdos.py in split_DOS(self, on, only, exclude, clean, **kwargs)
742 >>> plot.split_DOS(on="n+l", species=["Au"], name="Au $ns")
743 """
--> 744 requests = self.get_param('requests')._generate_queries(
745 on=on, only=only, exclude=exclude, query_gen=self._new_request, **kwargs)
746
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _generate_queries(self, on, only, exclude, query_gen, **kwargs)
458 only those that belong to carbon atoms.
459 """
--> 460 return self._split_query({}, on=on, only=only, exclude=exclude, query_gen=query_gen, **kwargs)
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _split_query(self, query, on, only, exclude, query_gen, ignore_constraints, **kwargs)
378
379 # Knowing what are our constraints (which may be none), get the available options
--> 380 values = self.get_options("+".join(on), **constraints)
381
382 # We are going to make sure that, even if there was only one parameter to split on,
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in get_options(self, key, **kwargs)
259 """
260 # Get the tadatframe
--> 261 df = self.orb_filtering_df
262
263 # Filter the dataframe according to the constraints imposed by the kwargs,
AttributeError: 'OrbitalQueries' object has no attribute 'orb_filtering_df'
Managing existing requests¶
Not only you can create requests easily with split_DOS
, but it’s also easy to manage the requests that you have created.
The methods that help you accomplish this are split_requests
, update_requests
, remove_requests
. All three methods accept an undefined number of arguments that are used to select the requests you want to act on. You can refer to requests by their name (using a str
) or their position (using an int
). It’s very easy to understand with examples. Then, keyword arguments depend on the functionality of each method.
For example, let’s say that we have splitted the DOS on species
[13]:
plot.split_DOS(name="$species")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_4610/2101396501.py in <module>
----> 1 plot.split_DOS(name="$species")
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plots/pdos.py in split_DOS(self, on, only, exclude, clean, **kwargs)
742 >>> plot.split_DOS(on="n+l", species=["Au"], name="Au $ns")
743 """
--> 744 requests = self.get_param('requests')._generate_queries(
745 on=on, only=only, exclude=exclude, query_gen=self._new_request, **kwargs)
746
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _generate_queries(self, on, only, exclude, query_gen, **kwargs)
458 only those that belong to carbon atoms.
459 """
--> 460 return self._split_query({}, on=on, only=only, exclude=exclude, query_gen=query_gen, **kwargs)
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _split_query(self, query, on, only, exclude, query_gen, ignore_constraints, **kwargs)
378
379 # Knowing what are our constraints (which may be none), get the available options
--> 380 values = self.get_options("+".join(on), **constraints)
381
382 # We are going to make sure that, even if there was only one parameter to split on,
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in get_options(self, key, **kwargs)
259 """
260 # Get the tadatframe
--> 261 df = self.orb_filtering_df
262
263 # Filter the dataframe according to the constraints imposed by the kwargs,
AttributeError: 'OrbitalQueries' object has no attribute 'orb_filtering_df'
and we want to remove the Sr and O lines. That’s easy:
[14]:
plot.remove_requests("Sr", 2)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_4610/491162076.py in <module>
----> 1 plot.remove_requests("Sr", 2)
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plots/pdos.py in remove_requests(self, all, update_fig, *i_or_names)
548 requests = [req for i, req in enumerate(self.get_setting("requests", copy=False)) if not self._matches_request(req, i_or_names, i)]
549
--> 550 return self.update_settings(run_updates=update_fig, requests=requests)
551
552 def update_requests(self, *i_or_names, **kwargs):
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in update_settings(self, *args, **kwargs)
419 # the available kwargs for the plot class and provide more help to the user
420 def update_settings(self, *args, **kwargs):
--> 421 return self._update_settings(*args, **kwargs)
422
423 update_settings.__doc__ = f"Updates the settings of this plot.\n\nDocs for {new_cls.__name__}:\n\n{get_configurable_docstring(new_cls)}"
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in _update_settings(self, run_updates, **kwargs)
554 #Do things after updating the settings
555 if len(self.settings_history.last_updated) > 0 and run_updates:
--> 556 self._run_updates(self.settings_history.last_updated)
557
558 return self
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in _run_updates(self, for_keys)
582 # Execute the functions that we need to execute.
583 for f_name in func_names:
--> 584 getattr(self, f_name)()
585
586 return self
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plotutils.py in apply_to_all_plots(obj, childs_sel, *args, **kwargs)
817 else:
818
--> 819 return method(obj, *args, **kwargs)
820
821 return apply_to_all_plots
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in func(obj, *args, **kwargs)
881 def func(obj, *args, **kwargs):
882 getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 883 return method(obj, *args, **kwargs)
884
885 elif when == 'after':
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plot.py in set_data(self, update_fig, **kwargs)
1126 self._starting_traces = len(self.data)
1127
-> 1128 self._set_data()
1129
1130 if update_fig:
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/configurable.py in f_default_setting_args(self, *args, **kwargs)
962 pass
963
--> 964 return f(self, *args, **kwargs)
965
966 return f_default_setting_args
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plots/pdos.py in _set_data(self, requests, E0, Erange)
364
365 #Get only the part of the arra
--> 366 E_PDOS = self.PDOS.where(
367 (self.PDOS.E > Emin) & (self.PDOS.E < Emax), drop=True)
368
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plot.py in __getattr__(self, key)
734 pass
735
--> 736 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its figure, or in shared attributes.")
737
738 def __setattr__(self, key, val):
AttributeError: The attribute 'PDOS' was not found either in the plot, its figure, or in shared attributes.
We have indicated that we wanted to remove the request with name "Sr"
and the 2nd request. Simple, isn’t it?
Now that we know how to indicate the requests that we want to act on, let’s use it to get the total Sr
contribution, and then the Ti
and O
contributions splitted by n
and l
.
It sounds difficult, but it’s actually not. Just split the DOS on species:
[15]:
plot.split_DOS(name="$species", normalize=True)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_4610/1783703930.py in <module>
----> 1 plot.split_DOS(name="$species", normalize=True)
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plots/pdos.py in split_DOS(self, on, only, exclude, clean, **kwargs)
742 >>> plot.split_DOS(on="n+l", species=["Au"], name="Au $ns")
743 """
--> 744 requests = self.get_param('requests')._generate_queries(
745 on=on, only=only, exclude=exclude, query_gen=self._new_request, **kwargs)
746
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _generate_queries(self, on, only, exclude, query_gen, **kwargs)
458 only those that belong to carbon atoms.
459 """
--> 460 return self._split_query({}, on=on, only=only, exclude=exclude, query_gen=query_gen, **kwargs)
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in _split_query(self, query, on, only, exclude, query_gen, ignore_constraints, **kwargs)
378
379 # Knowing what are our constraints (which may be none), get the available options
--> 380 values = self.get_options("+".join(on), **constraints)
381
382 # We are going to make sure that, even if there was only one parameter to split on,
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/input_fields/queries.py in get_options(self, key, **kwargs)
259 """
260 # Get the tadatframe
--> 261 df = self.orb_filtering_df
262
263 # Filter the dataframe according to the constraints imposed by the kwargs,
AttributeError: 'OrbitalQueries' object has no attribute 'orb_filtering_df'
And then use split_requests
to split only the requests that we want to split:
[16]:
plot.split_requests("Sr", 2, on="n+l", dash="dot")
Notice how we’ve also set dash
for all the requests that split_requests
has generated. We can do this because split_requests
works exactly as split_DOS
, with the only difference that splits specific requests.
Just as a last thing, we will let you figure out how update_requests
works:
[17]:
plot.update_requests("Ti", color="red", linewidth=2)
We hope you enjoyed what you learned!
This next cell is just to create the thumbnail for the notebook in the docs
[18]:
thumbnail_plot = plot.update_requests("Ti", color=None, linewidth=1)
if thumbnail_plot:
thumbnail_plot.show("png")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_4610/3186451907.py in <module>
2
3 if thumbnail_plot:
----> 4 thumbnail_plot.show("png")
~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plot.py in show(self, listen, return_figWidget, *args, **kwargs)
1187 warn(e)
1188
-> 1189 return self.figure.show(*args, **kwargs)
1190
1191 def _ipython_display_(self, return_figWidget=False, **kwargs):
~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.11.0/lib/python3.8/site-packages/plotly/basedatatypes.py in show(self, *args, **kwargs)
3396 import plotly.io as pio
3397
-> 3398 return pio.show(self, *args, **kwargs)
3399
3400 def to_json(self, *args, **kwargs):
~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.11.0/lib/python3.8/site-packages/plotly/io/_renderers.py in show(fig, renderer, validate, **kwargs)
387
388 # Mimetype renderers
--> 389 bundle = renderers._build_mime_bundle(fig_dict, renderers_string=renderer, **kwargs)
390 if bundle:
391 if not ipython_display:
~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.11.0/lib/python3.8/site-packages/plotly/io/_renderers.py in _build_mime_bundle(self, fig_dict, renderers_string, **kwargs)
295 setattr(renderer, k, v)
296
--> 297 bundle.update(renderer.to_mimebundle(fig_dict))
298
299 return bundle
~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.11.0/lib/python3.8/site-packages/plotly/io/_base_renderers.py in to_mimebundle(self, fig_dict)
126
127 def to_mimebundle(self, fig_dict):
--> 128 image_bytes = to_image(
129 fig_dict,
130 format=self.format,
~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.11.0/lib/python3.8/site-packages/plotly/io/_kaleido.py in to_image(fig, format, width, height, scale, validate, engine)
132 # Raise informative error message if Kaleido is not installed
133 if scope is None:
--> 134 raise ValueError(
135 """
136 Image export using the "kaleido" engine requires the kaleido package,
ValueError:
Image export using the "kaleido" engine requires the kaleido package,
which can be installed using pip:
$ pip install -U kaleido