• About Us
  • Disclaimer
  • Contact Us
  • Privacy Policy
Thursday, May 7, 2026
mGrowTech
No Result
View All Result
  • Technology And Software
    • Account Based Marketing
    • Channel Marketing
    • Marketing Automation
      • Al, Analytics and Automation
      • Ad Management
  • Digital Marketing
    • Social Media Management
    • Google Marketing
  • Direct Marketing
    • Brand Management
    • Marketing Attribution and Consulting
  • Mobile Marketing
  • Event Management
  • PR Solutions
  • Technology And Software
    • Account Based Marketing
    • Channel Marketing
    • Marketing Automation
      • Al, Analytics and Automation
      • Ad Management
  • Digital Marketing
    • Social Media Management
    • Google Marketing
  • Direct Marketing
    • Brand Management
    • Marketing Attribution and Consulting
  • Mobile Marketing
  • Event Management
  • PR Solutions
No Result
View All Result
mGrowTech
No Result
View All Result
Home Al, Analytics and Automation

A Coding Implementation for Building and Analyzing Crystal Structures Using Pymatgen for Symmetry Analysis, Phase Diagrams, Surface Generation, and Materials Project Integration

Josh by Josh
March 22, 2026
in Al, Analytics and Automation
0
A Coding Implementation for Building and Analyzing Crystal Structures Using Pymatgen for Symmetry Analysis, Phase Diagrams, Surface Generation, and Materials Project Integration


header("11. DISORDERED STRUCTURE -> ORDERED APPROXIMATION")


disordered = Structure(
   Lattice.cubic(3.6),
   [{"Cu": 0.5, "Au": 0.5}],
   [[0, 0, 0]],
)


disordered.make_supercell([2, 2, 2])


print("Disordered composition:", disordered.composition)


try:
   disordered_oxi = disordered.copy()
   disordered_oxi.add_oxidation_state_by_element({"Cu": 1, "Au": 1})


   ordered_transform = OrderDisorderedStructureTransformation()


   ordered_candidates = ordered_transform.apply_transformation(
       disordered_oxi,
       return_ranked_list=3,
   )


   for idx, cand in enumerate(ordered_candidates):
       s = cand["structure"].copy()
       s.remove_oxidation_states()
       print(f"Ordered candidate {idx+1}: formula={s.composition.formula}, sites={len(s)}")


except Exception as e:
   print("Ordering step skipped due to transformation issue:", e)


header("12. MOLECULE SUPPORT")


water = Molecule(
   ["O", "H", "H"],
   [
       [0.0, 0.0, 0.0],
       [0.7586, 0.0, 0.5043],
       [-0.7586, 0.0, 0.5043],
   ],
)


print("Water formula:", water.composition.formula)


print("Water center of mass:", np.round(water.center_of_mass, 4))


print(
   "O-H bond lengths:",
   round(water.get_distance(0, 1), 4),
   round(water.get_distance(0, 2), 4),
)


header("13. CIF EXPORT")


output_dir = "/content/pymatgen_tutorial_outputs"


os.makedirs(output_dir, exist_ok=True)


si_cif = os.path.join(output_dir, "si.cif")
nacl_cif = os.path.join(output_dir, "nacl.cif")
slab_cif = os.path.join(output_dir, "si_111_slab.cif")


CifWriter(si).write_file(si_cif)
CifWriter(nacl).write_file(nacl_cif)
CifWriter(slab).write_file(slab_cif)


print("Saved:", si_cif)
print("Saved:", nacl_cif)
print("Saved:", slab_cif)


header("14. DATAFRAME SUMMARY")


rows = []


for name, s in [
   ("Si", si),
   ("NaCl", nacl),
   ("LiFePO4-like", li_fe_po4),
   ("Si slab", slab),
]:


   sga = SpacegroupAnalyzer(s, symprec=0.1)


   rows.append(
       {
           "name": name,
           "formula": s.composition.reduced_formula,
           "sites": len(s),
           "volume_A3": round(s.volume, 4),
           "density_g_cm3": round(float(s.density), 4),
           "spacegroup": sga.get_space_group_symbol(),
           "sg_number": sga.get_space_group_number(),
       }
   )


