Angle getAngleFromLine(string line){
    Angle angle = createAngle(-1, -1, -1, false);

    char *tokens;
    char *charLine = (char *)malloc(sizeof(char) * line.size());
    strcpy(charLine, line.c_str());
    tokens = strtok(charLine, " ");
    strcpy(charLine, line.c_str());
    
    int tokenNumber = 0;
    while(tokens != NULL){
       switch(tokenNumber){
           case 0:
               angle.atom1 = atoi(tokens);
               break;
            case 1:
               angle.atom2 = atoi(tokens);
               break;
            case 2:
               angle.value = atof(tokens);
               break;
            case 3:
               if(atoi(tokens) == 1)
                   angle.variable = true;
               else
                   angle.variable = false;
       }
       tokens = strtok(NULL, " ");
       tokenNumber++;
    }
    return angle;
}
Beispiel #2
0
void testGetOppositeAtom()
{
    cout << "Testing getOppositeAtom"<< endl;
    Bond testBond = createBond(1,3,5.5,true);
    Angle testAngle = createAngle(2,6,30,false);
    Dihedral testDihed = createDihedral(3,7,180,true);

    //test with bonds
    assert(getOppositeAtom(testBond,1)==3);
    assert(getOppositeAtom(testBond,3)==1);
    assert(getOppositeAtom(testBond,4)==-1);

    //test with bonds
    assert(getOppositeAtom(testAngle,2)==6);
    assert(getOppositeAtom(testAngle,6)==2);
    assert(getOppositeAtom(testAngle,5)==-1);

    //test with bonds
    assert(getOppositeAtom(testDihed,3)==7);
    assert(getOppositeAtom(testDihed,7)==3);
    assert(getOppositeAtom(testDihed,6)==-1);

    testBond = createBond(11,12,3.5,true);
    testAngle = createAngle(1,22,30,false);
    testDihed = createDihedral(5,9,180,true);

    //test with bonds
    assert(getOppositeAtom(testBond,11)==12);
    assert(getOppositeAtom(testBond,12)==11);
    assert(getOppositeAtom(testBond,13)==-1);

    //test with bonds
    assert(getOppositeAtom(testAngle,1)==22);
    assert(getOppositeAtom(testAngle,22)==1);
    assert(getOppositeAtom(testAngle,15)==-1);

    //test with bonds
    assert(getOppositeAtom(testDihed,5)==9);
    assert(getOppositeAtom(testDihed,9)==5);
    assert(getOppositeAtom(testDihed,62)==-1);

    cout << "Testing getOppositeAtom Complete\n" << endl;

}
Beispiel #3
0
Molecule createMeshZMolecules(Opls_Scan *scanner)
{

    //1 S    200    0    0    0.000000   0    0.000000   0    0.000000        0  
    Atom atom1=scanner->getAtom("200");
    atom1.id=1;

    // 2 DUM   -1    0    1    0.500000   0    0.000000   0    0.000000        0
    Atom atom2=createAtom(2,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond2=createBond(2,1,0.5,false);

    //3 DUM   -1    0    2    0.500000   1   90.000000   0    0.000000        0 
    Atom atom3=createAtom(3,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond3=createBond(3,2,0.5,false);
    Angle angle3=createAngle(3,1,90,false);

    //4 hH    204    0    1    1.336532   2   90.000000   3  180.000000        0    
    Atom atom4=scanner->getAtom("204");
    atom4.id=4;
    Bond bond4=createBond(4,1,1.336532,true);
    Angle angle4=createAngle(4,2,90,false);
    Dihedral dihed4=createDihedral(4,3,180,false);

    //5 C    217    0    1    1.811119   4   96.401770   2  180.000000        0
    Atom atom5=scanner->getAtom("217");
    atom5.id=5;
    Bond bond5=createBond(5,1,1.811119,true);
    Angle angle5=createAngle(5,4,96.401770,true);
    Dihedral dihed5=createDihedral(5,2,180,false);

    //6 HC   140    0    5    1.090187   1  110.255589   4  179.999947        0
    Atom atom6=scanner->getAtom("140");
    atom6.id=6;
    Bond bond6=createBond(6,5,1.090187,true);
    Angle angle6=createAngle(6,1,110.255589,true);
    Dihedral dihed6=createDihedral(6,4,179.999947,true);    

    //7 HC   140    0    5    1.090135   6  108.527646   1  121.053891        0
    Atom atom7=scanner->getAtom("140");
    atom7.id=7;
    Bond bond7=createBond(7,5,1.090135,true);
    Angle angle7=createAngle(7,6,108.527646,true);
    Dihedral dihed7=createDihedral(7,1,121.053891,true);    

    //8 HC   140    0    5    1.090135   6  108.527646   1  238.946114        0
    Atom atom8=scanner->getAtom("140");
    atom8.id=8;
    Bond bond8=createBond(8,5,1.090135,true);
    Angle angle8=createAngle(8,6,108.527646,true);
    Dihedral dihed8=createDihedral(8,1,238.946114,true);

    /* HOPS and BONDS Diagram of Mesh.z
    //      1--2--3
    //      |\
    //      | \
    //      4  5
    //        /|\
    //       / | \
    //      6  7  8
    */
    //All hops that have a hop distance >= 3

    Hop hop1= createHop(2,6,3);
    Hop hop2= createHop(2,7,3);
    Hop hop3= createHop(2,8,3);
    Hop hop4= createHop(3,4,3);
    Hop hop5= createHop(3,5,3);
    Hop hop6= createHop(3,6,4);
    Hop hop7= createHop(3,7,4);
    Hop hop8= createHop(3,8,4);
    Hop hop9= createHop(4,6,3);
    Hop hop10= createHop(4,7,3);
    Hop hop11= createHop(4,8,3);

    Atom *atomPtr = new Atom[8];
    Bond *bondPtr = new Bond[7];
    Angle *anglePtr = new Angle[6];
    Dihedral *dihedPtr = new Dihedral[5];
    Hop *hopPtr = new Hop[11];


    atomPtr[0]=atom1;  atomPtr[1]=atom2; atomPtr[2]=atom3; atomPtr[3]=atom4; atomPtr[4]=atom5; atomPtr[5]=atom6; atomPtr[6]=atom7; atomPtr[7]=atom8;
    bondPtr[0]=bond2; bondPtr[1]=bond3; bondPtr[2]=bond4; bondPtr[3]=bond5; bondPtr[4]=bond6; bondPtr[5]=bond7; bondPtr[6]=bond8;
    anglePtr[0]=angle3; anglePtr[1]=angle4; anglePtr[2]=angle5; anglePtr[3]=angle6; anglePtr[4]=angle7; anglePtr[5]=angle8;
    dihedPtr[0]=dihed4; dihedPtr[1]=dihed5; dihedPtr[2]=dihed6; dihedPtr[3]=dihed7; dihedPtr[4]=dihed8;
    hopPtr[0]=hop1; hopPtr[1]=hop2; hopPtr[2]=hop3; hopPtr[3]=hop4; hopPtr[4]=hop5; hopPtr[5]=hop6;  hopPtr[6]=hop7; hopPtr[7]=hop8; hopPtr[8]=hop9; 
    hopPtr[9]=hop10; hopPtr[10]=hop11;


    return createMolecule(1,atomPtr,anglePtr,bondPtr,dihedPtr,hopPtr,8,6,7,5,11);
}
Beispiel #4
0
vector<Molecule> createT3pdimMolecules(Opls_Scan *scanner)
{
    // TIP3P Water Dimer                                      Tot. E =     -6.5396
    //1  O   111  111    0     .000000   0     .000000   0     .000000        0
    Atom atom1 = scanner->getAtom("111");
    atom1.id=1;    

    //2  DU   -1   -1    1    1.000000   0     .000000   0     .000000        0 
    Atom atom2=createAtom(2,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond2=createBond(2,1,1.0,false);   

    //3  DU   -1   -1    2    1.000000   1   90.000000   0     .000000        0
    Atom atom3=createAtom(3,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond3=createBond(3,2,1.0,false);
    Angle angle3=createAngle(3,1,90.0,false);    

    //4  HO  112  112    1     .957200   2  127.740000   3   90.000000        0
    Atom atom4=scanner->getAtom("112");
    atom4.id=4;
    Bond bond4=createBond(4,1,.957200,false);
    Angle angle4=createAngle(4,2,127.740000,false);
    Dihedral dihed4=createDihedral(4,3,90.00,false);

    //5  HO  112  112    1     .957200   4  104.520000   2  180.000000        0 
    Atom atom5=scanner->getAtom("112");
    atom5.id=5;
    Bond bond5=createBond(5,1,.957200,false);
    Angle angle5=createAngle(5,4,104.520000,false);
    Dihedral dihed5=createDihedral(5,2,180.00,false); 
     
    //6  X    -1   -1    1     .150000   4   52.260000   5     .000000        0
    Atom atom6=createAtom(6,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond6=createBond(6,1,.150000,false);
    Angle angle6=createAngle(6,4,52.260000,false);
    Dihedral dihed6=createDihedral(6,5,.00,false); 

    //TERZ 2nd Bonded Molecule                                                                           
    //7  O   111  111    1    2.751259   2  131.716186   3  269.946364        0
    Atom atom7=scanner->getAtom("111");
    atom7.id=7;
    Bond bond7=createBond(7,1,2.751259,false);
    Angle angle7=createAngle(7,2,131.716186,false);
    Dihedral dihed7=createDihedral(7,3,269.946364,false);

    //8  DU   -1   -1    7    1.000000   1   21.472391   2  179.887530        0
    Atom atom8=createAtom(8,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond8=createBond(8,7,1.0,false);
    Angle angle8=createAngle(8,1,21.472391,false);
    Dihedral dihed8=createDihedral(8,2,179.887530,false); 

    //9  DU   -1   -1    8    1.000000   7   90.000000   1  179.624613        0
    Atom atom9=createAtom(9,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond9=createBond(9,8,1.0,false);
    Angle angle9=createAngle(9,7,90.000000,false);
    Dihedral dihed9=createDihedral(9,1,179.624613,false); 

    //10  HO  112  112    7     .957200   8  127.740000   9   90.000000        0
    Atom atom10=scanner->getAtom("112");
    atom10.id=10;
    Bond bond10=createBond(10,7,0.957200,false);
    Angle angle10=createAngle(10,8,127.74,false);
    Dihedral dihed10=createDihedral(10,9,90.0,false);


    //11  HO  112  112    7     .957200  10  104.520000   8  180.000000        0
    Atom atom11=scanner->getAtom("112");
    atom11.id=11;
    Bond bond11=createBond(11,7,0.957200,false);
    Angle angle11=createAngle(11,10,104.52,false);
    Dihedral dihed11=createDihedral(11,8,180.0,false);

    //12  X    -1   -1    7     .150000  10   52.260000  11     .000000        0 
    Atom atom12=createAtom(12,-1,-1,-1,-1,-1,-1,NULL);
    Bond bond12=createBond(12,7,0.15,false);
    Angle angle12=createAngle(12,10,52.26,false);
    Dihedral dihed12=createDihedral(12,11,0.0,false);

    /* HOPS and BONDS Diagram of Mesh.z
    //      
    //
    //      10  11 12
    //        \ | /
    //         \|/
    //          7--8--9
    //          |
    //          |
    //          1--2--3
    //         /|\
    //        / | \
    //       4  5  6
    */
    //All intermolecular hops that have a hop distance >= 3 

    //bottom Molecule 
    Hop hop1=createHop(3,4,3);
    Hop hop2=createHop(3,5,3);
    Hop hop3=createHop(3,6,3);
    //top Molecule 
    Hop hop4=createHop(9,10,3);
    Hop hop5=createHop(9,11,3);
    Hop hop6=createHop(9,12,3);

    Atom *atomPtr = new Atom[6];
    Bond *bondPtr = new Bond[5];
    Angle *anglePtr = new Angle[4];
    Dihedral *dihedPtr = new Dihedral[3];
    Hop *hopPtr = new Hop[3];
    vector<Molecule> retVect;

    atomPtr[0]=atom1; atomPtr[1]=atom2; atomPtr[2]=atom3; atomPtr[3]=atom4; atomPtr[4]=atom5; atomPtr[5]=atom6;
    bondPtr[0]=bond2; bondPtr[1]=bond3; bondPtr[2]=bond4; bondPtr[3]=bond5; bondPtr[4]=bond6;
    anglePtr[0]=angle3; anglePtr[1]=angle4; anglePtr[2]=angle5; anglePtr[3]=angle6;
    dihedPtr[0]=dihed4; dihedPtr[1]=dihed5; dihedPtr[2]=dihed6;
    hopPtr[0]=hop1; hopPtr[1]=hop2; hopPtr[2]=hop3;  
    retVect.push_back( createMolecule(1,atomPtr,anglePtr,bondPtr,dihedPtr,hopPtr,6,4,5,3,3) );

    Atom *atomPt = new Atom[6];
    Bond *bondPt = new Bond[6];
    Angle *anglePt = new Angle[6];
    Dihedral *dihedPt = new Dihedral[6];
    Hop *hopPt = new Hop[3];

    atomPt[0]=atom7; atomPt[1]=atom8; atomPt[2]=atom9; atomPt[3]=atom10; atomPt[4]=atom11; atomPt[5]=atom12;
    bondPt[0]=bond7; bondPt[1]=bond8; bondPt[2]=bond9; bondPt[3]=bond10; bondPt[4]=bond11;  bondPt[5]=bond12;
    anglePt[0]=angle7; anglePt[1]=angle8; anglePt[2]=angle9; anglePt[3]=angle10; anglePt[4]=angle11; anglePt[5]=angle12;
    dihedPt[0]=dihed7; dihedPt[1]=dihed8; dihedPt[2]=dihed9; dihedPt[3]=dihed10; dihedPt[4]=dihed11; dihedPt[5]=dihed12;
    hopPt[0]=hop4; hopPt[1]=hop5; hopPt[2]=hop6;  
    retVect.push_back( createMolecule(7,atomPt,anglePt,bondPt,dihedPt,hopPt,6,6,6,6,3) );

    return retVect;
}
Beispiel #5
0
 /* load the file, parse the text, add the elements */
bool Scene::loadFile (std::string filename) {
    std::ifstream fs;
    fs.open (filename);
    if (!fs.is_open ()) {
        fs.close ();
        return false;
    }

    clearScene();

    int vertNum = 0;
    int lineNum = 0;
    int angleNum = 0;
    int fanoNum = 0;

    Vertex * newVerts[1024];
    Line * newLines[1024];

    int vertIdx = 0;
    int lineIdx = 0;

    std::cout<< "Reading in file " << filename << std::endl;
    std::string line;
    while(std::getline(fs, line)){

      //line that includes data
      if(line.length() > 0 && (line.at(0) == 'V' || line.at(0) == 'v')){
        char *copyLine = (char*)line.c_str();
        char *token;
        token = strtok(copyLine, " ,");
        token = strtok(NULL, " ,");
        float x, y, z;
        x = atof(token);
        token = strtok(NULL, " ,");
        y = atof(token);
        token = strtok(NULL, " ,");
        z = atof(token);

        if(vertIdx == 0)
          newVerts[vertIdx++] = addVertex3f(x, y, z, 1);
        else
          newVerts[vertIdx++] = addVertex3f(x, y, z, 0);
      }
      else if(line.length() > 0 && (line.at(0) == 'L' || line.at(0) == 'l')){
        char *copyLine = (char*)line.c_str();
        char *token;
        token = strtok(copyLine, " ,");
        token = strtok(NULL, " ,");
        int v1, v2;
        v1 = atoi(token);
        token = strtok(NULL, " ,");
        v2 = atoi(token);

        newLines[lineIdx++] = createLine(newVerts[v1], newVerts[v2]);
      }
      else if(line.length() > 0 && (line.at(0) == 'A' || line.at(0) == 'a')){
        char *copyLine = (char*)line.c_str();
        char *token;
        token = strtok(copyLine, " ,");
        token = strtok(NULL, " ,");
        int l1, l2;
        l1 = atoi(token);
        token = strtok(NULL, " ,");
        l2 = atoi(token);
        createAngle(newLines[l1], newLines[l2]);
      }
      else if(line.length() > 0 && (line.at(0) == 'F' || line.at(0) == 'f')){
        char *copyLine = (char*)line.c_str();
        char *token;
        token = strtok(copyLine, " ,");
        token = strtok(NULL, " ,");
        int a1, a2, a3;
        a1 = atoi(token);
        token = strtok(NULL, " ,");
        a2 = atoi(token);
        token = strtok(NULL, " ,");
        a3 = atoi(token);
        createFano(newLines[a1], newLines[a2], newLines[a3]);
      }
      else if(line.length()>0 && (line.at(0)=='C' || line.at(0)=='c')){
        char *copyLine = (char*)line.c_str();
        char *token;
        token = strtok(copyLine, " ,");
        token = strtok(NULL, " ,");
        int l;
        float r, g, b;
        l = atoi(token);
        token = strtok(NULL, " ,");
        r = atof(token);
        token = strtok(NULL, " ,");
        g = atof(token);
        token = strtok(NULL, " ,");
        b = atof(token);
        Line *a = newLines[l];
        a->setColor3f(r,g,b);
      }
      
    }

    //...
    return true;
}