Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:10:06+00:00 2026-06-12T08:10:06+00:00

I am trying to create a program that puts identical non-overlapping particles of diameter

  • 0

I am trying to create a program that puts identical non-overlapping particles of diameter d in a cubic (3d) lattice with periodic boundary conditions.

Really what this means is I need a program that creates an XYZ file that will look something like the below but will go through every comibination:

H 0.0000000.0000005.000000
H 0.0000000.0000006.000000
H 0.0000000.0000007.000000
H 0.0000000.0000008.000000
H 0.0000000.0000009.000000

Now for some reason, my code below is keeping my z value 0 and not going through the values to create the the other combinations …instead its only going through x and y.

#create a file and enter first two lines
text_file=open("question1.xyz","w")
text_file.write("\n")
text_file.write("comment goes here\n")

L=10
d=1

#first particle or line will be at 0,0,0, counter used to count how many lines
x,y,z = 0,0,0
counter=0

#placing the particles
while x<=L-d:
    while y<=L-d:
        while z<=L-d:
            text_file.write('H ')
            text_file.write('%f'%x)
            text_file.write('%f'%y)
            text_file.write('%f\n'%z)
            counter=counter+1
            z=z+d
        z=0
        y=y+d
    z,y=0,0
    x=x+d

text_file.close()

with open("question1.xyz") as infile:
    with open("outputfile.xyz","w") as outfile:
        for i,line in enumerate(infile):
            if i==0:
                outfile.write('%f\n'%counter)
            else:
                outfile.write(line)

Any ideas on why its happening? My while statement is a little messy but i am not sure how else to do it

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:10:08+00:00Added an answer on June 12, 2026 at 8:10 am

    There is an easier way. Use itertools.product:

    import itertools
    
    L = 3
    d = 1
    counter = 0
    with open("question1.xyz","w") as text_file:
        text_file.write("\ncomment goes here\n")
        for x,y,z in itertools.product(range(L),repeat = 3):
            text_file.write('H %f %f %f\n' % (x, y, z))
            counter=counter+1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a program that will get data directly from socket
I am trying to create a program that will be passed input data from
I'm trying to create a program that takes a text file of c++ code
I am trying to create a program that will do some simple calculations, but
I am trying to create a program that has one tableview and when you
I'm currently trying to create a program that estimates location based on signal strength.
I'm trying to create a c program that implements the radon transform algorithm. I
I am trying to create a Jenkins job that restarts a program that runs
I have a small program that I'm trying to create to get ip addresses
Alright so what I am trying to do is essentially create a program that,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.