df = pd.DataFrame(rows)


print(df)


header("15. OPTIONAL MATERIALS PROJECT API ACCESS")


mp_api_key = None


try:
   from google.colab import userdata
   mp_api_key = userdata.get("MP_API_KEY")
except Exception:
   pass


if not mp_api_key:
   mp_api_key = os.environ.get("MP_API_KEY", None)


if mp_api_key:


   try:
       from pymatgen.ext.matproj import MPRester


       with MPRester(mp_api_key) as mpr:


           mp_struct = mpr.get_structure_by_material_id("mp-149")


           summary_docs = mpr.summary.search(
               material_ids=["mp-149"],
               fields=[
                   "material_id",
                   "formula_pretty",
                   "band_gap",
                   "energy_above_hull",
                   "is_stable",
               ],
           )


       print("Fetched mp-149 from Materials Project")


       print("Formula:", mp_struct.composition.reduced_formula)


       print("Sites:", len(mp_struct))


       if len(summary_docs) > 0:


           doc = summary_docs[0]


           print(
               {
                   "material_id": str(doc.material_id),
                   "formula_pretty": doc.formula_pretty,
                   "band_gap": doc.band_gap,
                   "energy_above_hull": doc.energy_above_hull,
                   "is_stable": doc.is_stable,
               }
           )


   except Exception as e:
       print("Materials Project API section skipped due to runtime/API issue:", e)


else:
   print("No MP_API_KEY found. Skipping live Materials Project query.")
   print("In Colab, add a secret named MP_API_KEY or set os.environ['MP_API_KEY'].")


header("16. SAVE SUMMARY JSON")


summary = {
   "structures": {
       "Si": {
           "formula": si.composition.reduced_formula,
           "sites": len(si),
           "spacegroup": SpacegroupAnalyzer(si, symprec=0.1).get_space_group_symbol(),
       },
       "NaCl": {
           "formula": nacl.composition.reduced_formula,
           "sites": len(nacl),
           "spacegroup": SpacegroupAnalyzer(nacl, symprec=0.1).get_space_group_symbol(),
       },
       "LiFePO4-like": {
           "formula": li_fe_po4.composition.reduced_formula,
           "sites": len(li_fe_po4),
           "spacegroup": SpacegroupAnalyzer(li_fe_po4, symprec=0.1).get_space_group_symbol(),
       },
   },
   "phase_diagram": {
       "target": target.composition.reduced_formula,
       "energy_above_hull_eV_atom": float(e_above_hull),
   },
   "files": {
       "si_cif": si_cif,
       "nacl_cif": nacl_cif,
       "slab_cif": slab_cif,
   },
}


json_path = os.path.join(output_dir, "summary.json")


with open(json_path, "w") as f:
   json.dump(summary, f, indent=2)


print("Saved:", json_path)


header("17. FINAL NOTES")


print("Tutorial completed successfully.")


print("Artifacts are saved in:", output_dir)


print("You can now extend this notebook to parse VASP outputs, query MP at scale, or build defect/workflow pipelines.")



Source_link

READ ALSO

Study: Firms often use automation to control certain workers’ wages | MIT News

A Groq-Powered Agentic Research Assistant with LangGraph, Tool Calling, Sub-Agents, and Agentic Memory: Lets Built It

Related Posts

Study: Firms often use automation to control certain workers’ wages | MIT News
Al, Analytics and Automation

Study: Firms often use automation to control certain workers’ wages | MIT News

May 7, 2026
A Groq-Powered Agentic Research Assistant with LangGraph, Tool Calling, Sub-Agents, and Agentic Memory: Lets Built It
Al, Analytics and Automation

