Spaces:
Running
Running
Upload 4 files
Browse filesFiles changed (4)
- 1.pngAdded
- NdSiRu.cifAdded+50
- app.pyAdded+118
- requirements.txtAdded+1
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950# generated using pymatgendata_NdSiRu_symmetry_space_group_name_H-M P4/nmm_cell_length_a 4.22194715_cell_length_b 4.22194715_cell_length_c 6.93978618_cell_angle_alpha 90.00000000_cell_angle_beta 90.00000000_cell_angle_gamma 90.00000000_symmetry_Int_Tables_number 129_chemical_formula_structural NdSiRu_chemical_formula_sum 'Nd2 Si2 Ru2'_cell_volume 123.70056259_cell_formula_units_Z 2loop_ _symmetry_equiv_pos_site_id _symmetry_equiv_pos_as_xyz 1 'x, y, z' 2 '-y+1/2, x+1/2, z' 3 '-x, -y, z' 4 'y+1/2, -x+1/2, z' 5 'x+1/2, -y+1/2, -z' 6 '-y, -x, -z' 7 '-x+1/2, y+1/2, -z' 8 'y, x, -z' 9 '-x+1/2, -y+1/2, -z' 10 'y, -x, -z' 11 'x+1/2, y+1/2, -z' 12 '-y, x, -z' 13 '-x, y, z' 14 'y+1/2, x+1/2, z' 15 'x, -y, z' 16 '-y+1/2, -x+1/2, z'loop_ _atom_type_symbol _atom_type_oxidation_number Nd2+ 2.0 Si4- -4.0 Ru2+ 2.0loop_ _atom_site_type_symbol _atom_site_label _atom_site_symmetry_multiplicity _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy Nd2+ Nd0 2 0.00000000 0.50000000 0.31849090 1 Si4- Si1 2 0.00000000 0.50000000 0.82833210 1 Ru2+ Ru2 2 0.00000000 0.00000000 0.00000000 1123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118import gradio as grfrom slices.core import SLICESfrom pymatgen.core.structure import Structurefrom pymatgen.io.cif import CifWriterfrom pymatgen.io.ase import AseAtomsAdaptorfrom ase.io import write as ase_writeimport tempfilefrom pymatgen.symmetry.analyzer import SpacegroupAnalyzerimport os# Initialize SLICES backendbackend = SLICES(relax_model="chgnet", fmax=0.4, steps=25)
def wrap_structure(structure): """Wrap all atoms back into the unit cell.""" for i, site in enumerate(structure): frac_coords = site.frac_coords % 1.0 structure.replace(i, species=site.species, coords=frac_coords, coords_are_cartesian=False) return structure
def get_primitive_structure(structure): """Convert the structure to its primitive cell.""" analyzer = SpacegroupAnalyzer(structure) return analyzer.get_primitive_standard_structure()
def visualize_structure(structure): """Generate an image of the structure.""" atoms = AseAtomsAdaptor.get_atoms(structure) with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as temp_file: ase_write(temp_file.name, atoms, format='png', rotation='10x,10y,10z') return temp_file.name
def process_structure(structure): """Wrap and convert to primitive cell.""" structure = wrap_structure(structure) return get_primitive_structure(structure)
def cif_to_slices(cif_file): try: structure = Structure.from_file(cif_file.name) structure = process_structure(structure) slices_string = backend.structure2SLICES(structure) image_file = visualize_structure(structure) return slices_string, image_file, None, slices_string, slices_string # Added another slices_string for aug_slices_input except Exception as e: return str(e), None, None, "", ""
def slices_to_cif(slices_string): try: structure, energy = backend.SLICES2structure(slices_string) structure = process_structure(structure) with tempfile.NamedTemporaryFile(mode='w', suffix='.cif', delete=False) as temp_file: CifWriter(structure).write_file(temp_file.name) image_file = visualize_structure(structure) return temp_file.name, image_file, f"Conversion successful. Energy: {energy:.4f} eV/atom" except Exception as e: return None, None, f"Conversion failed. Error: {str(e)}"
def augment_and_canonicalize_slices(slices_string, num_augmentations): try: augmented_slices = backend.SLICES2SLICESAug_atom_order(slices_string,num=num_augmentations) unique_augmented_slices = list(set(augmented_slices)) canonical_slices = list(set([backend.get_canonical_SLICES(s) for s in unique_augmented_slices])) return augmented_slices, canonical_slices except Exception as e: return [], [], str(e)
# Gradio interfacewith gr.Blocks() as iface: gr.Markdown("# Crystal Structure and SLICES Converter", elem_classes=["center"]) with gr.Row(elem_classes=["center"]): gr.Image("1.png", label="SLICES Representation", show_label=False, width=600, height=250) gr.Markdown("SLICES provides a text-based encoding of crystal structures, allowing for efficient manipulation and generation of new materials.", elem_classes=["center"]) with gr.Tab("CIF-SLICES Conversion"): with gr.Row(): with gr.Column(): cif_input = gr.File(label="Upload CIF file", file_types=[".cif"], value="NdSiRu.cif") convert_cif_button = gr.Button("Convert CIF to SLICES") slices_input = gr.Textbox(label="Enter SLICES String") convert_slices_button = gr.Button("Convert SLICES to CIF") with gr.Column(): slices_output = gr.Textbox(label="SLICES String") cif_output = gr.File(label="Download CIF", file_types=[".cif"]) conversion_status = gr.Textbox(label="Conversion Status") with gr.Row(): cif_image = gr.Image(label="Original Structure") slices_image = gr.Image(label="Converted Structure") with gr.Tab("SLICES Augmentation and Canonicalization"): aug_slices_input = gr.Textbox(label="Enter SLICES String") num_augmentations = gr.Slider(minimum=1, maximum=50, step=1, value=10, label="Number of Augmentations") augment_button = gr.Button("Augment and Canonicalize") aug_slices_output = gr.Textbox(label="Augmented SLICES Strings") canon_slices_output = gr.Textbox(label="Canonical SLICES Strings") # Event handlers convert_cif_button.click( cif_to_slices, inputs=[cif_input], outputs=[slices_output, cif_image, conversion_status, slices_input, aug_slices_input] ) convert_slices_button.click( slices_to_cif, inputs=[slices_input], outputs=[cif_output, slices_image, conversion_status] ) augment_button.click( augment_and_canonicalize_slices, inputs=[aug_slices_input, num_augmentations], outputs=[aug_slices_output, canon_slices_output] )
# Launch the interfaceiface.launch(share=True)1slices==2.0.41.pngAdded

NdSiRu.cifAdded+50
app.pyAdded+118
requirements.txtAdded+1