diff --git a/README.rst b/README.rst index ef4a09a4defd306897174acf34e7c691d1b11b2d..9be12f1ed019627bad89a38cf3880892ec1d557e 100644 --- a/README.rst +++ b/README.rst @@ -127,11 +127,11 @@ FILES | │  ├── ruptured_Pd.xml # a fcc(100) like surface with some sites missing | │  └── small.xml # demo file | ├── tests/ # Unit tests and test data -| └── tools # Entry points for command line interface -| ├── kmcos -| ├── kmcos.bat -| ├── kmcos-build-standalone -| └── kmcos-install-dependencies-ubuntu +| ├── tools # Entry points for command line interface +| │  ├── kmcos +| │  ├── kmcos.bat +| │  ├── kmcos-build-standalone +| │  └── kmcos-install-dependencies-ubuntu COPYRIGHT AND LICENSE diff --git a/examples/0-README_for_Examples200423.txt b/examples/0-README_for_Examples200423.txt index 01de53992c384d7863a84f5e35f1caf911eeea1a..0576b8d38b4efcc3fc0c54ba0a5c63173d1fe38c 100644 --- a/examples/0-README_for_Examples200423.txt +++ b/examples/0-README_for_Examples200423.txt @@ -8,7 +8,7 @@ Below is a list of the examples, then explanation of how to use them. To use one of the examples, follow this type of procedure: -python3 MyFirstSnapshots.py +python3 MyFirstSnapshots__build.py cd MyFirstSnapshots_local_smart python3 runfile.py diff --git a/examples/MyFirstDiffusion_local_smart/runfile_atoms_export.py b/examples/MyFirstDiffusion_local_smart/runfile_atoms_export.py new file mode 100644 index 0000000000000000000000000000000000000000..4d628ffbd209e6a89e3785e249f8d25101dcd28a --- /dev/null +++ b/examples/MyFirstDiffusion_local_smart/runfile_atoms_export.py @@ -0,0 +1,7 @@ +import pickle +from kmcos.run import KMC_Model + +model = KMC_Model() +NSTEPS = 1e6 +model.do_steps(NSTEPS) +model.pickle_export_atoms("MyFirstDiffusion_atoms_" + str(NSTEPS) + ".pkl") \ No newline at end of file diff --git a/examples/MyFirstDiffusion_local_smart/runfile_atoms_import.py b/examples/MyFirstDiffusion_local_smart/runfile_atoms_import.py new file mode 100644 index 0000000000000000000000000000000000000000..8a8c3a082b990f734304cb4ba24187b7908df6f7 --- /dev/null +++ b/examples/MyFirstDiffusion_local_smart/runfile_atoms_import.py @@ -0,0 +1,7 @@ +from ase.io import write +import pickle + +filehandler = open('MyFirstDiffusion_atoms_1000000.0.pkl', 'rb') +loaded_atoms_object = pickle.load(filehandler) +filehandler.close() +write('MyFirstDiffusion_atoms_1000000.0.png', loaded_atoms_object) diff --git a/examples/MyFirstSnapshots_local_smart/runfile.py b/examples/MyFirstSnapshots_local_smart/runfile.py index 7974c45e7c33d2b6da3dcf56912725ff8b39306f..4600417b93ca17949f5158a5a36dbd1ca689db0d 100644 --- a/examples/MyFirstSnapshots_local_smart/runfile.py +++ b/examples/MyFirstSnapshots_local_smart/runfile.py @@ -42,8 +42,15 @@ do_snapshots(sps, n_snapshots) #The final command below writes the simulation details to the logfile create_log() +# plot_configuration(self, filename = '', resolution = 150, scale = 20, representation = '', plot_settings = {}): + #The first plot_configuration will use default arguments to construct the plot and export as "plottedConfiguration.png" -sg.model.plot_configuration() +#sg.model.plot_configuration() + +#The second plot_configuration will use the atomic argument to contruct the plot and export as "atomic_view.png" +#for the filename, you can specify with or without the .png at the end. This function will automatically convert to .png file +sg.model.plot_configuration(filename='MyFirstSnapshots_atomic_view', resolution=100, scale=20, representation='atomic') + plot_settings = { "y_label": "y_direction", @@ -58,4 +65,5 @@ plot_settings = { "num_y_ticks": 3, } #the second plot_configuration here will construct the plot using the above dictionary and export the file as "Plot.png" -sg.model.plot_configuration(plot_settings) +# Note that the spatial representation plots by default, but you can always specify in representation +sg.model.plot_configuration(representation='spatial', plot_settings=plot_settings) \ No newline at end of file diff --git a/kmcos/__init__.py b/kmcos/__init__.py index 8906ac5d5a852b34018c3cfd9042bdd8eb226c96..d8f244700906566ec2d4a25297a399a967e890de 100644 --- a/kmcos/__init__.py +++ b/kmcos/__init__.py @@ -56,7 +56,8 @@ from __future__ import print_function #import kmcos.io -__version__ = "0.0.64" + +__version__ = "0.0.66" VERSION = __version__ def evaluate_param_expression(param, parameters={}): diff --git a/kmcos/run/__init__.py b/kmcos/run/__init__.py index 509f7893d4364197c5b3216c25041998415bef1d..ae5cae90edcdcb2382d095069494142c4eb7db23 100644 --- a/kmcos/run/__init__.py +++ b/kmcos/run/__init__.py @@ -930,13 +930,16 @@ class KMC_Model(Process): print('Wrote {filename}'.format(**locals())) self.do_steps(skip) - def show(self, *args, **kwargs): + def peek(self, *args, **kwargs): """Visualize the current configuration of the model using ASE ag.""" tag = kwargs.pop('tag', None) ase = import_ase() ase.visualize.view(self.get_atoms(tag=tag), *args, **kwargs) + def show(self): + return self.peek() + def view(self, scaleA = None): """Start current model in live view mode.""" from kmcos import view @@ -1558,9 +1561,17 @@ class KMC_Model(Process): if showFigure==False: plt.close(fig0) return fig0, ax0 + + def export_picture(self, filename, resolution, scale, **kwargs): + atoms = self.get_atoms(reset_time_overrun = False) #here, the self is the KMC_Model object + kmcos.run.png.MyPNG(atoms, show_unit_cell=False, scale=scale, model=self, **kwargs).write(filename=filename, resolution=resolution) + return - def plot_configuration(self, plot_settings = {}): + def plot_configuration(self, filename = '', resolution = 150, scale = 20, representation = 'spatial', plot_settings = {}): """ + representation is an optional argument for spatial and atomic view + You should specify as 'atomic' to see the atomic view. Leaving representation empty returns spatial view by default. + plot_settings is a dictionary that allows for the plot to change given the arguements EX: "y_label": "test", @@ -1572,12 +1583,24 @@ class KMC_Model(Process): "dpi": 220, "speciesName": False plot_configuration will make a graph named 'plottedConfiguration.png,' unless specified by 'figure_name' in plot_settings - """ - config = self._get_configuration().tolist() - species = self.species_tags - species_coordinates = self.get_species_coordinates(config, species) - self.create_plot(species_coordinates, species, plot_settings) - + """ + if representation == 'atomic': + if 'show_unit_cell' in plot_settings: + show_unit_cell = plot_settings['show_unit_cell'] + else: + show_unit_cell = True + if 'kwargs' in plot_settings: + kwargs = plot_settings['kwargs'] + else: + kwargs = {} #default for kwargs is a blank dictionary + self.export_picture(filename = filename, resolution = resolution, scale = scale) + + if (representation == 'spatial') or (representation == 'circles'): + config = self._get_configuration().tolist() + species = self.species_tags + species_coordinates = self.get_species_coordinates(config, species) + self.create_plot(species_coordinates, species, plot_settings) + def _put(self, site, new_species, reduce=False): """ Works exactly like put, but without updating the database of @@ -1983,6 +2006,21 @@ class KMC_Model(Process): self._set_configuration(config) self._adjust_database() + def pickle_export_atoms(self, filename = ""): + # takes atoms object in filename and turns it into a .pkl file + import pickle + if filename == "": + filename = "atoms_export.pkl" + else: + if filename[-4:] == '.pkl': + filename.replace('.pkl', '.pkl') + else: + filename = filename + '.pkl' + filehandler = open(filename, 'wb') + pickle.dump(self.get_atoms(), filehandler) + filehandler.close() + + class Model_Parameters(object): """Holds all user defined parameters of a model in concise form. All user defined parameters can be diff --git a/kmcos/run/png.py b/kmcos/run/png.py index 39e6d93d045582d68dd313d90326a9ebfefaa30c..f2030c34eb354bd1653b4d7b5d0ba9c88bed870f 100644 --- a/kmcos/run/png.py +++ b/kmcos/run/png.py @@ -16,6 +16,7 @@ class MyPNG(PNG): model=None, scale=20) : + self.atoms = atoms self.numbers = atoms.get_atomic_numbers() self.colors = colors self.model = model @@ -114,7 +115,6 @@ class MyPNG(PNG): self.filename = filename self.write_header(resolution=resolution) self.write_info() - self.write_body() self.write_trailer(resolution=resolution) def write_info(self): @@ -140,8 +140,9 @@ class MyPNG(PNG): text.draw(self.renderer) def write_header(self, resolution=72): - from matplotlib.backends.backend_agg import RendererAgg, Figure + from matplotlib.backends.backend_agg import RendererAgg from matplotlib.backend_bases import GraphicsContextBase + from matplotlib.figure import Figure try: from matplotlib.transforms import Value @@ -157,23 +158,20 @@ class MyPNG(PNG): self.gc.set_linewidth(.2) def write_trailer(self, resolution=72): + import matplotlib renderer = self.renderer if hasattr(renderer._renderer, 'write_png'): # Old version of matplotlib: renderer._renderer.write_png(self.filename) else: - from matplotlib import _png - # buffer_rgba does not accept arguments from version 1.2.0 - # https://github.com/matplotlib/matplotlib/commit/f4fee350f9fbc639853bee76472d8089a10b40bd - import matplotlib - if matplotlib.__version__ < '1.2.0': - x = renderer._renderer.buffer_rgba(0, 0) - _png.write_png(renderer._renderer.buffer_rgba(0, 0), - renderer.width, renderer.height, - self.filename, resolution) + from ase.io import write + #self.atoms.rotate(a=0.5, (0,1,0), rotate_self=True) + if self.filename == "": + write('atomic_view.png', self.atoms) else: - x = renderer._renderer.buffer_rgba() - _png.write_png(renderer._renderer.buffer_rgba(), - #renderer.width, renderer.height, - self.filename, resolution) + if self.filename[-4:] == '.png': + self.filename.replace('.png', '.png') + else: + self.filename = self.filename + '.png' + write(self.filename, self.atoms)