A Groq-Powered Agentic Research Assistant with LangGraph, Tool Calling, Sub-Agents, and Agentic Memory: Lets Built It

May 7, 2026
Google AI Releases Multi-Token Prediction (MTP) Drafters for Gemma 4: Delivering Up to 3x Faster Inference Without Quality Loss
Al, Analytics and Automation

Google AI Releases Multi-Token Prediction (MTP) Drafters for Gemma 4: Delivering Up to 3x Faster Inference Without Quality Loss

May 6, 2026
Medical Imaging Data Annotation for AI: Choosing the Right Partner
Al, Analytics and Automation

Medical Imaging Data Annotation for AI: Choosing the Right Partner

May 6, 2026
U.S. Officials Want Early Access to Advanced AI, and the Big Companies Have Agreed
Al, Analytics and Automation

U.S. Officials Want Early Access to Advanced AI, and the Big Companies Have Agreed

May 6, 2026
Games people — and machines — play: Untangling strategic reasoning to advance AI | MIT News
Al, Analytics and Automation

Games people — and machines — play: Untangling strategic reasoning to advance AI | MIT News

May 6, 2026
Next Post
Digital Detox & Screen Time Statistics 2025

Digital Detox & Screen Time Statistics 2025

POPULAR NEWS

Trump ends trade talks with Canada over a digital services tax

Trump ends trade talks with Canada over a digital services tax

June 28, 2025
Communication Effectiveness Skills For Business Leaders

Communication Effectiveness Skills For Business Leaders

June 10, 2025
15 Trending Songs on TikTok in 2025 (+ How to Use Them)

15 Trending Songs on TikTok in 2025 (+ How to Use Them)

June 18, 2025
App Development Cost in Singapore: Pricing Breakdown & Insights

App Development Cost in Singapore: Pricing Breakdown & Insights

June 22, 2025
Comparing the Top 7 Large Language Models LLMs/Systems for Coding in 2025

Comparing the Top 7 Large Language Models LLMs/Systems for Coding in 2025

November 4, 2025

EDITOR'S PICK

Tools, Tips, And Best Practices

Tools, Tips, And Best Practices

November 26, 2025
14 Best Travel Toiletry Bags, Tested Over Many Miles (2025)

14 Best Travel Toiletry Bags, Tested Over Many Miles (2025)

October 4, 2025
Road to Battlefield: Central Eurasia’s gateway to TechCrunch Startup Battlefield

Road to Battlefield: Central Eurasia’s gateway to TechCrunch Startup Battlefield

July 1, 2025

14 Experts on the State of Email Marketing in the Age of AI and Owned Media

July 15, 2025

About

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Check our landing page for details.

Follow us

Categories

  • Account Based Marketing
  • Ad Management
  • Al, Analytics and Automation
  • Brand Management
  • Channel Marketing
  • Digital Marketing
  • Direct Marketing
  • Event Management
  • Google Marketing
  • Marketing Attribution and Consulting
  • Marketing Automation
  • Mobile Marketing
  • PR Solutions
  • Social Media Management
  • Technology And Software
  • Uncategorized

Recent Posts

  • Busting silos helped Chicago Bears drive statewide change
  • 8 Best AIOps Platforms for IT Operations Monitoring in 2026
  • AI Outsourcing for Enterprises: Choose the Right Partner
  • Chrome’s AI features may be hogging 4GB of your computer storage
  • About Us
  • Disclaimer
  • Contact Us
  • Privacy Policy
No Result
View All Result
  • Technology And Software
    • Account Based Marketing
    • Channel Marketing
    • Marketing Automation
      • Al, Analytics and Automation
      • Ad Management
  • Digital Marketing
    • Social Media Management
    • Google Marketing
  • Direct Marketing
    • Brand Management
    • Marketing Attribution and Consulting
  • Mobile Marketing
  • Event Management
  • PR Solutions