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

  • SEARCH
  • Home
  • 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 6253827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:04:20+00:00 2026-05-24T14:04:20+00:00

I am still very new to python, but I need to interface with some

  • 0

I am still very new to python, but I need to interface with some software that is written as a bunch of python modules (.py files in case I incorrectly identified them as “modules.”) This program has some very useful and complicated functions that I really cannot feasibly hack (if nothing else, because every time I update the software, I will have to re-hack everything.)

I have a python script that looks like this:

from software import thingfromsoftware
def mything(x,y,someboolean=True,etc)
    var=thingfromsoftware(x,y)
    #....code....
    setattr(var, 'dimensions', somearraything)
    return(var)

Then, if I try:

result=mything(4,5)

then result correctly contains the values of all the attributes first assigned to it via thingfromsoftware but result.dimensions has not been assigned (has no attribute "dimensions")

The goal is to store the dimensions of every result computed and configured by myfunctionthing in some semi-coherent manner.

Real code (upon request)

from ase.structure import nanotube
from ase import Atoms, view, io
from numpy import *
from Avogadro import Molecule, MoleculeFile
import cPickle as pickle
import os


def make_nanotube(n,m,length=1,TYPE='free'):
    #This will set up leads so transport occures along the z axis and leads are aligned along the y axis (so they may be separated along the x axis.)

    os.chdir("/tmp")

    print 'Making ('+str(n)+','+str(m)+') nanotube with '+str(length)+" unit cell as "+str(TYPE)
    tube = nanotube(n, m, length=length, bond=1.420, symbol='C')
    center=tube.get_center_of_mass()
    name='tube:('+str(n)+', '+str(m)+'):unit cells:'+str(length)+':'+str(TYPE)+'.xyz'
    io.write(str(name), tube)

    print 'Computing bonds'
    mol = MoleculeFile.readMolecule(str(name))

    RELOAD=0
    for atom in mol.atoms[:]:
        if len(atom.bonds)<2 and atom.pos[-1]<center[-1]:
            print 'Relocating atom '+str(atom.index)+' from '+str(atom.pos[-1])+' to '+str(tube.get_cell()[-1, -1] + atom.pos[-1])
            tube.positions[atom.index, -1] += tube.get_cell()[-1, -1]
            RELOAD=1

    print 'Orienting tube'
    tip_atom=tube.get_positions()[:, -1].argmax() #the tip on the right (farther) end
    tip=tube.get_positions()[tip_atom]
    tube.rotate(append(tip[:-1], 0), append(center[0], zeros(2)), center=center) #rotate so that the tip is slanted toward x-axis (center[0],0,0)
    tube.center()
    setattr(tube, 'dimensions', [tube.get_cell()[0, 0]/2,tube.get_cell()[-1,-1]])
    cell=tube.get_cell()

    if TYPE!='bare':
        if RELOAD==1:
            print 'Recomputing bonds'
            io.write(str(name), tube)
            mol = MoleculeFile.readMolecule(str(name))

        print 'Adding hydrogens'
        mol.addHydrogens()

        if TYPE=='left lead':
            print 'Removing hydrogens from the right side'
            for atom in mol.atoms[:]:
                if atom.pos[2]<center[2]:
                    mol.removeHydrogens(atom)
        elif TYPE=='right lead':
            print 'Removing hydrogens from the left side'
            for atom in mol.atoms[:]:
                if atom.pos[2]>center[2]:
                    mol.removeHydrogens(atom)
        MoleculeFile.writeMolecule(mol,str(name))
        tube=io.read(str(name))
    else:
        tube.set_cell(cell)
    return(tube)
  • 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-05-24T14:04:20+00:00Added an answer on May 24, 2026 at 2:04 pm

    You’re doing

    tube=io.read(str(name))
    

    if

    TYPE!='bare'
    

    So in that case you wouldn’t get the dimensions. Could this be why you’re having the problem?

    Also, have you tried just doing

    tube.dimensions = [tube.get_cell()[0, 0] / 2, tube.get_cell()[-1,-1]]
    

    instead of setattr? It’s only needed when the name of the attribute to change is stored in a variable name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

still new to the world of linq, and i need some help flatening a
I still very new using Subversion. Is it possible to have a working copy
I am still very new to Ruby (reading through the Pickaxe and spending most
I'm VERY new to WPF, and still trying to wrap my head around binding
I find this very strange, must be something I'm doing wrong, but still... I'm
I used multiple threads in a few programs, but still don't feel very comfortable
I'm very new to Python and multithreaded programming in general. Basically, I have a
I have a project I'm thinking of doing in F#, but I'm still very
I'm still very new to Objective C, and I was wondering something regarding viewDidDisappear.
i am still very new to objective c and in fact this is my

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.